diff --git a/.github/scripts/validate_pr.py b/.github/scripts/validate_pr.py new file mode 100644 index 0000000000..1d18fb814f --- /dev/null +++ b/.github/scripts/validate_pr.py @@ -0,0 +1,44 @@ +import os +import sys +import re +import requests + +# GitHub environment variables +pr_number = os.getenv("PR_NUMBER") +repo_name = os.getenv("GITHUB_REPOSITORY") +token = os.getenv("GITHUB_TOKEN") + +# API request to get PR body +url = f"https://api.github.com/repos/{repo_name}/pulls/{pr_number}" +headers = {"Authorization": f"token {token}"} +response = requests.get(url, headers=headers) + +if response.status_code != 200: + print("Error fetching PR details") + sys.exit(1) + +pr_body = response.json().get("body", "") + +# Check for 'Proposed changes' section +proposed_changes_match = re.search(r"### Proposed changes\s+(.+)", pr_body, re.DOTALL) +if proposed_changes_match: + proposed_changes_text = proposed_changes_match.group(1).strip() + word_count = len(proposed_changes_text.split()) + + if word_count <= 10: + print(f"Error: 'Proposed changes' section should have more than 10 words. Found {word_count} words.") + sys.exit(1) +else: + print("Error: 'Proposed changes' section is missing.") + sys.exit(1) + +# Check if the first two checklist items are selected +if not re.search(r"- \[x\] I have read the \[`CONTRIBUTING`\]", pr_body): + print("Error: The first checklist item is not checked.") + sys.exit(1) + +if not re.search(r"- \[x\] I have run `make install-tools`", pr_body): + print("Error: The second checklist item is not checked.") + sys.exit(1) + +print("PR description is valid.") \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d70db7d41..e925f3c828 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,20 @@ jobs: run: make install-tools - name: run lint run: make lint + pr-description-checklist-check: + name: Validate PR Description and Checklist + runs-on: ubuntu-24.04 + steps: + - name: Check out code + uses: actions/checkout@v4.1.4 + + - name: Validate PR description and checklist + run: | + python3 .github/scripts/validate_pr.py + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} unit-test: name: Unit Tests runs-on: ubuntu-22.04