Skip to content

fix(running-in-ci): add fork-PR check before pushing commits - #1412

Merged
max-sixty merged 5 commits into
mainfrom
hourly/review-22862714668
Mar 10, 2026
Merged

max-sixty merged 5 commits into
mainfrom
hourly/review-22862714668

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

  • Add fork-PR guidance to the running-in-ci skill: check headRepositoryOwner before pushing commits to a PR branch
  • Add guidance to avoid referencing commit SHAs from temporary/deleted branches

Fixes #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

  • Verify the skill file renders correctly and the guidance is clear
  • Future fork-PR interactions should check ownership before pushing

🤖 Generated with Claude Code

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]>
Comment thread .claude/skills/running-in-ci/SKILL.md Outdated
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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but is this accurate? surely a maintainer can generally push to PRs?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but isn't @worktrunk-bot a maintainer??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but sometimes we do want to push to the fork PR, not to add code snippets!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in d4fd49c — the guidance now says:

  1. Key rule: never create new branches on origin for fork PRs
  2. Default: push directly to the fork's PR branch (add fork as a remote)
  3. Fallback: code snippets only if pushing fails (e.g., "Allow edits from maintainers" is off)

worktrunk-bot and others added 3 commits March 9, 2026 20:19
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]>
Comment thread .claude/skills/running-in-ci/SKILL.md Outdated

# Add the fork as a remote and push
git remote add fork https://github.com/<owner>/<repo>.git
git push fork HEAD:<branch>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there simpler commands for this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! gh pr checkout handles the fork remote setup automatically:

gh pr checkout <number>
# make changes, commit...
git push

Simplified in eefcd08.

@max-sixty
max-sixty merged commit 4e62058 into main Mar 10, 2026
24 checks passed
@max-sixty
max-sixty deleted the hourly/review-22862714668 branch March 10, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-mention: bot pushes branch to upstream before checking if PR is from a fork

2 participants