|
| 1 | +name: PR Template Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, edited] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-template: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + pull-requests: write |
| 12 | + steps: |
| 13 | + - name: Check PR description for template sections |
| 14 | + uses: actions/github-script@v7 |
| 15 | + with: |
| 16 | + script: | |
| 17 | + const body = context.payload.pull_request.body || ''; |
| 18 | + const requiredSections = [ |
| 19 | + '## Description', |
| 20 | + '## Type of change', |
| 21 | + '## Setup guide for the review', |
| 22 | + '## Checklist' |
| 23 | + ]; |
| 24 | +
|
| 25 | + const missingSections = requiredSections.filter( |
| 26 | + section => !body.includes(section) |
| 27 | + ); |
| 28 | +
|
| 29 | + if (missingSections.length === 0) return; |
| 30 | +
|
| 31 | + // Check if we already left a comment to avoid spamming |
| 32 | + const comments = await github.rest.issues.listComments({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + issue_number: context.payload.pull_request.number |
| 36 | + }); |
| 37 | +
|
| 38 | + const botComment = comments.data.find( |
| 39 | + c => c.user.type === 'Bot' && c.body.includes('<!-- pr-template-check -->') |
| 40 | + ); |
| 41 | +
|
| 42 | + if (botComment) return; |
| 43 | +
|
| 44 | + const missing = missingSections.map(s => `- ${s}`).join('\n'); |
| 45 | +
|
| 46 | + await github.rest.issues.createComment({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + issue_number: context.payload.pull_request.number, |
| 50 | + body: `<!-- pr-template-check -->\nIt looks like the PR template may not have been filled out. The following sections appear to be missing:\n\n${missing}\n\nPlease edit your PR description to include them. The template helps reviewers understand and test your changes. Thanks!` |
| 51 | + }); |
0 commit comments