fix: detect SSH remotes with non-git user prefixes (e.g. gitlab@) (#3649)

This commit is contained in:
JackatDJL authored and GitHub committed 2026-08-15 12:26:45 +00:00
1 parent dc0ff8f13e
commit 7ce4194707
6 files changed
+72 -16

No files matched your search

+39
View File
@@ -3,6 +3,7 @@ import { describe, expect, it } from "vite-plus/test";
import {
detectSourceControlProviderFromRemoteUrl,
getChangeRequestTerminologyForKind,
isSshRemoteUrl,
resolveChangeRequestPresentation,
} from "./sourceControl.ts";
@@ -120,4 +121,42 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
)?.kind,
).toBe("unknown");
});
it("detects SSH remotes with non-git SSH users (e.g. gitlab@, deploy@)", () => {
expect(
detectSourceControlProviderFromRemoteUrl("[email protected]:group/project.git")?.kind,
).toBe("gitlab");
expect(
detectSourceControlProviderFromRemoteUrl("[email protected]:group/project.git")
?.baseUrl,
).toBe("https://gitlab.example.com");
expect(detectSourceControlProviderFromRemoteUrl("[email protected]:owner/repo.git")?.kind).toBe(
"github",
);
expect(
detectSourceControlProviderFromRemoteUrl("[email protected]:workspace/repo.git")?.kind,
).toBe("bitbucket");
});
});
describe("isSshRemoteUrl", () => {
it("recognises SCP-like SSH URLs with any SSH user prefix", () => {
expect(isSshRemoteUrl("[email protected]:owner/repo.git")).toBe(true);
expect(isSshRemoteUrl("[email protected]:group/project.git")).toBe(true);
expect(isSshRemoteUrl("[email protected]:workspace/repo.git")).toBe(true);
});
it("recognises ssh:// URLs with any case", () => {
expect(isSshRemoteUrl("ssh://[email protected]/group/project.git")).toBe(true);
expect(isSshRemoteUrl("ssh://[email protected]:22/group/project.git")).toBe(true);
expect(isSshRemoteUrl("SSH://[email protected]/group/project.git")).toBe(true);
expect(isSshRemoteUrl("SsH://[email protected]/group/project.git")).toBe(true);
});
it("returns false for HTTPS, local paths, and SCP-like paths without a colon", () => {
expect(isSshRemoteUrl("https://gitlab.example.com/group/project.git")).toBe(false);
expect(isSshRemoteUrl("/home/user/repos/project")).toBe(false);
expect(isSshRemoteUrl("")).toBe(false);
expect(isSshRemoteUrl("[email protected]/project/repo")).toBe(false);
});
});