Skip to content

Detect pull requests against upstream repositories - #3907

Open
jakeleventhal wants to merge 7 commits into
pingdotgg:mainfrom
jakeleventhal:t3code/detect-upstream-fork-prs
Open

Detect pull requests against upstream repositories#3907
jakeleventhal wants to merge 7 commits into
pingdotgg:mainfrom
jakeleventhal:t3code/detect-upstream-fork-prs

Conversation

@jakeleventhal

@jakeleventhal jakeleventhal commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • detect pull requests opened from a fork against the conventional upstream GitHub remote
  • qualify fork branch lookups as owner:branch and target GitHub CLI operations at the upstream repository
  • keep unrelated remotes named upstream from overriding a valid GitHub origin

Root cause

PR discovery derived the fork-qualified head selector, but GitHub CLI still resolved the repository from the local checkout's origin. In a fork checkout, that queried the fork rather than the upstream repository where the pull request exists.

Impact

Branches pushed to a fork now show their upstream pull request metadata in T3 Code. Related PR operations consistently use the upstream repository context.

Validation

  • focused Git manager fork/upstream regression test
  • GitHub CLI, GitHub source-control provider, and provider registry suites
  • vp check
  • vp run typecheck

Note

Medium Risk
Changes core PR lookup and creation paths for forks, including a new REST API create path that may behave differently from gh pr create for permissions or edge cases.

Overview
Fixes PR discovery in fork checkouts where GitHub CLI still scoped to origin, so open PRs against the parent repo were missed.

Provider selection prefers a conventional GitHub fork layout: when origin and upstream share the same repo name on the same host but different owners, registry resolution and branch head context treat upstream as the PR target. Unrelated upstream remotes no longer override a valid GitHub origin.

GitHub CLI gains optional --repo on list/view/checkout/default-branch, resolves base vs head repo context (including via gh repo view parent metadata), uses gh pr view for qualified owner:branch selectors instead of gh pr list --head, and creates fork → upstream PRs through gh api while same-repo PRs still use gh pr create.

GitManager passes fork source metadata on create, uses targetRemoteName for merge-base range resolution, and improves remote URL parsing (HTTPS trailing slashes, GitHub Enterprise host in coordinates).

Reviewed by Cursor Bugbot for commit 13d7bdf. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Detect pull requests against upstream repositories for conventional GitHub forks

  • When a git remote named upstream is a conventional fork of origin (same host and repo name, different owner), the provider context now prefers the upstream remote, scoping PR listings, creation, checkout, and default branch queries to the upstream repository.
  • listOpenPullRequests detects qualified owner:branch head selectors and calls gh pr view directly instead of gh pr list, reducing API calls for cross-repo lookups.
  • createPullRequest resolves base and head repository context via gh repo view and uses gh api POST /repos/{base}/pulls when targeting a different repository (e.g. an org-owned fork), falling back to gh pr create for same-repo PRs.
  • Remote URL parsing in parseGitHubRepositoryNameWithOwnerFromRemoteUrl now handles SCP-style remotes and non-github.com hosts, returning host/owner/name coordinates for GHE instances.
  • Behavioral Change: repositories with a conventional upstream remote will now have PR operations (list, create, checkout, default branch) scoped to the upstream repository rather than origin.

Macroscope summarized 13d7bdf.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

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 Plus

Run ID: f1031ebe-3ecb-4eef-9fd6-64416e5f5fac

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

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.

@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Jul 12, 2026
@jakeleventhal
jakeleventhal marked this pull request as ready for review July 12, 2026 03:44
Comment thread apps/server/src/sourceControl/SourceControlProviderRegistry.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new feature for detecting pull requests against upstream repositories in fork workflows, with significant changes to PR detection, creation, and listing logic across multiple layers. Multiple unresolved review comments identify potential edge case bugs with org-owned forks and GitHub Enterprise hosts.

You can customize Macroscope's approvability policy. Learn more.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e512ba2d4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/server/src/sourceControl/SourceControlProviderRegistry.ts Outdated
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5df12cd1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/server/src/git/GitManager.ts Outdated
Comment thread apps/server/src/git/GitManager.ts Outdated
Comment thread apps/server/src/git/GitManager.ts Outdated
@github-actions github-actions Bot added size:L 100-499 changed lines (additions + deletions). and removed size:M 30-99 changed lines (additions + deletions). labels Jul 25, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b16508f364

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/server/src/sourceControl/GitHubCli.ts
@jakeleventhal
jakeleventhal force-pushed the t3code/detect-upstream-fork-prs branch from b16508f to 2d23111 Compare August 10, 2026 19:45
Comment thread apps/server/src/git/GitManager.ts
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts Outdated
Comment thread apps/server/src/git/GitManager.ts Outdated
Comment thread apps/server/src/git/GitManager.test.ts Outdated
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Aug 10, 2026

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Effect service conventions: two new Effect.catchTag usages were introduced. The convention is to use Effect.catchTags({ ... }) even when handling a single tag.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts Outdated
Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
- Detect upstream and fork repository context
- Use the GitHub API for cross-repository pull requests
- Preserve standard creation for same-repository pull requests
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts
@jakeleventhal
jakeleventhal force-pushed the t3code/detect-upstream-fork-prs branch from 41b6411 to 5b173be Compare August 10, 2026 20:15
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6f34800. Configure here.

Comment thread apps/server/src/git/GitManager.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant