fix(ci): edit PRs through REST so the bot token does not need read:org (v5) - #25379
Open
AztecBot wants to merge 1 commit into
Open
fix(ci): edit PRs through REST so the bot token does not need read:org (v5)#25379AztecBot wants to merge 1 commit into
AztecBot wants to merge 1 commit into
Conversation
gh pr edit resolves the PR through a GraphQL query that selects the review requests, whose User.login / Team.name / Team.slug fields classic PATs gate behind read:org. AZTEC_BOT_GITHUB_TOKEN carries only repo + workflow, so every gh pr edit run under it is rejected before the edit is attempted. The equivalent REST endpoints need only the repo scope.
ludamad
approved these changes
Sep 1, 2026
ludamad
marked this pull request as ready for review
September 1, 2026 15:05
ludamad
approved these changes
Sep 1, 2026
ludamad
enabled auto-merge (squash)
September 1, 2026 15:05
alexghr
approved these changes
Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Port of #25378 onto the spartan-v5 train.
Why
gh pr editresolves the PR through a GraphQL query that always selects the PR's review requests, whoseUser.login/Team.name/Team.slugfields classic PATs gate behindread:org.AZTEC_BOT_GITHUB_TOKENcarries onlyrepo+workflow, so everygh pr editrun under it is rejected before the edit is attempted:The equivalent REST endpoints need only the
reposcope, so nothing about the token changes. That is the same conversion#25378makes onnext.The four sites
#25378fixes, ported as-isscripts/merge-train/update-pr-body.sh--body→PATCH .../pulls/{n}scripts/merge-train/wakeup-prs.sh--add-label ci-wakeup-pr-after-merge→POST .../issues/{n}/labels.github/workflows/ci3.yml--remove-label ci-wakeup-pr-after-merge→DELETE .../labels/{name}.github/ci3.sh--remove-label ci-release-pr→DELETE .../labels/{name}.github/workflows/ci3-external.yml(x2)--remove-label ci-external→DELETE .../labels/{name}Bodies and label lists are built with
jqrather than-f body=..., so a commit subject containing quotes,$or@cannot corrupt the request.Four more sites that exist only on this branch
ci3.ymlandci3_success.shhave diverged fromnext, and the v5 copies carry four additionalgh pr editcalls under the same token. They are the same one-line transform, so they are converted here too — two of them are currently hard failures rather than silent ones:ci3.yml—--remove-label ci-network-scenario(guarded by|| true, silent)ci3.yml—--remove-label ci-network-bench(guarded by|| true, silent)ci3.yml—--remove-label ci-network-kind— no guard, and it is the first step of theci-network-kindjob, so that job fails immediately on every labelled PR and the KIND tests never run. Converted, and given the|| trueits three sibling one-time-use strips already have, so a missing label cannot kill a 3-hour run.ci3_success.sh—--remove-label ci-squash-and-merge— no guard, and it sits betweensquash-pr.shandgh pr merge --auto, soci-squash-and-mergecurrently aborts before the auto-merge is ever enabled.That last one also picks up the ordering
nextalready uses: the label is dropped beforesquash-pr.shruns, because that script force-pushes and the resultingsynchronizeevent would otherwise re-enter this path with the label still set. This is the one place where the port carries anext-side behavioural fix along with the scope fix rather than being a pure like-for-like swap.Testing
bash -non the four shell scripts, YAML parse on both workflows, and thejqpayloads checked against subjects containing quotes,&and$. The endpoints cannot be exercised from a sandbox; the proof is the nextmerge-train/spartan-v5push updating the PR body instead of exiting 1.Deliberately not included
Sites that need a bespoke transform (PR URL → number, or a dynamically built label list) rather than the one-liner above, same exclusions as
#25378plus the two that are v5-only:.github/workflows/release-canary-pr-update.yml:135— builds--add-labelflags in a string; it is what appliesci-release-prandci-network-kindin the first place, so those two labels are likely never being set on this branch at all.github/workflows/auto-rebase-pr.yml,.github/workflows/pull-noir.yml,scripts/socket-fix-ci.sh,scripts/backport_to_staging.shci3-external.yml'sci-external-oncestrip is untouched on purpose: it runs undergithub.token, which is not scope-limited this way.Created by claudebox · group:
slackbot· requested by ludamad (@ludamad) · Slack thread