Skip to content

Conversation

@findepi
Copy link
Member

@findepi findepi commented Oct 22, 2025

Add CI check that validates PR descriptions are not empty. The check handles both cases: PRs using the template and PRs without template. It ignores Sourcery AI bot summaries and requires minimum meaningful content.

Includes validation script, GitHub workflow, and test suite.

Summary by Sourcery

Enforce meaningful pull request descriptions by adding a validation script, accompanying tests, and a CI workflow to run the checks on PR events

New Features:

  • Add PR description validator script enforcing non-empty descriptions with minimum-length requirements for templated and non-templated PRs, and ignoring Sourcery AI summaries

CI:

  • Introduce GitHub Actions workflow to run validation tests and enforce PR description checks on pull request events

Tests:

  • Add shell-based test suite with fixtures to verify PR description validation logic

Add CI check that validates PR descriptions are not empty. The check handles
both cases: PRs using the template and PRs without template. It ignores
Sourcery AI bot summaries and requires minimum meaningful content.

Includes validation script, GitHub workflow, and test suite.
@findepi findepi marked this pull request as draft October 22, 2025 15:50
@cla-bot cla-bot bot added the cla-signed label Oct 22, 2025
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 22, 2025

Reviewer's Guide

This PR enforces non-empty, meaningful PR descriptions by adding a Python validation script, a test suite, and a GitHub Actions workflow to run the checks on pull request events, handling both templated and free-form descriptions while ignoring Sourcery AI summaries.

Sequence diagram for PR description validation on pull request

sequenceDiagram
    participant GitHub
    participant Workflow
    participant Script
    GitHub->>Workflow: Trigger on PR event
    Workflow->>Workflow: Checkout repo, setup Python, run tests
    Workflow->>Workflow: Extract PR description to pr_description.txt
    Workflow->>Script: Run validate-pr-description.py with pr_description.txt
    Script->>Script: Validate description (template, length, ignore Sourcery)
    Script-->>Workflow: Return pass/fail result
    Workflow-->>GitHub: Mark check as passed/failed
Loading

Class diagram for PR description validation script

classDiagram
    class validate_pr_description.py {
        +remove_html_comments(text)
        +remove_sourcery_section(text)
        +extract_description_section(text)
        +get_meaningful_content(text)
        +validate_pr_description(description)
        +main()
    }
Loading

File-Level Changes

Change Details Files
Validation script for PR descriptions
  • Strip HTML comments and Sourcery AI sections
  • Extract and validate the 'Description' section from templates
  • Require minimum content length (20 chars for templates, 50 for free-form)
  • Read PR body from file and exit with appropriate status and messages
.github/bin/validate-pr-description.py
Test suite for description validator
  • Implement shell test runner with multiple test cases
  • Verify exit codes for empty, short, valid, and AI-only descriptions
  • Organize test fixtures for templated and non-templated scenarios
.github/bin/test/pr-description/run-tests.sh
.github/bin/test/pr-description/test_empty.txt
.github/bin/test/pr-description/test_valid.txt
.github/bin/test/pr-description/test_sourcery.txt
.github/bin/test/pr-description/test_no_template_valid.txt
.github/bin/test/pr-description/test_no_template_short.txt
GitHub Actions workflow for PR checks
  • Trigger on pull_request events (opened, edited, synchronized, reopened)
  • Checkout code and set up Python 3.11
  • Run validation tests and execute the validator against PR body
.github/workflows/pr-description.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider extracting the hard-coded minimum description lengths (20 and 50) into named constants or configuration so you can tweak them without changing validation logic.
  • To improve maintainability and ease of adding edge cases, think about migrating the shell-based test suite to a Python test framework (like pytest) instead of a custom bash runner.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the hard-coded minimum description lengths (20 and 50) into named constants or configuration so you can tweak them without changing validation logic.
- To improve maintainability and ease of adding edge cases, think about migrating the shell-based test suite to a Python test framework (like pytest) instead of a custom bash runner.

## Individual Comments

### Comment 1
<location> `.github/bin/validate-pr-description.py:119-121` </location>
<code_context>
+    except FileNotFoundError:
+        print(f"Error: File '{description_file}' not found.", file=sys.stderr)
+        sys.exit(1)
+    except Exception as e:
+        print(f"Error reading file: {e}", file=sys.stderr)
+        sys.exit(1)
</code_context>

<issue_to_address>
**suggestion:** Generic exception handling may obscure specific errors.

Handle only expected exceptions, such as IOError, and log or re-raise unexpected ones to aid debugging.

```suggestion
    except IOError as e:
        print(f"IOError reading file '{description_file}': {e}", file=sys.stderr)
        sys.exit(1)
    except Exception as e:
        print(f"Unexpected error reading file '{description_file}': {e}", file=sys.stderr)
        raise
```
</issue_to_address>

### Comment 2
<location> `.github/bin/validate-pr-description.py:33-36` </location>
<code_context>
def extract_description_section(text):
    """
    Extract content from the Description section of the template.
    Returns None if template is not used.
    """
    # Look for "## Description" heading
    match = re.search(r'##\s+Description\s*\n(.*?)(?=##|$)', text, flags=re.DOTALL)
    if match:
        return match.group(1)
    return None

</code_context>

<issue_to_address>
**suggestion (code-quality):** We've found these issues:

- Use named expression to simplify assignment and conditional ([`use-named-expression`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/use-named-expression/))
- Replace m.group(x) with m[x] for re.Match objects ([`use-getitem-for-re-match-groups`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/use-getitem-for-re-match-groups/))

```suggestion
    if match := re.search(
        r'##\s+Description\s*\n(.*?)(?=##|$)', text, flags=re.DOTALL
    ):
        return match[1]
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@findepi findepi requested a review from Copilot October 22, 2025 15:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces automated validation for pull request descriptions to ensure they contain meaningful content. The implementation includes a Python validation script, a comprehensive shell-based test suite, and a GitHub Actions workflow that runs on PR events (opened, edited, synchronize, reopened).

Key changes:

  • Added validation logic that distinguishes between templated and non-templated PRs, requiring minimum content length while filtering out automated bot summaries
  • Created a CI workflow that both tests the validator and enforces description requirements on actual PRs
  • Implemented a test harness with fixtures covering various PR description scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@raunaqmorarka
Copy link
Member

Is this really solving a problem ?
There are often trivial PRs that don't require description beyond the PR title and the commit messages.
If a PR needs a description and there is nothing provided, or the provided description is insufficient (more realistic case), then PR reviewers are going to ask for that.
Having a requirement to populate something doesn't do anything, its easy to copy paste the PR title or an AI summary to get past this. You're not going to force a good PR description from someone through simple checks. I already see community PRs with verbose AI generated descriptions that are either not concise or inaccurate.
It will take an actual reviewer asking for clarifications to elicit a useful response from PR authors.

@findepi
Copy link
Member Author

findepi commented Oct 23, 2025

If a PR needs a description and there is nothing provided, or the provided description is insufficient (more realistic case), then PR reviewers are going to ask for that.

This is true. But people often reply as a comment while they should also fill the PR description.

Having a requirement to populate something doesn't do anything, its easy to copy paste the PR title or an AI summary to get past this.

Yes. And that's what people might end up doing.
I share this concern and this is why i made this PR a draft. I am not convinced we should merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants