Add CI Check for Validating PR Template #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Validate PR Template | |
| on: | |
| pull_request: | |
| types: [opened, edited, synchronize] | |
| jobs: | |
| validate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check PR template | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const body = context.payload.pull_request.body || ""; | |
| const checkbox1 = /\[x\].*?There is reasonable content/i.test(body); | |
| const checkbox2 = /\[x\].*?I have read and accepted/i.test(body); | |
| const urlMatch = /https?:\/\/[^\s)]+/i.exec(body); | |
| const urlValid = urlMatch && /^https?:\/\/[^\s]+$/.test(urlMatch[0]); | |
| const explanationMatch = />\s*The site content is(?:\s*|\s*\n)(.+)/i.exec(body); | |
| const explanation = explanationMatch && explanationMatch[1].trim().length > 10; | |
| if (!checkbox1 || !checkbox2 || !urlValid || !explanation) { | |
| core.setFailed("❌ PR template is not properly filled:\n" + | |
| `Checkbox1: ${checkbox1 ? '✅' : '❌'}\n` + | |
| `Checkbox2: ${checkbox2 ? '✅' : '❌'}\n` + | |
| `Valid URL: ${urlValid ? '✅' : '❌'}\n` + | |
| `Explanation: ${explanation ? '✅' : '❌'}` | |
| ); | |
| } else { | |
| console.log("✅ PR template format is valid."); | |
| } |