Skip to content

Commit be1396d

Browse files
authored
Merge pull request #9782 from mraxays/patch-2
Add CI Check for Validating PR Template
2 parents e8f6d02 + 770879e commit be1396d

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

.github/workflows/validate.yml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Validate cnames_active.js
1+
name: Validate
22

33
on:
44
push:
@@ -7,12 +7,17 @@ on:
77
pull_request:
88
branches:
99
- master
10+
types:
11+
- opened
12+
- reopened
13+
- edited
14+
- synchronize
1015

1116
permissions:
1217
contents: read
1318

1419
jobs:
15-
validate:
20+
validate-cnames:
1621
runs-on: ubuntu-latest
1722

1823
env:
@@ -41,3 +46,40 @@ jobs:
4146
- name: Validate cnames_active.js
4247
run: node index.js --validate ../cnames_active.js
4348
working-directory: cleanup
49+
50+
validate-pr-template:
51+
if: github.event_name == 'pull_request'
52+
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Validate PR template
57+
uses: actions/github-script@v7
58+
with:
59+
script: |
60+
const body = context.payload.pull_request.body || "";
61+
62+
// 1. Check both checkboxes
63+
const checkbox1 = /\[x\].*?There is reasonable content/i.test(body);
64+
const checkbox2 = /\[x\].*?I have read and accepted/i.test(body);
65+
66+
// 2. URL must be on the exact "The site content can be seen at ..." line
67+
const urlLineRegex = /^[ \t]*-[ \t]*The site content can be seen at[ \t]+(https?:\/\/[^\s]+)/m;
68+
const urlMatch = urlLineRegex.exec(body);
69+
const urlValid = urlMatch !== null;
70+
71+
// 3. Explanation must follow the blockquote marker
72+
const explanationMatch = />\s*The site content is(?:\s*|\s*\n)(.+)/i.exec(body);
73+
const explanation = explanationMatch && explanationMatch[1].trim().length > 10;
74+
75+
if (!checkbox1 || !checkbox2 || !urlValid || !explanation) {
76+
core.setFailed(
77+
"❌ PR template is not properly filled:\n" +
78+
`Checkbox1: ${checkbox1 ? '✅' : '❌'}\n` +
79+
`Checkbox2: ${checkbox2 ? '✅' : '❌'}\n` +
80+
`URL on correct line: ${urlValid ? '✅' : '❌'}\n` +
81+
`Explanation: ${explanation ? '✅' : '❌'}`
82+
);
83+
} else {
84+
console.log("✅ PR template format is valid.");
85+
}

0 commit comments

Comments
 (0)