PR triage requires checks to pass (#3503)

* Add formatting workflow to git filter-repo path rename

* Verify checks pass before triaging
This commit is contained in:
Lorenz Junglas
2025-12-01 11:43:11 +01:00
committed by GitHub
parent 6736a09ad8
commit 1408529189
4 changed files with 54 additions and 7 deletions

View File

@@ -8,10 +8,56 @@ jobs:
runs-on: ubuntu-latest
if: github.event.label.name == 'triaged'
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v4
- name: Ensure PR checks passed
uses: actions/github-script@v7
with:
token: ${{ secrets.SBOXBOT_TOKEN }}
repository: Facepunch/sbox
event-type: pr-triaged
client-payload: '{"github": ${{ toJson(github) }}}'
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const requiredChecks = ['Tests', 'Formatting'];
const pr = context.payload.pull_request;
if (!pr) {
throw new Error('No pull request found in event payload.');
}
const { data } = await github.rest.checks.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: pr.head.sha,
per_page: 100
});
const checkRuns = data.check_runs ?? [];
for (const requiredCheck of requiredChecks) {
const match = checkRuns.find(run => (run.name ?? '') === requiredCheck);
if (!match || match.conclusion !== 'success') {
const status = match ? (match.conclusion ?? match.status ?? 'unknown') : 'missing';
core.warning(`Required check '${requiredCheck}' did not pass (${status}). Removing triaged label.`);
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: 'triaged'
});
throw new Error('Cannot triage until required checks succeed.');
}
}
- name: Repository Dispatch
uses: actions/github-script@v7
env:
DISPATCH_CONTEXT: ${{ toJson(github) }}
with:
github-token: ${{ secrets.SBOXBOT_TOKEN }}
script: |
const clientPayload = JSON.parse(process.env.DISPATCH_CONTEXT);
await github.rest.repos.createDispatchEvent({
owner: 'Facepunch',
repo: 'sbox',
event_type: 'pr-triaged',
client_payload: { github: clientPayload }
});

View File

@@ -1,4 +1,4 @@
name: Pull Request Checks
name: Tests
on:
pull_request:

View File

@@ -95,6 +95,7 @@ internal class SyncPublicRepo( string name, bool dryRun = false ) : Step( name )
{ "public/.gitattributes", ".gitattributes" },
{ "public/.github/workflows/pull_request.yml", ".github/workflows/pull_request.yml" },
{ "public/.github/workflows/pull_request_checks.yml", ".github/workflows/pull_request_checks.yml" },
{ "public/.github/workflows/pull_request_formatting.yml", ".github/workflows/pull_request_formatting.yml" },
{ "public/README.md", "README.md" },
{ "public/LICENSE.md", "LICENSE.md" },
{ "public/CONTRIBUTING.md", "CONTRIBUTING.md" },