Skip to content

Commit 89c7e92

Browse files
ci: add workflow to validate PR description sections
Checks that PR descriptions include the required sections from the template: Description, Checklist, Expected Behavior, and Steps to Test. - Triggers on opened, edited, reopened, and ready_for_review - Skips draft PRs and bot accounts (dependabot, renovate) - Uses line-anchored regex to match section headers - Additional Context section is intentionally optional Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0acf5d6 commit 89c7e92

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

.github/workflows/validate_pr.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "Validate PR Description"
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened, ready_for_review]
6+
7+
jobs:
8+
validate-pr:
9+
if: >-
10+
!github.event.pull_request.draft &&
11+
github.actor != 'dependabot[bot]' &&
12+
github.actor != 'renovate[bot]'
13+
permissions:
14+
contents: read
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Validate PR description sections
18+
uses: actions/github-script@v9
19+
with:
20+
script: |
21+
const body = context.payload.pull_request.body || "";
22+
23+
const required = [
24+
{ header: /^##\s+Description\s*$/m, name: "Description" },
25+
{ header: /^##\s+Checklist\s*$/m, name: "Checklist" },
26+
{ header: /^##\s+Expected Behavior\s*$/m, name: "Expected Behavior" },
27+
{ header: /^##\s+Steps to Test This Pull Request\s*$/m, name: "Steps to Test This Pull Request" },
28+
];
29+
30+
const missing = required
31+
.filter(s => !s.header.test(body))
32+
.map(s => s.name);
33+
34+
if (missing.length > 0) {
35+
core.setFailed(
36+
`PR description is missing required sections: ${missing.join(", ")}.\n` +
37+
`Please use the PR template from .github/pull_request_template.md.`
38+
);
39+
} else {
40+
core.info("All required PR description sections are present.");
41+
}

0 commit comments

Comments
 (0)