|
8 | 8 | runs-on: ubuntu-latest |
9 | 9 | if: github.event.label.name == 'triaged' |
10 | 10 | steps: |
| 11 | + - name: Ensure PR checks passed |
| 12 | + uses: actions/github-script@v7 |
| 13 | + with: |
| 14 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 15 | + script: | |
| 16 | + const requiredChecks = ['Tests', 'Formatting']; |
| 17 | +
|
| 18 | + const pr = context.payload.pull_request; |
| 19 | + if (!pr) { |
| 20 | + throw new Error('No pull request found in event payload.'); |
| 21 | + } |
| 22 | +
|
| 23 | + const { data } = await github.rest.checks.listForRef({ |
| 24 | + owner: context.repo.owner, |
| 25 | + repo: context.repo.repo, |
| 26 | + ref: pr.head.sha, |
| 27 | + per_page: 100 |
| 28 | + }); |
| 29 | +
|
| 30 | + const checkRuns = data.check_runs ?? []; |
| 31 | + for (const requiredCheck of requiredChecks) { |
| 32 | + const match = checkRuns.find(run => (run.name ?? '') === requiredCheck); |
| 33 | +
|
| 34 | + if (!match || match.conclusion !== 'success') { |
| 35 | + const status = match ? (match.conclusion ?? match.status ?? 'unknown') : 'missing'; |
| 36 | + core.warning(`Required check '${requiredCheck}' did not pass (${status}). Removing triaged label.`); |
| 37 | +
|
| 38 | + await github.rest.issues.removeLabel({ |
| 39 | + owner: context.repo.owner, |
| 40 | + repo: context.repo.repo, |
| 41 | + issue_number: pr.number, |
| 42 | + name: 'triaged' |
| 43 | + }); |
| 44 | +
|
| 45 | + throw new Error('Cannot triage until required checks succeed.'); |
| 46 | + } |
| 47 | + } |
| 48 | +
|
11 | 49 | - name: Repository Dispatch |
12 | | - uses: peter-evans/repository-dispatch@v4 |
| 50 | + uses: actions/github-script@v7 |
| 51 | + env: |
| 52 | + DISPATCH_CONTEXT: ${{ toJson(github) }} |
13 | 53 | with: |
14 | | - token: ${{ secrets.SBOXBOT_TOKEN }} |
15 | | - repository: Facepunch/sbox |
16 | | - event-type: pr-triaged |
17 | | - client-payload: '{"github": ${{ toJson(github) }}}' |
| 54 | + github-token: ${{ secrets.SBOXBOT_TOKEN }} |
| 55 | + script: | |
| 56 | + const clientPayload = JSON.parse(process.env.DISPATCH_CONTEXT); |
| 57 | +
|
| 58 | + await github.rest.repos.createDispatchEvent({ |
| 59 | + owner: 'Facepunch', |
| 60 | + repo: 'sbox', |
| 61 | + event_type: 'pr-triaged', |
| 62 | + client_payload: { github: clientPayload } |
| 63 | + }); |
0 commit comments