|
| 1 | +name: PR body check |
| 2 | + |
| 3 | +# Fails the check when a pull request description is missing the sections from |
| 4 | +# .github/PULL_REQUEST_TEMPLATE.md. GitHub only auto-fills that template in the |
| 5 | +# web "compose" form and in `gh pr create` with no --body; a PR opened through |
| 6 | +# the REST API or `gh pr create --body "..."` (the path most AI tools take) |
| 7 | +# silently skips it. This check is the only thing that actually enforces it. |
| 8 | +# |
| 9 | +# Recovery is automatic: editing the PR description fires the `edited` event and |
| 10 | +# re-runs this check with the new body. No new commit or manual re-run needed. |
| 11 | + |
| 12 | +on: |
| 13 | + pull_request: |
| 14 | + types: [opened, edited, reopened, synchronize] |
| 15 | + branches: [main] |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + check: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Check required sections are present |
| 25 | + env: |
| 26 | + PR_BODY: ${{ github.event.pull_request.body }} |
| 27 | + run: | |
| 28 | + set -euo pipefail |
| 29 | + required=( |
| 30 | + "## What I built" |
| 31 | + "## How to review" |
| 32 | + "## How to run" |
| 33 | + "## What reviewers should see" |
| 34 | + "## Self-check" |
| 35 | + ) |
| 36 | + missing=() |
| 37 | + for section in "${required[@]}"; do |
| 38 | + if ! printf '%s' "$PR_BODY" | grep -qiF "$section"; then |
| 39 | + missing+=("$section") |
| 40 | + fi |
| 41 | + done |
| 42 | + if [ ${#missing[@]} -ne 0 ]; then |
| 43 | + echo "::error::Your PR description is missing required sections. Start from the template (.github/PULL_REQUEST_TEMPLATE.md) and keep these headings:" |
| 44 | + for m in "${missing[@]}"; do echo " - $m"; done |
| 45 | + echo "" |
| 46 | + echo "If you (or an AI tool) opened this PR without the template, click 'Edit' on the" |
| 47 | + echo "PR description, paste the template, and fill it in. Editing the description" |
| 48 | + echo "re-runs this check automatically. A complete PR is easy to review and" |
| 49 | + echo "reproducible: that is part of the assignment." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + echo "All required PR sections present." |
0 commit comments