-
Couldn't load subscription status.
- Fork 3.4k
Require PRs to have description #27053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
findepi
wants to merge
1
commit into
trinodb:master
Choose a base branch
from
findepi:findepi/pr-desc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/bin/bash | ||
| # Test runner for PR description validation | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| VALIDATOR="$SCRIPT_DIR/../../validate-pr-description.py" | ||
| TEST_DIR="$SCRIPT_DIR" | ||
|
|
||
| echo "Running PR description validation tests..." | ||
| echo | ||
|
|
||
| # Track test results | ||
| PASSED=0 | ||
| FAILED=0 | ||
|
|
||
| # Test helper function | ||
| run_test() { | ||
| local test_name="$1" | ||
| local test_file="$2" | ||
| local expected_exit_code="$3" | ||
|
|
||
| echo -n "Testing $test_name... " | ||
|
|
||
| if "$VALIDATOR" "$test_file" > /dev/null 2>&1; then | ||
| actual_exit_code=0 | ||
| else | ||
| actual_exit_code=$? | ||
| fi | ||
|
|
||
| if [ "$actual_exit_code" -eq "$expected_exit_code" ]; then | ||
| echo "✓ PASS" | ||
| PASSED=$((PASSED + 1)) | ||
| else | ||
| echo "✗ FAIL (expected exit code $expected_exit_code, got $actual_exit_code)" | ||
| FAILED=$((FAILED + 1)) | ||
| fi | ||
| } | ||
|
|
||
| # Run tests | ||
| run_test "empty description" "$TEST_DIR/test_empty.txt" 1 | ||
| run_test "valid description" "$TEST_DIR/test_valid.txt" 0 | ||
| run_test "sourcery bot only" "$TEST_DIR/test_sourcery.txt" 1 | ||
| run_test "no template, valid" "$TEST_DIR/test_no_template_valid.txt" 0 | ||
| run_test "no template, short" "$TEST_DIR/test_no_template_short.txt" 1 | ||
|
|
||
| echo | ||
| echo "================================" | ||
| echo "Test Results: $PASSED passed, $FAILED failed" | ||
| echo "================================" | ||
|
|
||
| if [ "$FAILED" -gt 0 ]; then | ||
| exit 1 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <!-- Thank you for submitting a pull request! Find more information | ||
| at https://trino.io/development/process.html, | ||
| at https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md | ||
| and contact us on #core-dev in Slack. --> | ||
| <!-- Provide an overview for maintainers and reviewers. --> | ||
| ## Description | ||
|
|
||
|
|
||
|
|
||
| <!-- Provide details that help an engineer who is unfamiliar with this part of the code. --> | ||
| ## Additional context and related issues | ||
|
|
||
|
|
||
|
|
||
| <!-- Mark the appropriate option with an (x). Propose a release note if you can. | ||
| More info at https://trino.io/development/process#release-note --> | ||
| ## Release notes | ||
|
|
||
| ( ) This is not user-visible or is docs only, and no release notes are required. | ||
| ( ) Release notes are required. Please propose a release note for me. | ||
| ( ) Release notes are required, with the following suggested text: | ||
|
|
||
| ```markdown | ||
| ## Section | ||
| * Fix some things. ({issue}`issuenumber`) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Fix bug | ||
|
|
||
| ## Summary by Sourcery | ||
|
|
||
| Long verbose AI-generated content that we should ignore. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| This PR fixes the authentication bug by properly validating JWT tokens before processing requests. The issue was caused by missing null checks in the token validation logic. | ||
|
|
||
| ## Summary by Sourcery | ||
|
|
||
| Some verbose AI-generated text here that we want to ignore. | ||
|
|
||
| Changes: | ||
| - Added null checks | ||
| - Updated tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ## Description | ||
|
|
||
|
|
||
|
|
||
| ## Summary by Sourcery | ||
|
|
||
| This pull request includes various improvements to the codebase including refactoring some methods, updating documentation, and optimizing performance in several key areas. The changes are backward compatible and include comprehensive test coverage. | ||
|
|
||
| Key changes: | ||
| - Refactored method X | ||
| - Updated documentation for Y | ||
| - Optimized Z | ||
|
|
||
| ## Additional context and related issues |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <!-- Thank you for submitting a pull request! --> | ||
| ## Description | ||
|
|
||
| This PR adds support for JSON parsing with better error handling. It includes validation for malformed JSON and provides helpful error messages to users. | ||
|
|
||
| ## Additional context and related issues | ||
|
|
||
| Fixes #12345 | ||
|
|
||
| ## Release notes | ||
|
|
||
| (x) Release notes are required, with the following suggested text: | ||
|
|
||
| ```markdown | ||
| ## General | ||
| * Add improved JSON parsing with better error messages. ({issue}`12345`) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Validate that PR descriptions contain meaningful content. | ||
|
|
||
| This script checks: | ||
| 1. PR description is not empty | ||
| 2. Description section (if template is used) has content | ||
| 3. Ignores Sourcery AI bot summaries | ||
| 4. Requires minimum meaningful content | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
|
|
||
|
|
||
| def remove_html_comments(text): | ||
| """Remove HTML comments from text.""" | ||
| return re.sub(r'<!--.*?-->', '', text, flags=re.DOTALL) | ||
|
|
||
|
|
||
| def remove_sourcery_section(text): | ||
| """Remove 'Summary by Sourcery' section.""" | ||
| # Match the Sourcery heading and everything until the next heading or end | ||
| pattern = r'##\s+Summary by Sourcery.*?(?=##|$)' | ||
| return re.sub(pattern, '', text, flags=re.DOTALL | re.IGNORECASE) | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
|
|
||
| def get_meaningful_content(text): | ||
| """ | ||
| Extract meaningful content by removing comments, sourcery, and whitespace. | ||
| """ | ||
| # Remove HTML comments | ||
| text = remove_html_comments(text) | ||
|
|
||
| # Remove Sourcery section | ||
| text = remove_sourcery_section(text) | ||
|
|
||
| # Remove markdown code blocks that are empty or just placeholders | ||
| text = re.sub(r'```[a-z]*\s*```', '', text) | ||
|
|
||
| # Remove excessive whitespace | ||
| text = re.sub(r'\n\s*\n', '\n', text) | ||
|
|
||
| return text.strip() | ||
|
|
||
|
|
||
| def validate_pr_description(description): | ||
| """ | ||
| Validate PR description. | ||
| Returns (is_valid, error_message). | ||
| """ | ||
| if not description or not description.strip(): | ||
| return False, "PR description is empty. Please provide a description of your changes." | ||
|
|
||
| # Check if template is used | ||
| description_section = extract_description_section(description) | ||
|
|
||
| if description_section is not None: | ||
| # Template is used, validate the Description section | ||
| meaningful_content = get_meaningful_content(description_section) | ||
|
|
||
| if not meaningful_content: | ||
| return False, ( | ||
| "PR description's 'Description' section is empty. " | ||
| "Please provide a meaningful description of your changes." | ||
| ) | ||
|
|
||
| # Require at least 20 characters of meaningful content | ||
| if len(meaningful_content) < 20: | ||
| return False, ( | ||
| f"PR description's 'Description' section is too short ({len(meaningful_content)} chars). " | ||
| "Please provide a more detailed description (at least 20 characters)." | ||
| ) | ||
| else: | ||
| # Template not used, validate the entire description | ||
| meaningful_content = get_meaningful_content(description) | ||
|
|
||
| if not meaningful_content: | ||
| return False, ( | ||
| "PR description is empty or contains only template comments. " | ||
| "Please provide a meaningful description of your changes." | ||
| ) | ||
|
|
||
| # Require at least 50 characters when template is not used | ||
| if len(meaningful_content) < 50: | ||
| return False, ( | ||
| f"PR description is too short ({len(meaningful_content)} chars). " | ||
| "Please provide a more detailed description (at least 50 characters)." | ||
| ) | ||
|
|
||
| return True, "PR description is valid." | ||
|
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) < 2: | ||
| print("Usage: validate-pr-description.py <pr_description_file>", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| description_file = sys.argv[1] | ||
|
|
||
| try: | ||
| with open(description_file, 'r', encoding='utf-8') as f: | ||
| description = f.read() | ||
| 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) | ||
findepi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| is_valid, message = validate_pr_description(description) | ||
|
|
||
| if is_valid: | ||
| print("✓", message) | ||
| sys.exit(0) | ||
| else: | ||
| print("✗", message, file=sys.stderr) | ||
| print("\nPlease update your PR description to include meaningful information about your changes.", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: "PR Description Check" | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, edited, synchronize, reopened] | ||
findepi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| validate-description: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Run validation script tests | ||
| run: | | ||
| .github/bin/test/pr-description/run-tests.sh | ||
| - name: Get PR description | ||
| id: pr-description | ||
| env: | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| run: | | ||
| echo "$PR_BODY" > pr_description.txt | ||
| - name: Validate PR description | ||
| run: | | ||
| python3 .github/bin/validate-pr-description.py pr_description.txt | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.