fix: detect SSH remotes with non-git user prefixes (e.g. gitlab@)#3649
fix: detect SSH remotes with non-git user prefixes (e.g. gitlab@)#3649JackatDJL wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes source control provider detection and SSH-vs-HTTPS clone URL preference for SCP-like SSH remotes that use non-git usernames (e.g. gitlab@host:group/project.git), which is common on enterprise/self-hosted GitLab and other deployments.
Changes:
- Generalized SCP-like SSH remote parsing in
parseRemoteHostto support any SSH user prefix (not justgit@). - Added a shared
isSshRemoteUrlhelper and reused it for SSH remote preference checks in server code. - Added test coverage for provider detection with non-
gitSSH usernames and forisSshRemoteUrl.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/shared/src/sourceControl.ts | Generalizes SCP-like SSH parsing and adds isSshRemoteUrl helper used by server code. |
| packages/shared/src/sourceControl.test.ts | Adds tests for provider detection with gitlab@/deploy@ and for SSH URL detection. |
| apps/server/src/sourceControl/BitbucketApi.ts | Uses shared SSH detection for clone URL selection; broadens SCP-like remote parsing for Bitbucket slug extraction. |
| apps/server/src/git/GitManager.ts | Uses shared SSH detection for clone URL selection logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ApprovabilityVerdict: Approved Bug fix that expands SSH remote URL detection to handle non-standard SSH user prefixes (gitlab@, deploy@) in addition to git@. Changes are limited to regex pattern updates with comprehensive test coverage, posing minimal runtime risk. You can customize Macroscope's approvability policy. Learn more. |
08aceb1 to
e32032c
Compare
Dismissing prior approval to re-evaluate e32032c
parseRemoteHost only handled the git@ prefix when parsing SCP-like SSH
remote URLs. Enterprise GitLab instances commonly use gitlab@ as the SSH
user, causing host detection to fail and the provider to stay unknown.
Replace startsWith("git@") with a regex matching any SCP-like SSH syntax
(user@host:path). Extract a shared isSshRemoteUrl helper and use it in
GitManager and BitbucketApi to fix the same pattern there.
Closes pingdotgg#3648
e32032c to
536dc17
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 536dc17. Configure here.
normalizeGitRemoteUrl in packages/shared/src/git.ts still used the old git@ prefix and [:/] separator, inconsistent with the fixed parseRemoteHost which now requires : and accepts any SSH user prefix. - Require : as SCP separator (git@host:path, not git@host/path) - Generalize git@ to [a-zA-Z0-9._-]+@ for gitlab@, deploy@, etc. Addresses Cursor Bugbot review comment on PR pingdotgg#3649.

What changed
parseRemoteHostonly handled thegit@prefix when parsing SCP-like SSH remote URLs. Enterprise GitLab instances commonly usegitlab@as the SSH user (GitLab's default), so remotes likegitlab@gitlab.example.com:group/project.gitwere not parsed —parseRemoteHostreturnednull, the provider stayedunknown, and every PR/MR operation failed with:Replaced the
startsWith("git@")check with a regex (/^[a-zA-Z0-9._-]+@([^:/]+)[:/]/) that matches any SCP-like SSH syntax, coveringgit@,gitlab@,deploy@, and any other SSH user prefix.Extracted a shared
isSshRemoteUrlhelper inpackages/shared/src/sourceControl.tsand used it to fix the samestartsWith("git@")pattern in:apps/server/src/git/GitManager.ts—shouldPreferSshRemote(clone URL selection)apps/server/src/sourceControl/BitbucketApi.ts—parseBitbucketRemoteUrlandshouldPreferSshRemoteWhy
SCP-like SSH syntax (
user@host:path) is standard git remote format. The SSH user is not alwaysgit— GitLab usesgitlab@, Bitbucket Server usesgit@or custom users, and enterprise deployments may use any username. Hardcodinggit@breaks provider detection for all of these.Tests
Added test cases for:
detectSourceControlProviderFromRemoteUrlwithgitlab@anddeploy@SSH usersisSshRemoteUrlfor SCP-like,ssh://, HTTPS, and local pathsExisting tests and typecheck pass (verified with
tsgoper-package;vptest runner has a native binding issue on this platform).Closes #3648
Note
Medium Risk
Touches shared remote parsing used for provider detection, clone URL choice, and Bitbucket slug extraction; wrong regex behavior could misclassify remotes, though scope is narrow and well covered by new tests.
Overview
Fixes provider detection and clone URL selection for SCP-style SSH remotes whose SSH user is not
git(e.g. GitLab’sgitlab@), which previously left the provider as unknown and broke PR/MR flows.Adds shared
isSshRemoteUrland aSCP_SSH_REMOTE_PATTERNinsourceControl.ts, updatesparseRemoteHostto extract the host from anyuser@host:pathform, and wiresGitManager/BitbucketApiSSH preference and Bitbucket URL parsing through that helper instead ofstartsWith("git@").normalizeGitRemoteUrlingit.tsuses the same broader SCP regex so non-gitusers normalize consistently.Tests cover
gitlab@/deploy@detection,isSshRemoteUrledge cases, and SCP normalization. SCP-like strings without a colon are no longer treated as SSH and may not yield a host from SCP parsing.Reviewed by Cursor Bugbot for commit 8242b99. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix SSH remote detection to support non-
gitusername prefixes (e.g.gitlab@,deploy@)isSshRemoteUrlandSCP_SSH_REMOTE_PATTERNin sourceControl.ts to detect SCP-like SSH remotes with any valid username, not justgit@.normalizeGitRemoteUrlin git.ts andparseRemoteHostin sourceControl.ts to use the generalized pattern for host/path extraction.git@/ssh://string checks inGitManager.shouldPreferSshRemoteandBitbucketApiwith calls to the sharedisSshRemoteUrlhelper.BitbucketApi.parseBitbucketRemoteUrlto correctly parse SCP-like remotes that use non-gitSSH users (e.g.deploy@bitbucket.org:workspace/repo.git).Macroscope summarized 8242b99.