Skip to content

fix(source-control): handle self-hosted GitLab and multi-account GitHub auth#2480

Open
GuilhermeVieiraDev wants to merge 5 commits intopingdotgg:mainfrom
GuilhermeVieiraDev:fix/gitlab-self-hosted-detection
Open

fix(source-control): handle self-hosted GitLab and multi-account GitHub auth#2480
GuilhermeVieiraDev wants to merge 5 commits intopingdotgg:mainfrom
GuilhermeVieiraDev:fix/gitlab-self-hosted-detection

Conversation

@GuilhermeVieiraDev
Copy link
Copy Markdown
Contributor

@GuilhermeVieiraDev GuilhermeVieiraDev commented May 3, 2026

What Changed

Improved source-control auth discovery for mixed provider auth states.

For GitLab:

  • Detect authenticated self-hosted GitLab remotes even when the remote host does not contain gitlab.
  • Keep normal remote URL heuristics as the first path, but allow providers to refine an unknown remote when they have a stronger auth signal.
  • Parse glab auth status by host, so one failing configured GitLab host does not hide another authenticated host.
  • Only claim an unknown remote as GitLab when the remote host exactly matches an authenticated glab host.

For GitHub:

  • Use gh auth status --json hosts instead of parsing human-readable output.
  • Support multiple GitHub accounts on the same host.
  • Prefer the active successful account, then fall back to any successful account.
  • Treat parsed GitHub auth JSON with no successful accounts as unauthenticated.
  • Keep GitHub authenticated when at least one account is valid, preferring the active valid account.

Why

Self-hosted GitLab instances can live on arbitrary domains, so checking whether a remote host contains gitlab is not enough.

The GitLab issue showed up when glab auth status returned a mixed result: one configured host failed auth, while the repo's self-hosted instance was authenticated. The old path treated the whole command as unauthenticated because the command exited non-zero, and provider routing still saw the repo as unknown because the remote host did not look like GitLab.

The GitHub issue is the same class of auth-discovery problem: gh auth status can include multiple accounts for github.com, and one stale inactive account should not make GitHub look unauthenticated when another account is active and valid. GitHub exposes this state as structured JSON, so this now uses the CLI's JSON contract instead of human-readable terminal text.

Bitbucket and Azure DevOps are left unchanged because their auth models are different: Bitbucket is API-token based in T3 Code, and Azure DevOps relies on Azure CLI login plus az repos --detect.

UI Changes

No UI changes. The settings screen now receives more accurate source-control auth state.

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

Note

Medium Risk
Changes provider detection and CLI auth parsing for GitHub/GitLab, which can alter how repos are classified and whether integrations report authenticated (including reliance on gh auth status --json). Failures could mis-route providers or misreport auth status in some environments.

Overview
Improves source-control discovery to handle mixed auth states across multiple configured accounts/hosts, especially for self-hosted GitLab and multi-account GitHub.

GitHub auth probing now uses gh auth status --json hosts and parses structured output to select the active authenticated account (or any authenticated account), while treating parsed-but-all-failed results as explicitly unauthenticated.

GitLab auth probing now parses glab auth status by host so one failing host doesn’t hide another successful login, and provider detection can now refine an initially unknown remote into GitLab when the remote host exactly matches an authenticated glab host.

Remote URL parsing now preserves ports in baseUrl (URL.host), while still classifying providers using the hostname only; tests were updated/added to cover these scenarios.

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

Note

Fix source control auth to support self-hosted GitLab and multi-account GitHub

  • Switches GitHub auth detection from regex parsing to JSON-based parsing via gh auth status --json hosts, preferring active authenticated accounts and gracefully handling mixed account states.
  • Adds refineUnknownGitLabRemote which probes glab auth status to upgrade an 'unknown' remote context to a concrete self-hosted GitLab provider, including remotes on non-standard ports.
  • Introduces refineUnknownRemoteProvider in SourceControlProviderDiscovery.ts as a general mechanism for CLI-based refinement of unknown remotes, called during provider detection in SourceControlProviderRegistry.ts.
  • Fixes port handling in parseRemoteHost so that HTTPS/HTTP remote URLs preserve the port in baseUrl, while classification uses only the hostname.
  • Behavioral Change: gh auth status is now invoked with --json hosts instead of plain auth status, which requires gh CLI v2.40+.

Macroscope summarized a066090.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 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: 568209a8-ffd0-4b2a-b53f-1000bb78986b

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels May 3, 2026
Comment thread apps/server/src/sourceControl/GitLabSourceControlProvider.ts Outdated
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented May 3, 2026

Approvability

Verdict: Needs human review

Introduces new capabilities for multi-account GitHub authentication and self-hosted GitLab detection, including a new refineUnknownRemote mechanism that can reclassify remote providers at runtime. These are feature additions with new code paths rather than simple fixes.

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

@GuilhermeVieiraDev GuilhermeVieiraDev force-pushed the fix/gitlab-self-hosted-detection branch from 64c268f to 0a0d025 Compare May 3, 2026 21:53
@GuilhermeVieiraDev GuilhermeVieiraDev force-pushed the fix/gitlab-self-hosted-detection branch from 0a0d025 to 1200763 Compare May 4, 2026 10:17
@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

@GuilhermeVieiraDev is attempting to deploy a commit to the Ping Labs Team on Vercel.

A member of the Team first needs to authorize it.

…d-detection

# Conflicts:
#	apps/server/src/sourceControl/GitLabSourceControlProvider.test.ts
#	apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts
@GuilhermeVieiraDev GuilhermeVieiraDev changed the title fix(source-control): detect authenticated self-hosted gitlab remotes fix(source-control): handle self-hosted GitLab and multi-account GitHub auth May 9, 2026
Comment thread apps/server/src/sourceControl/GitHubSourceControlProvider.ts Outdated
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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 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 f5d8806. Configure here.

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

Labels

size:L 100-499 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