Repository navigation
fix(running-in-ci): add fork-PR check before pushing commits - #1412
Conversation
The bot pushed a branch to upstream before realizing PR #1408 was from a fork, then had to delete it. Add guidance to check headRepositoryOwner before pushing, and avoid referencing SHAs from deleted branches. Closes #1411 Co-Authored-By: Claude Opus 4.6 <[email protected]>
| gh pr view <number> --json headRepositoryOwner --jq '.headRepositoryOwner.login' | ||
| ``` | ||
|
|
||
| If the owner is **not** `max-sixty`, it's a fork PR — you cannot push to it. |
There was a problem hiding this comment.
but is this accurate? surely a maintainer can generally push to PRs?
There was a problem hiding this comment.
Good catch — you're right, maintainers can push to fork PRs when "Allow edits from maintainers" is enabled. The restriction is specifically that the CI bot's GITHUB_TOKEN is scoped to the base repo and can't push to fork branches.
Updated the wording to clarify this in a5b8559.
There was a problem hiding this comment.
You're right — @worktrunk-bot uses a PAT (WORKTRUNK_BOT_TOKEN) with maintainer access, not the default GITHUB_TOKEN. It's not a token permissions issue.
The real problem from #1411 was the bot creating a new branch (feat/other-github-hosts) and pushing it to origin (upstream), rather than pushing to the fork's existing PR branch. Updated the wording in 4601170 to reflect this: the guidance now says "don't create new branches and push them to origin" instead of the incorrect claim about token access.
There was a problem hiding this comment.
but sometimes we do want to push to the fork PR, not to add code snippets!
There was a problem hiding this comment.
You're right — the guidance is too restrictive. The bot can push to fork PR branches directly (PAT + "Allow edits from maintainers"), so defaulting to code snippets is unnecessarily limiting.
How about restructuring to: the key rule is "don't create new branches on origin" for fork PRs, and the default should be pushing to the fork's branch when possible (add the fork as a remote), falling back to code snippets only when that fails?
There was a problem hiding this comment.
Updated in d4fd49c — the guidance now says:
- Key rule: never create new branches on
originfor fork PRs - Default: push directly to the fork's PR branch (add fork as a remote)
- Fallback: code snippets only if pushing fails (e.g., "Allow edits from maintainers" is off)
Maintainers can push to fork PRs when "Allow edits from maintainers" is enabled, but the CI bot's GITHUB_TOKEN is scoped to the base repo. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…t token access @worktrunk-bot uses a PAT with maintainer access, not the default GITHUB_TOKEN. The real issue is creating new branches on origin (upstream) instead of pushing to the fork's branch. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Restructure fork-PR guidance: the key rule is "don't create new branches on origin", not "never push". Default to pushing directly to the fork's PR branch (via a fork remote), falling back to code snippets only when that fails. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
|
||
| # Add the fork as a remote and push | ||
| git remote add fork https://github.com/<owner>/<repo>.git | ||
| git push fork HEAD:<branch> |
There was a problem hiding this comment.
are there simpler commands for this?
There was a problem hiding this comment.
Yes! gh pr checkout handles the fork remote setup automatically:
gh pr checkout <number>
# make changes, commit...
git pushSimplified in eefcd08.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
running-in-ciskill: checkheadRepositoryOwnerbefore pushing commits to a PR branchFixes #1411 — in run 22862093653, the bot pushed a branch to upstream before discovering PR #1408 was from a fork, then had to delete it.
Test plan
🤖 Generated with Claude Code