File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments