Skip to content

Commit 1408529

Browse files
authored
PR triage requires checks to pass (#3503)
* Add formatting workflow to git filter-repo path rename * Verify checks pass before triaging
1 parent 6736a09 commit 1408529

4 files changed

Lines changed: 53 additions & 6 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,56 @@ jobs:
88
runs-on: ubuntu-latest
99
if: github.event.label.name == 'triaged'
1010
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+
1149
- name: Repository Dispatch
12-
uses: peter-evans/repository-dispatch@v4
50+
uses: actions/github-script@v7
51+
env:
52+
DISPATCH_CONTEXT: ${{ toJson(github) }}
1353
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+
});

.github/workflows/pull_request_checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pull Request Checks
1+
name: Tests
22

33
on:
44
pull_request:
File renamed without changes.

engine/Tools/SboxBuild/Steps/SyncPublicRepo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ protected override ExitCode RunInternal()
9595
{ "public/.gitattributes", ".gitattributes" },
9696
{ "public/.github/workflows/pull_request.yml", ".github/workflows/pull_request.yml" },
9797
{ "public/.github/workflows/pull_request_checks.yml", ".github/workflows/pull_request_checks.yml" },
98+
{ "public/.github/workflows/pull_request_formatting.yml", ".github/workflows/pull_request_formatting.yml" },
9899
{ "public/README.md", "README.md" },
99100
{ "public/LICENSE.md", "LICENSE.md" },
100101
{ "public/CONTRIBUTING.md", "CONTRIBUTING.md" },

0 commit comments

Comments
 (0)