Skip to content

fix(github): load PR details on fork checkouts by preferring upstream (#7331) - #9384

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-7331-fork-pr-owner-repo
Jul 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-7331-fork-pr-owner-repo

Conversation

@nwparker

@nwparker nwparker commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

On a fork checkout — where origin points at your personal fork and upstream points at the parent repo — opening PR details failed to load. GitHub PRs live on the upstream parent, but the PR-lookup resolver only ever consulted the fork.

Root cause: getOwnerRepo() in src/main/github/github-repository-identity.ts:206 resolved only the origin remote, so gh pr view <N> --repo <fork> targeted the fork and returned Could not resolve to a PullRequest. The sibling getIssueOwnerRepo() already preferred upstream first, so issues loaded but PRs did not — the exact divergence #7331 reports.

Fix: make getOwnerRepo() prefer the upstream remote when present and fall back to origin otherwise, mirroring getIssueOwnerRepo(). Repos with no upstream remote are unaffected (behavior unchanged).

Because getOwnerRepo() is also used by callers that specifically need the checkout's own (origin) identity, those call sites were switched to the origin-only primitive getOwnerRepoForRemote(repoPath, 'origin', …) so their behavior is preserved:

  • getRepoSlug (src/main/github/client.ts:1649) — the slug is the checkout's own identity used for renderer display and icon autodetect; must stay origin-based.
  • getRepoUpstream (src/main/github/client.ts:1675) — its offline fork-parent fast-path compares origin against the upstream remote; both must be distinct.
  • resolvePrWorkItemSource (src/main/github/client.ts:1093) — combines origin + upstream itself, so it needs origin explicitly.
  • createGitHubPullRequest (src/main/github/client.ts:1889) — the head branch is unqualified and lives on the fork, so gh pr create must run against origin.

Fixes #7331

Evidence (proof of improvement)

New test: src/main/github/github-repository-identity.fork-owner-repo.test.ts (imports the real github-repository-identity and client modules; only the git runner / ssh dispatch / config-signature boundaries are mocked).

 RUN  v4.1.5

 Test Files  1 passed (1)
      Tests  7 passed (7)

Coverage:

  • getOwnerRepo prefers the upstream parent on a fork checkout — returns stablyai/orca, not the fork fsdwen/orca.
  • getOwnerRepo and getIssueOwnerRepo now agree on a fork checkout (the pre-fix discrepancy is gone).
  • getOwnerRepo falls back to origin when there is no upstream remote (non-fork behavior unchanged).
  • The missing-upstream probe is cached, so repeat lookups don't respawn git.
  • SSH-style remote URLs ([email protected]:…) resolve the upstream parent too.
  • getOwnerRepoForRemote('origin') still resolves the fork itself (origin-only primitive intact).
  • getRepoUpstream still resolves the fork parent offline without any gh call (fast-path regression guard).

Failing-on-main → passing-on-fix reasoning: the reproduction test in the scan worktree pins the buggy behavior — on main, getOwnerRepo(forkCheckout) returns { owner: 'fsdwen', repo: 'orca' } (the fork) while getIssueOwnerRepo returns { owner: 'stablyai', repo: 'orca' }, and the two resolvers disagree. After this change getOwnerRepo returns the upstream parent and the two resolvers agree, which is what the new test asserts.

Proof of no regression

  • Full src/main/github/ vitest suite: 27 files, 389 tests passed.
  • typecheck:tsc:node (tsc --noEmit -p config/tsconfig.node.json): clean, no errors.
  • oxlint on all changed files: exit 0, no warnings/errors. Pre-commit hook (oxlint + react-doctor + oxfmt) passed.

Unchanged behaviors and why:

  • Non-fork repos have no upstream remote, so getOwnerRepo falls through to the identical origin resolution — the negative upstream probe is cached to avoid extra git spawns.
  • getRepoSlug continues returning the checkout's own (origin) identity, so renderer display and icon autodetect are untouched.
  • getRepoUpstream's offline fork-detection fast-path still compares a distinct origin vs. upstream, so fork parents still resolve without a network gh call.
  • createGitHubPullRequest still targets origin, so PR creation pushes to the fork the branch actually lives on.
  • Existing github tests that previously defined the origin candidate through getOwnerRepo were rerouted to the origin-only getOwnerRepoForRemote mock, asserting the same end-user outcomes.

ELI5

When you copy someone else's project to your own account (a "fork") and then look at a pull request, the request actually lives on the original project, not your copy. The app was mistakenly looking in your copy, so the PR page came up empty. Now it looks in the original project first — just like it already did for issues — so pull requests load correctly, and everything works exactly as before for projects that aren't forks.

Credit

This lands the fix community-identified in #7332 by @fsdwen (who also filed #7331 with the root-cause analysis) and hardened in #7513 by @brennanb2025. Both are credited as commit co-authors. This PR carries the same upstream-first core change plus an audit of every getOwnerRepo call site (notably keeping getRepoSlug on the checkout's own origin identity) against current main.

Made with Orca 🐋

…7331)

getOwnerRepo() only consulted the origin remote, so on a fork checkout
(origin -> fork, upstream -> parent) PR detail lookups targeted the fork
and failed with 'Could not resolve to a PullRequest'. Make getOwnerRepo
prefer upstream when present, mirroring getIssueOwnerRepo, and fall back
to origin when there is no upstream remote.

Callers that need the checkout's own identity (getRepoSlug), that combine
both remotes themselves (getRepoUpstream, resolvePrWorkItemSource), or that
create a PR against the pushed branch (createGitHubPullRequest) now request
the origin remote explicitly via getOwnerRepoForRemote.

Fixes #7331

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker marked this pull request as ready for review July 18, 2026 21:33
@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Repository identity resolution now checks the upstream remote before origin and retains origin-specific resolution through getOwnerRepoForRemote. GitHub client operations for PR sources, repository slugs, fork detection, and PR creation explicitly resolve origin where required. Tests update remote mocks, add fork and upstream-only coverage, validate SSH and WSL behavior, and verify offline upstream detection. Documentation clarifies upstream-first participant resolution and transient issue lookup handling.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the fix, but it does not follow the required template sections or include screenshots, AI review, security audit, or notes. Rewrite it to match the template: add Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections, or state 'No visual change' if applicable.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code changes match #7331 by making getOwnerRepo prefer upstream first and preserving origin-only callers.
Out of Scope Changes check ✅ Passed The additional test and doc updates stay focused on the fork-checkout PR-resolution fix and its regressions.
Title check ✅ Passed It clearly summarizes the main change: PR details on fork checkouts now prefer upstream.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@nwparker
nwparker merged commit 4930c87 into main Jul 18, 2026
4 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#9384)

On a fork checkout (origin=fork, upstream=parent) PR details failed to load because getOwnerRepo() resolved only the origin remote while GitHub PRs live on the upstream parent. Make getOwnerRepo() prefer upstream (mirroring getIssueOwnerRepo), and pin the call sites that genuinely need the checkout's own origin identity (getRepoSlug, getRepoUpstream, createGitHubPullRequest, resolvePrWorkItemSource) to the origin-only primitive.

Lands the fix community-identified in stablyai#7332 and hardened in stablyai#7513.

Closes stablyai#7331

Co-authored-by: fsdwen <[email protected]>
Co-authored-by: brennanb2025 <[email protected]>
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.

[Bug]: PR details fail to load for fork repositories — getOwnerRepo only checks origin

1 participant