Commit f9ce8cbff7
Unsigned
Layout: unified · split
.github/workflows/pr-check.yml +26 −6
| @@ -21,21 +21,30 @@ jobs: | |||
| 21 | - uses: actions/checkout@v5 | 21 | - uses: actions/checkout@v5 |
| 22 | with: | 22 | with: |
| 23 | fetch-depth: 0 | 23 | fetch-depth: 0 |
| 24 | - run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} | 24 | - name: Find merge base with ${{ github.event.pull_request.base.ref }} |
| 25 | id: mb | ||
| 26 | env: | ||
| 27 | BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| 28 | BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
| 29 | run: | | ||
| 30 | git fetch origin "$BASE_REF" || git fetch --depth=1 origin "$BASE_SHA" || true | ||
| 31 | MB=$(git merge-base "$BASE_SHA" HEAD 2>/dev/null || echo "") | ||
| 32 | git cat-file -e "${MB}^{commit}" 2>/dev/null || MB="" | ||
| 33 | echo "sha=${MB:-$BASE_SHA}" >> "$GITHUB_OUTPUT" | ||
| 25 | - uses: actions/setup-python@v6 | 34 | - uses: actions/setup-python@v6 |
| 26 | with: | 35 | with: |
| 27 | python-version: "3.12" | 36 | python-version: "3.12" |
| 28 | - name: Check README edits | 37 | - name: Check README edits |
| 29 | id: readme | 38 | id: readme |
| 30 | continue-on-error: true | 39 | continue-on-error: true |
| 31 | run: python lib/checks/check-readme-edits.py --base-ref ${{ github.event.pull_request.base.sha }} | 40 | run: python lib/checks/check-readme-edits.py --base-ref ${{ steps.mb.outputs.sha }} |
| 32 | - name: Check PR metadata | 41 | - name: Check PR metadata |
| 33 | id: meta | 42 | id: meta |
| 34 | env: | 43 | env: |
| 35 | PR_TITLE: ${{ github.event.pull_request.title }} | 44 | PR_TITLE: ${{ github.event.pull_request.title }} |
| 36 | PR_BODY: ${{ github.event.pull_request.body }} | 45 | PR_BODY: ${{ github.event.pull_request.body }} |
| 37 | PR_DRAFT: ${{ github.event.pull_request.draft }} | 46 | PR_DRAFT: ${{ github.event.pull_request.draft }} |
| 38 | BASE_REF: ${{ github.event.pull_request.base.sha }} | 47 | BASE_REF: ${{ steps.mb.outputs.sha }} |
| 39 | README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }} | 48 | README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }} |
| 40 | run: python lib/checks/check-pr-meta.py | 49 | run: python lib/checks/check-pr-meta.py |
| 41 | - name: Upload findings | 50 | - name: Upload findings |
| @@ -56,13 +65,24 @@ jobs: | |||
| 56 | yaml_changed: ${{ steps.changes.outputs.yaml_changed }} | 65 | yaml_changed: ${{ steps.changes.outputs.yaml_changed }} |
| 57 | steps: | 66 | steps: |
| 58 | - uses: actions/checkout@v5 | 67 | - uses: actions/checkout@v5 |
| 59 | - run: git fetch --depth=1 origin ${{ github.event.pull_request.base.sha }} | 68 | with: |
| 69 | fetch-depth: 0 | ||
| 70 | - name: Find merge base with ${{ github.event.pull_request.base.ref }} | ||
| 71 | id: mb | ||
| 72 | env: | ||
| 73 | BASE_SHA: ${{ github.event.pull_request.base.sha }} | ||
| 74 | BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
| 75 | run: | | ||
| 76 | git fetch origin "$BASE_REF" || git fetch --depth=1 origin "$BASE_SHA" || true | ||
| 77 | MB=$(git merge-base "$BASE_SHA" HEAD 2>/dev/null || echo "") | ||
| 78 | git cat-file -e "${MB}^{commit}" 2>/dev/null || MB="" | ||
| 79 | echo "sha=${MB:-$BASE_SHA}" >> "$GITHUB_OUTPUT" | ||
| 60 | - uses: actions/setup-python@v6 | 80 | - uses: actions/setup-python@v6 |
| 61 | with: | 81 | with: |
| 62 | python-version: "3.12" | 82 | python-version: "3.12" |
| 63 | - name: Detect changes | 83 | - name: Detect changes |
| 64 | id: changes | 84 | id: changes |
| 65 | run: python lib/checks/detect-changes.py --base-ref ${{ github.event.pull_request.base.sha }} | 85 | run: python lib/checks/detect-changes.py --base-ref ${{ steps.mb.outputs.sha }} |
| 66 | - name: Install dependencies | 86 | - name: Install dependencies |
| 67 | if: steps.changes.outputs.yaml_changed == 'true' | 87 | if: steps.changes.outputs.yaml_changed == 'true' |
| 68 | run: pip install -q -r lib/requirements.txt | 88 | run: pip install -q -r lib/requirements.txt |
| @@ -75,7 +95,7 @@ jobs: | |||
| 75 | if: steps.changes.outputs.yaml_changed == 'true' | 95 | if: steps.changes.outputs.yaml_changed == 'true' |
| 76 | id: diff | 96 | id: diff |
| 77 | continue-on-error: true | 97 | continue-on-error: true |
| 78 | run: python lib/checks/check-yaml-diff.py --base-ref ${{ github.event.pull_request.base.sha }} | 98 | run: python lib/checks/check-yaml-diff.py --base-ref ${{ steps.mb.outputs.sha }} |
| 79 | - name: Check additions | 99 | - name: Check additions |
| 80 | if: steps.changes.outputs.yaml_changed == 'true' | 100 | if: steps.changes.outputs.yaml_changed == 'true' |
| 81 | id: additions | 101 | id: additions |
lib/checks/check-pr-meta.py +28 −4
| @@ -44,6 +44,15 @@ BOT_MSG = ( | |||
| 44 | "Submissions are only accepted from humans." | 44 | "Submissions are only accepted from humans." |
| 45 | " This PR appears to have been authored by a bot or AI assistant." | 45 | " This PR appears to have been authored by a bot or AI assistant." |
| 46 | ) | 46 | ) |
| 47 | MISSING_TYPE_MSG = ( | ||
| 48 | "Please specify the PR type (under the Type heading of the PR template)," | ||
| 49 | " for example 'Addition', 'Amendment' or 'Removal'" | ||
| 50 | ) | ||
| 51 | |||
| 52 | _VALID_TYPES = re.compile( | ||
| 53 | r"addition|amendment|removal|spelling|grammar|website|lib|ci|api|misc|other", | ||
| 54 | re.IGNORECASE, | ||
| 55 | ) | ||
| 47 | 56 | ||
| 48 | _BOT_AUTHOR_RE = re.compile( | 57 | _BOT_AUTHOR_RE = re.compile( |
| 49 | r"(?:noreply@anthropic\.com|devin-ai-integration|copilot-swe-agent|noreply@cursor\.com)", | 58 | r"(?:noreply@anthropic\.com|devin-ai-integration|copilot-swe-agent|noreply@cursor\.com)", |
| @@ -86,20 +95,32 @@ def check_template(body): | |||
| 86 | return None | 95 | return None |
| 87 | 96 | ||
| 88 | 97 | ||
| 89 | def check_checkboxes(body): | 98 | def check_checkboxes(body, min_checkboxes=4): |
| 90 | """Return a finding if any checklist checkboxes are unchecked.""" | 99 | """Return a finding if any checklist checkboxes are unchecked or missing.""" |
| 91 | section = extract_section(body, "Checklist") | 100 | section = extract_section(body, "Checklist") |
| 92 | if section is None: | 101 | if section is None: |
| 93 | return None | 102 | return None |
| 94 | checked = re.findall(r"- \[x\]", section, re.IGNORECASE) | 103 | checked = re.findall(r"- \[x\]", section, re.IGNORECASE) |
| 95 | unchecked = re.findall(r"- \[ \]", section) | 104 | unchecked = re.findall(r"- \[ \]", section) |
| 96 | if not checked and not unchecked: | 105 | total = len(checked) + len(unchecked) |
| 97 | return None | 106 | if total < min_checkboxes: |
| 107 | return CHECKBOX_MSG | ||
| 98 | if unchecked: | 108 | if unchecked: |
| 99 | return CHECKBOX_MSG | 109 | return CHECKBOX_MSG |
| 100 | return None | 110 | return None |
| 101 | 111 | ||
| 102 | 112 | ||
| 113 | def check_type(body): | ||
| 114 | """Return a finding if the Type section doesn't contain a recognised PR type.""" | ||
| 115 | content = extract_section(body, "Type") | ||
| 116 | if content is None: | ||
| 117 | return None # missing section is already caught by check_template | ||
| 118 | text = strip_html_comments(content) | ||
| 119 | if text and not _VALID_TYPES.search(text): | ||
| 120 | return MISSING_TYPE_MSG | ||
| 121 | return None | ||
| 122 | |||
| 123 | |||
| 103 | def check_bot_coauthors(base_ref): | 124 | def check_bot_coauthors(base_ref): |
| 104 | """Return a finding if any commit in the PR has a bot author or co-author.""" | 125 | """Return a finding if any commit in the PR has a bot author or co-author.""" |
| 105 | if not base_ref: | 126 | if not base_ref: |
| @@ -166,6 +187,9 @@ def main(): | |||
| 166 | if finding: | 187 | if finding: |
| 167 | findings.append({"msg": finding, "level": "error"}) | 188 | findings.append({"msg": finding, "level": "error"}) |
| 168 | critical = True | 189 | critical = True |
| 190 | finding = check_type(body) | ||
| 191 | if finding: | ||
| 192 | findings.append(finding) | ||
| 169 | 193 | ||
| 170 | finding = check_readme(readme_failed) | 194 | finding = check_readme(readme_failed) |
| 171 | if finding: | 195 | if finding: |