Skip to content

feat(github): use the right account for each repository - #6052

Closed
DominicVonk wants to merge 20 commits into
pingdotgg:mainfrom
DominicVonk:t3code/support-multiple-github-tokens
Closed

DominicVonk wants to merge 20 commits into
pingdotgg:mainfrom
DominicVonk:t3code/support-multiple-github-tokens

Conversation

@DominicVonk

@DominicVonk DominicVonk commented Aug 10, 2026 •

Copy link
Copy Markdown

What Changed

  • Discover every signed-in GitHub account from gh auth status --json hosts.
  • Let users select a default account per GitHub host and override it for individual repository owners.
  • Apply the selected account consistently to source-control actions and Pull Requests.
  • Support the same routing for GitHub.com and configured GitHub Enterprise hosts without storing tokens in T3 Code.

Why

T3 Code previously used whichever GitHub CLI account happened to be active. Users signed into personal, work, or GitHub Enterprise accounts could therefore access a repository with the wrong identity unless they switched accounts outside T3 Code.

Routing by host and repository owner matches how users separate those accounts while keeping GitHub CLI as the token authority.

UI Changes

Previously, the GitHub provider settings did not expose account selection. The updated UI shows each host's default account and lets users add repository-owner overrides.

Before After
GitHub settings before account routing GitHub account defaults and repository owner overrides

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Created with GPT-5.6 Sol in T3 Code.


Note

High Risk
Changes GitHub authentication and credential selection for all CLI/PR operations, including token injection and how viewers/batches are resolved across repositories.

Overview
Lets users pick which signed-in GitHub account T3 Code uses per host, with optional overrides by repository owner, instead of always using the active gh account.

Adds githubAccountRouting settings and a Source Control settings UI to choose defaults and owner overrides. Credentials stay with GitHub CLI / env vars; T3 Code only stores login + token source.

GitHubCli now resolves a credential route for each call and injects GH_TOKEN / GH_ENTERPRISE_TOKEN accordingly. Pull request listing and viewer resolution batch by that route so repos on the same host with different accounts stay separate, and involvement filtering can use per-repository viewers.

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

Note

Route GitHub CLI calls using the correct account per repository

  • Adds GitHubAccountRouting settings (default account per host, per-owner overrides) persisted in ServerSettings and editable via a new settings UI in GitHubAccountSettings.tsx.
  • Introduces credential routing in GitHubCli.ts: selects a token from the environment or gh keyring based on the chosen account, then injects GH_TOKEN/GH_ENTERPRISE_TOKEN for every CLI/GraphQL call.
  • All GitHub CLI operations in GitHubPullRequestCli.ts now receive explicit host and repositories scoping so the right token is used per request.
  • Viewer resolution and PR listing in PullRequestService.ts now operate per provider batch key (which maps to a credential route) rather than per host, so repositories on the same host but different accounts are handled independently.
  • Risk: getViewerLogin, getBatchKey, and execute interfaces are extended with required host/repository parameters, which is a breaking change for any callers of GitHubPullRequestCli or GitHubCli outside this PR.

Macroscope summarized 7620cb2.

@coderabbitai

coderabbitai Bot commented Aug 10, 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: eca03658-eba4-438a-8d8d-4bbf6e109c6b

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

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 vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XL 500-999 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.

Two findings in apps/server/src/sourceControl/GitHubCli.ts: new validation failures fabricate an Error only to satisfy the required cause field, and the real reason never reaches the error's structural attributes or message.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts
Comment thread apps/web/src/components/settings/SourceControlSettings.tsx Outdated
Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated

@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 review of the changed server/contracts/web TypeScript. The GitHub account-selection code in apps/server/src/sourceControl/GitHubCli.ts carries new failure modes in synthetic new Error(...) causes attached to pre-existing generic error tags, which the conventions disallow. One test-only namespace/deprecation note is included as well.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
Comment thread apps/server/src/sourceControl/GitHubCli.ts
Comment thread apps/server/src/sourceControl/GitHubCli.ts
Comment thread apps/server/src/sourceControl/GitHubCli.test.ts Outdated

@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.

One error-modelling finding in apps/server/src/sourceControl/GitHubCli.ts: the new gh auth token subprocess failure is collapsed onto GitHubCliAuthenticationError instead of the file's reusable fromVcsError classifier.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
@DominicVonk
DominicVonk marked this pull request as ready for review August 10, 2026 21:32
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts
@macroscopeapp

macroscopeapp Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a substantial new feature for multi-account GitHub support with per-owner credential routing. It adds ~1600 lines including new credential selection logic, settings schemas, and UI components, and involves security-sensitive token handling from environment variables and the GitHub CLI keyring. The scope and authentication implications warrant human review.

No code changes detected at 72e6b4e. Prior analysis still applies.

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

@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.

One convention finding: the new local service dependency is imported by name rather than through its module namespace. Everything else in the account-selection work (dedicated tagged errors with structural fields and no invented causes, yield*-based dependency acquisition in make, subpath namespace imports for effect/*, no new Layer.succeed/ManagedRuntime/runPromise) matches the conventions.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/GitHubCli.ts Outdated
Comment thread apps/web/src/components/settings/SourceControlSettings.tsx Outdated
Comment thread apps/web/src/components/settings/SourceControlSettings.tsx Outdated
Comment thread apps/web/src/components/settings/SourceControlSettings.tsx Outdated
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Aug 10, 2026
@DominicVonk
DominicVonk force-pushed the t3code/support-multiple-github-tokens branch from b374363 to fb7da77 Compare August 10, 2026 22:42

@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.

One convention finding on the new GitHub credential failure model in apps/server/src/sourceControl/GitHubCli.ts. Everything else in the changed Effect service scope (namespace imports, ServerSettings acquisition via the environment, make/layer shape, the pure GitHubCredentials routing helper, and the new tests) looks consistent with the conventions.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/GitHubCli.ts
Comment thread apps/server/src/pullRequest/GitHubPullRequestCli.ts
Comment thread apps/server/src/pullRequest/GitHubPullRequestCli.ts

@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 f84749e. Configure here.

Comment thread apps/server/src/sourceControl/GitHubCli.ts
@DominicVonk DominicVonk changed the title feat(github): support multiple accounts feat(github): use the right account for each repository Aug 11, 2026
@t3-code

t3-code Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

thanks for the contribution! closing this at the request of @StiensWout because it currently has merge conflicts. if you think closing this was a mistake, please feel free to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ 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