|
1 | | -name: Validate cnames_active.js |
| 1 | +name: Validate |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
|
7 | 7 | pull_request: |
8 | 8 | branches: |
9 | 9 | - master |
| 10 | + types: |
| 11 | + - opened |
| 12 | + - reopened |
| 13 | + - edited |
| 14 | + - synchronize |
10 | 15 |
|
11 | 16 | permissions: |
12 | 17 | contents: read |
13 | 18 |
|
14 | 19 | jobs: |
15 | | - validate: |
| 20 | + validate-cnames: |
16 | 21 | runs-on: ubuntu-latest |
17 | 22 |
|
18 | 23 | env: |
|
41 | 46 | - name: Validate cnames_active.js |
42 | 47 | run: node index.js --validate ../cnames_active.js |
43 | 48 | 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