Commit f9ce8cbff7
Unsigned
Layout: unified · split
.github/workflows/pr-check.yml +26 −6
| @@ -21,21 +21,30 @@ jobs: | ||
| 21 | 21 | - uses: actions/checkout@v5 |
| 22 | 22 | with: |
| 23 | 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 | 34 | - uses: actions/setup-python@v6 |
| 26 | 35 | with: |
| 27 | 36 | python-version: "3.12" |
| 28 | 37 | - name: Check README edits |
| 29 | 38 | id: readme |
| 30 | 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 | 41 | - name: Check PR metadata |
| 33 | 42 | id: meta |
| 34 | 43 | env: |
| 35 | 44 | PR_TITLE: ${{ github.event.pull_request.title }} |
| 36 | 45 | PR_BODY: ${{ github.event.pull_request.body }} |
| 37 | 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 | 48 | README_FAILED: ${{ steps.readme.outcome == 'failure' && 'true' || 'false' }} |
| 40 | 49 | run: python lib/checks/check-pr-meta.py |
| 41 | 50 | - name: Upload findings |
| @@ -56,13 +65,24 @@ jobs: | ||
| 56 | 65 | yaml_changed: ${{ steps.changes.outputs.yaml_changed }} |
| 57 | 66 | steps: |
| 58 | 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 | 80 | - uses: actions/setup-python@v6 |
| 61 | 81 | with: |
| 62 | 82 | python-version: "3.12" |
| 63 | 83 | - name: Detect changes |
| 64 | 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 | 86 | - name: Install dependencies |
| 67 | 87 | if: steps.changes.outputs.yaml_changed == 'true' |
| 68 | 88 | run: pip install -q -r lib/requirements.txt |
| @@ -75,7 +95,7 @@ jobs: | ||
| 75 | 95 | if: steps.changes.outputs.yaml_changed == 'true' |
| 76 | 96 | id: diff |
| 77 | 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 | 99 | - name: Check additions |
| 80 | 100 | if: steps.changes.outputs.yaml_changed == 'true' |
| 81 | 101 | id: additions |
lib/checks/check-pr-meta.py +28 −4
| @@ -44,6 +44,15 @@ BOT_MSG = ( | ||
| 44 | 44 | "Submissions are only accepted from humans." |
| 45 | 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 | 57 | _BOT_AUTHOR_RE = re.compile( |
| 49 | 58 | r"(?:noreply@anthropic\.com|devin-ai-integration|copilot-swe-agent|noreply@cursor\.com)", |
| @@ -86,20 +95,32 @@ def check_template(body): | ||
| 86 | 95 | return None |
| 87 | 96 | |
| 88 | 97 | |
| 89 | def check_checkboxes(body): | |
| 90 | """Return a finding if any checklist checkboxes are unchecked.""" | |
| 98 | def check_checkboxes(body, min_checkboxes=4): | |
| 99 | """Return a finding if any checklist checkboxes are unchecked or missing.""" | |
| 91 | 100 | section = extract_section(body, "Checklist") |
| 92 | 101 | if section is None: |
| 93 | 102 | return None |
| 94 | 103 | checked = re.findall(r"- \[x\]", section, re.IGNORECASE) |
| 95 | 104 | unchecked = re.findall(r"- \[ \]", section) |
| 96 | if not checked and not unchecked: | |
| 97 | return None | |
| 105 | total = len(checked) + len(unchecked) | |
| 106 | if total < min_checkboxes: | |
| 107 | return CHECKBOX_MSG | |
| 98 | 108 | if unchecked: |
| 99 | 109 | return CHECKBOX_MSG |
| 100 | 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 | 124 | def check_bot_coauthors(base_ref): |
| 104 | 125 | """Return a finding if any commit in the PR has a bot author or co-author.""" |
| 105 | 126 | if not base_ref: |
| @@ -166,6 +187,9 @@ def main(): | ||
| 166 | 187 | if finding: |
| 167 | 188 | findings.append({"msg": finding, "level": "error"}) |
| 168 | 189 | critical = True |
| 190 | finding = check_type(body) | |
| 191 | if finding: | |
| 192 | findings.append(finding) | |
| 169 | 193 | |
| 170 | 194 | finding = check_readme(readme_failed) |
| 171 | 195 | if finding: |