Skip to content

fix: support fork PRs by fetching via refs/pull/N/head#1219

Open
RobotSail wants to merge 1 commit intoanthropics:mainfrom
RobotSail:fix/fork-pr-checkout
Open

fix: support fork PRs by fetching via refs/pull/N/head#1219
RobotSail wants to merge 1 commit intoanthropics:mainfrom
RobotSail:fix/fork-pr-checkout

Conversation

@RobotSail
Copy link
Copy Markdown

Summary

  • Fix fork (cross-repository) PRs failing with fatal: couldn't find remote ref <branch>
  • Add isCrossRepository field to the PR GraphQL query and type
  • When a fork PR is detected, fetch using pull/<number>/head:<branch> refspec instead of fetching by branch name

Problem

When @claude is tagged on a PR from a fork, the action runs git fetch origin --depth=20 <branch-name>. Since the branch only exists on the fork's remote (not origin), this fails. GitHub exposes fork PR content at refs/pull/<number>/head, which works regardless of source repo.

Changes

File Change
src/github/api/queries/github.ts Add isCrossRepository to PR GraphQL query
src/github/types.ts Add isCrossRepository: boolean to GitHubPullRequest
src/github/operations/branch.ts Use pull/N/head refspec for fork PRs in setupBranch()
test/data-formatter.test.ts Add isCrossRepository to test fixture

Test plan

  • bun run typecheck passes
  • bun test — 664 tests pass, 0 failures

Fixes #1218

🤖 Generated with Claude Code

For cross-repository (fork) PRs, the head branch doesn't exist on the
origin remote. The action previously tried `git fetch origin <branch>`
which fails with "couldn't find remote ref".

Now detects fork PRs via `isCrossRepository` from the GraphQL API and
fetches using `pull/<number>/head:<branch>` refspec instead, which
GitHub exposes for all PR heads regardless of source repo.

Changes:
- Add `isCrossRepository` to PR GraphQL query and type
- Use `refs/pull/N/head` refspec for fork PRs in setupBranch()

Fixes anthropics#1218
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.

Fork PRs fail: action fetches branch by name instead of using refs/pull/N/head

1 participant