This commit is contained in:
Asish Kumar 2026-07-14 19:17:07 -07:00 committed by GitHub
commit b8ed8aa134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 2 deletions

View File

@ -124,8 +124,18 @@ function windowToDate(window: string): Date {
export function normalizeRemoteUrl(url: string): string {
let normalized = url.trim();
// SSH → HTTPS: git@github.com:user/repo → https://github.com/user/repo
const sshMatch = normalized.match(/^(?:ssh:\/\/)?git@([^:]+):(.+)$/);
// SSH URL → HTTPS: ssh://git@github.com/user/repo → https://github.com/user/repo
try {
const parsed = new URL(normalized);
if (parsed.protocol === "ssh:" && parsed.username === "git" && parsed.pathname.length > 1) {
normalized = `https://${parsed.host}${parsed.pathname}`;
}
} catch {
// Not a URL-style remote; try scp-style below.
}
// SCP-style SSH → HTTPS: git@github.com:user/repo → https://github.com/user/repo
const sshMatch = normalized.match(/^git@([^:]+):(.+)$/);
if (sshMatch) {
normalized = `https://${sshMatch[1]}/${sshMatch[2]}`;
}

View File

@ -30,6 +30,12 @@ describe("gstack-global-discover", () => {
);
});
test("converts URL-style SSH to HTTPS", () => {
expect(normalizeRemoteUrl("ssh://git@github.com/user/repo.git")).toBe(
"https://github.com/user/repo"
);
});
test("converts SSH without .git to HTTPS", () => {
expect(normalizeRemoteUrl("git@github.com:user/repo")).toBe(
"https://github.com/user/repo"
@ -44,9 +50,11 @@ describe("gstack-global-discover", () => {
test("SSH and HTTPS for same repo normalize to same URL", () => {
const ssh = normalizeRemoteUrl("git@github.com:garrytan/gstack.git");
const sshUrl = normalizeRemoteUrl("ssh://git@github.com/garrytan/gstack.git");
const https = normalizeRemoteUrl("https://github.com/garrytan/gstack.git");
const httpsNoDotGit = normalizeRemoteUrl("https://github.com/garrytan/gstack");
expect(ssh).toBe(https);
expect(sshUrl).toBe(https);
expect(https).toBe(httpsNoDotGit);
});
@ -61,6 +69,12 @@ describe("gstack-global-discover", () => {
"https://gitlab.com/org/project"
);
});
test("handles GitLab URL-style SSH URLs", () => {
expect(normalizeRemoteUrl("ssh://git@gitlab.com/org/project.git")).toBe(
"https://gitlab.com/org/project"
);
});
});
describe("CLI", () => {