|
| 1 | +name: PR Discussion URL Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, edited, synchronize] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: pr-discussion-${{ github.event.pull_request.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + check: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + permissions: |
| 15 | + pull-requests: write |
| 16 | + issues: write |
| 17 | + steps: |
| 18 | + - uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + script: | |
| 21 | + const pr = context.payload.pull_request; |
| 22 | + const body = pr.body || ''; |
| 23 | + const labels = pr.labels.map(l => l.name); |
| 24 | + const marker = '<!-- openab-pr-discussion-check -->'; |
| 25 | + const label = 'closing-soon'; |
| 26 | +
|
| 27 | + // Exempt bot-authored PRs (e.g. openab-app release PRs) |
| 28 | + if (pr.user.type === 'Bot') { |
| 29 | + console.log(`Skipping discussion check for bot PR by ${pr.user.login}`); |
| 30 | + if (old) { |
| 31 | + await github.rest.issues.deleteComment({ ...context.repo, comment_id: old.id }); |
| 32 | + } |
| 33 | + if (labels.includes(label)) { |
| 34 | + try { await github.rest.issues.removeLabel({ ...context.repo, issue_number: pr.number, name: label }); } catch (e) { if (e.status !== 404) throw e; } |
| 35 | + } |
| 36 | + return; |
| 37 | + } |
| 38 | +
|
| 39 | + const hasDiscordUrl = /https:\/\/discord\.com\/channels\/\d+\/\d+/.test(body); |
| 40 | +
|
| 41 | + const comments = await github.rest.issues.listComments({ |
| 42 | + ...context.repo, |
| 43 | + issue_number: pr.number |
| 44 | + }); |
| 45 | + const old = comments.data.find(c => c.body.includes(marker)); |
| 46 | +
|
| 47 | + if (!hasDiscordUrl) { |
| 48 | + if (!labels.includes(label)) { |
| 49 | + await github.rest.issues.addLabels({ |
| 50 | + ...context.repo, |
| 51 | + issue_number: pr.number, |
| 52 | + labels: [label] |
| 53 | + }); |
| 54 | + } |
| 55 | +
|
| 56 | + const msg = [ |
| 57 | + marker, |
| 58 | + '⚠️ This PR is missing a **Discord Discussion URL** in the body.', |
| 59 | + '', |
| 60 | + 'All PRs must reference a prior Discord discussion to ensure community alignment before implementation.', |
| 61 | + '', |
| 62 | + 'Please edit the PR description to include a link like:', |
| 63 | + '```', |
| 64 | + 'Discord Discussion URL: https://discord.com/channels/...', |
| 65 | + '```', |
| 66 | + '', |
| 67 | + `This PR will be **automatically closed in 3 days** if the link is not added.` |
| 68 | + ].join('\n'); |
| 69 | +
|
| 70 | + if (!old) { |
| 71 | + await github.rest.issues.createComment({ |
| 72 | + ...context.repo, |
| 73 | + issue_number: pr.number, |
| 74 | + body: msg |
| 75 | + }); |
| 76 | + } |
| 77 | + } else { |
| 78 | + // URL found — remove label and comment if present |
| 79 | + if (labels.includes(label)) { |
| 80 | + try { |
| 81 | + await github.rest.issues.removeLabel({ |
| 82 | + ...context.repo, |
| 83 | + issue_number: pr.number, |
| 84 | + name: label |
| 85 | + }); |
| 86 | + } catch (e) { |
| 87 | + if (e.status !== 404) throw e; |
| 88 | + } |
| 89 | + } |
| 90 | + if (old) { |
| 91 | + await github.rest.issues.deleteComment({ |
| 92 | + ...context.repo, |
| 93 | + comment_id: old.id |
| 94 | + }); |
| 95 | + } |
| 96 | + } |
0 commit comments