fix(vcs): open Bitbucket SSH clones on bitbucket.org (#3379)

For a Bitbucket Cloud repository cloned over SSH (git@ssh.bitbucket.org:team/repo.git), Open In used ssh.bitbucket.org as the web host and GitLab routes. remoteWebUrl now maps the services' SSH front hosts (ssh.bitbucket.org, ssh.github.com, altssh.gitlab.com) to their web hosts before building the URL.

Co-authored-by: akshathayadav378-boop <287247196+akshathayadav378-boop@users.noreply.github.com>
This commit is contained in:
akshathayadav378-boop
2026-11-14 22:54:44 +08:00
committed by GitHub
co-authored by akshathayadav378-boop
parent 488e819b46
commit 13e18af777
2 changed files with 16 additions and 0 deletions
@@ -7,6 +7,8 @@ describe("remoteHosting", () => {
["https://github.example.com/o/r", "GitHub", "github"],
["https://gitee.com/o/r.git", "Gitee", "github"],
["git@bitbucket.org:o/r.git", "Bitbucket", "bitbucket"],
["git@ssh.bitbucket.org:team/repo.git", "Bitbucket", "bitbucket"],
["git@ssh.github.com:o/r.git", "GitHub", "github"],
["ssh://git@gitlab.example.com:2222/group/sub/r.git", "GitLab", "gitlab"],
["git@git.example.com:group/r.git", "git.example.com", "gitlab"],
])("%s → %s", (url, name, kind) => {
@@ -43,4 +45,10 @@ describe("fileWebUrl", () => {
"https://bitbucket.org/o/r/src/main/a.py#lines-5",
);
});
it("opens a Bitbucket Cloud SSH clone on bitbucket.org, not the SSH front host (#3372)", () => {
expect(fileWebUrl("git@ssh.bitbucket.org:team/repo.git", "main", "a.py", { line: 4 })).toBe(
"https://bitbucket.org/team/repo/src/main/a.py#lines-5",
);
});
});
+8
View File
@@ -139,6 +139,13 @@ export function stashLabel(message: string): { branch: string | null; text: stri
return { branch: m[1]!, text: m[2]!.trim() || message };
}
/** SSH front hosts that serve the same service as the web host in the value. */
const WEB_HOST_ALIASES: Record<string, string> = {
"ssh.bitbucket.org": "bitbucket.org",
"ssh.github.com": "github.com",
"altssh.gitlab.com": "gitlab.com",
};
/**
* Web page of a git remote URL (`git@github.com:o/r.git`, `ssh://git@host:22/o/r`,
* `https://user@host/o/r.git`), or null for local paths.
@@ -155,6 +162,7 @@ export function remoteWebUrl(url: string): string | null {
if (full) [, host, path] = full as unknown as [string, string, string];
else if (scp) [, host, path] = scp as unknown as [string, string, string];
else return null;
host = WEB_HOST_ALIASES[host.toLowerCase()] ?? host;
return `https://${host}/${path.replace(/^\/+/, "")}`;
}