fix: CORE4-labelling check - get labels by GitHub API, not event payload #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change fixes a race-condition that very occasionally causes the CORE4 check to fail on a PR with valid labelling, and continue to fail even if it is re-attempted with multiple job invocations afterwards.
Background
CORE4-labelling check
The CORE4-labelling check was created with PR #105, and updated a little later with PR #108 to accept
dependenciesas a valid label - because both Dependabot & Scala Steward (as we have it configured) apply that label to their PRs. The CORE4 check was applied to Guardian repos in early December 2025.Atomicity of creation & labelling of PRs using the GitHub API
When PRs are created through the GitHub API (eg, by Scala Steward), there is no documented way to both create and label them in a single atomic API operation:
...so PRs are first created, and then labelled.
Problem
The CORE4-labelling check currently obtains the labels upon PRs by reading the webhook payload object for
pull_request:.github/.github/workflows/require-label.yaml
Line 16 in 6ba60f6
...but the webhook payload does not change, even if the workflow is manually re-run - only a new webhook event can pick up label changes.
This leads to the rare failure case where a CORE4 check run fails, and continues to fail, on a PR with valid labelling:
...this was seen with this Scala Steward PR, where the CORE4 check failed, and continues to fail:
Workaround
Remove the label, wait 10 seconds, and then re-add it. This will create 2 new webhook payloads, and the second - so long as it runs after the first - will have the label in it.
Fix
Use the GitHub API, not the the event payload, to get the labelling information - so simply re-running the GitHub workflow will work to clear any problem - and as the GitHub API information is being generated seconds later than the webhook, it stands more chance of including the applied label.
Testing
Tried out this branch with guardian/play-secret-rotation#580, where it worked well as I added and removed labels - the only difference being, this updated approach would be able to recover by just re-running the job if anything went wrong, rather than toggling the label.
See also