Skip to content

fix(server): respect fork remotes when creating PRs#904

Open
binbandit wants to merge 1 commit intopingdotgg:mainfrom
binbandit:t3code/fix-create-pr-forks
Open

fix(server): respect fork remotes when creating PRs#904
binbandit wants to merge 1 commit intopingdotgg:mainfrom
binbandit:t3code/fix-create-pr-forks

Conversation

@binbandit
Copy link
Contributor

@binbandit binbandit commented Mar 11, 2026

Summary

  • resolve PR base repositories from GitHub fork metadata instead of assuming the local tracking remote tells us the whole story
  • list PRs against the parent repository and filter by the actual head repository/owner so fork clones and fork worktrees resolve the right PR
  • create cross-repo PRs with --repo <base> and --head <owner>:<branch>, and add regression coverage for origin=fork, upstream=base layouts

Problem

The create-pr flow inferred too much from the local remote layout. In a common fork setup where origin points at a fork and upstream points at the main repository, the server could look up and create PRs against the wrong repository. It also depended on owner-qualified gh pr list --head behavior that the real GitHub CLI does not support.

Testing

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test src/git/Layers/GitHubCli.test.ts src/git/Layers/GitManager.test.ts

Note

Fix PR creation and detection to respect fork remotes in GitManager

  • Adds getRepositoryMetadata to GitHubCliShape and its implementation, fetching fork status, default branch, and parent repository from gh repo view.
  • Refactors resolveBranchHeadContext in GitManager.ts to detect fork remotes and resolve the correct base repository (using parent repo when the head is a fork).
  • createPullRequest now passes --repo <base> to gh pr create when a base repository is resolved, targeting the upstream repo instead of the fork.
  • PR lookup (findOpenPr, findLatestPr) switches from probing multiple head selector variants to a single gh pr list --repo <base> --head <branch> call filtered by repository/owner match.
  • Behavioral Change: PRs created from fork clones now target the parent repository; existing flows using owner-qualified head selectors are replaced by repository-scoped lookups.

Macroscope summarized 5e30124.

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 15c58d5c-a3e5-437a-9257-160712f58c8c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant