Skip to content

Commit a60c0a1

Browse files
authored
Update validate.yml
1 parent 111fe21 commit a60c0a1

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

.github/workflows/validate.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
name: Validate cnames_active.js
1+
name: Validate cnames and PR Template
22

33
on:
44
push:
55
branches:
66
- master
77
pull_request:
8-
branches:
9-
- master
8+
types: [opened, edited, synchronize]
109

1110
permissions:
1211
contents: read
1312

1413
jobs:
15-
validate:
14+
validate-cnames:
1615
runs-on: ubuntu-latest
1716

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

0 commit comments

Comments
 (0)