|
| 1 | +name: PR Checklist |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, reopened] |
| 5 | + |
| 6 | +permissions: |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + post-checklist: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.event.pull_request.draft == false |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Post PR Checklist |
| 18 | + uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + script: | |
| 22 | + const fs = require('fs'); |
| 23 | + const path = require('path'); |
| 24 | +
|
| 25 | + // Read checklist from file |
| 26 | + const checklistPath = path.join(process.env.GITHUB_WORKSPACE, '.github', 'pr-checklist.md'); |
| 27 | + const checklistContent = fs.readFileSync(checklistPath, 'utf8'); |
| 28 | +
|
| 29 | + // Check if we already posted a checklist comment |
| 30 | + const { data: comments } = await github.rest.issues.listComments({ |
| 31 | + owner: context.repo.owner, |
| 32 | + repo: context.repo.repo, |
| 33 | + issue_number: context.issue.number |
| 34 | + }); |
| 35 | +
|
| 36 | + const checklistExists = comments.some(comment => |
| 37 | + comment.user.login === 'github-actions[bot]' && |
| 38 | + comment.body.includes('PR Checklist') |
| 39 | + ); |
| 40 | +
|
| 41 | + if (!checklistExists) { |
| 42 | + await github.rest.issues.createComment({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + issue_number: context.issue.number, |
| 46 | + body: checklistContent |
| 47 | + }); |
| 48 | + } |
0 commit comments