Skip to content

Commit 84b7616

Browse files
authored
Add CI Check for Validating PR Template
This PR adds a GitHub Actions workflow to automatically validate that pull requests follow the required PR template format.
1 parent 100ce46 commit 84b7616

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Validate PR Template
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
validate:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check PR template
12+
uses: actions/github-script@v7
13+
with:
14+
script: |
15+
const body = context.payload.pull_request.body || "";
16+
17+
const checkbox1 = /\[x\].*?There is reasonable content/i.test(body);
18+
const checkbox2 = /\[x\].*?I have read and accepted/i.test(body);
19+
20+
const urlMatch = /https?:\/\/[^\s)]+/i.exec(body);
21+
const urlValid = urlMatch && /^https?:\/\/[^\s]+$/.test(urlMatch[0]);
22+
23+
const explanationMatch = />\s*The site content is(?:\s*|\s*\n)(.+)/i.exec(body);
24+
const explanation = explanationMatch && explanationMatch[1].trim().length > 10;
25+
26+
if (!checkbox1 || !checkbox2 || !urlValid || !explanation) {
27+
core.setFailed("❌ PR template is not properly filled:\n" +
28+
`Checkbox1: ${checkbox1 ? '✅' : '❌'}\n` +
29+
`Checkbox2: ${checkbox2 ? '✅' : '❌'}\n` +
30+
`Valid URL: ${urlValid ? '✅' : '❌'}\n` +
31+
`Explanation: ${explanation ? '✅' : '❌'}`
32+
);
33+
} else {
34+
console.log("✅ PR template format is valid.");
35+
}

0 commit comments

Comments
 (0)