File size: 1,439 Bytes
3201ca6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import { describe, expect, it } from "vitest";
import { parseGitRemoteUrl } from "#/utils/parse-git-remote-url";
import { constructBranchUrl } from "#/utils/utils";
// Spans both modules on purpose: a remote is only useful once the parsed
// fields reach a link builder, and an Azure DevOps SSH remote used to parse
// into values `constructBranchUrl` could not build from.
function branchLinkFor(remoteUrl: string, branch: string): string {
const parsed = parseGitRemoteUrl(remoteUrl);
if (!parsed?.provider) return "";
return constructBranchUrl(
parsed.provider,
parsed.repository ?? "",
branch,
parsed.host,
);
}
describe("Azure DevOps remotes resolve a browsable branch link", () => {
const expected =
"https://dev.azure.com/myorg/myproject/_git/myrepo?version=GBmain";
it("builds a branch link from an HTTPS remote", () => {
expect(
branchLinkFor(
"https://dev.azure.com/myorg/myproject/_git/myrepo",
"main",
),
).toBe(expected);
});
it("builds the same branch link from the SSH remote", () => {
expect(
branchLinkFor("git@ssh.dev.azure.com:v3/myorg/myproject/myrepo", "main"),
).toBe(expected);
});
it("builds the same branch link from a legacy visualstudio.com SSH remote", () => {
expect(
branchLinkFor(
"git@vs-ssh.visualstudio.com:v3/myorg/myproject/myrepo",
"main",
),
).toBe(expected);
});
});
|