Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ describe("gitHubApiHostForRemote", () => {
);
assert.strictEqual(gitHubApiHostForRemote("git@gitlab.com:a/b.git"), null);
});

it("ignores a secondary remote whose host is not a valid URL host", () => {
for (const url of [
"git@nas.08:team/repo.git",
"git@08:team/repo.git",
"git@node.256:team/repo.git",
"git@[2001:db8::1]:team/repo.git",
]) {
const remotes = [
"origin\tgit@github.com:pingdotgg/t3code.git (fetch)",
`backup\t${url} (fetch)`,
].join("\n");
assert.deepStrictEqual(
resolveGitHubRepository({
remotes,
resolved: "",
hostHint: undefined,
defaultHost: "github.com",
}),
{ host: "github.com", locator: { host: "github.com", owner: "pingdotgg", name: "t3code" } },
url,
);
}
});
});

describe("github.com-<name> SSH aliases", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ function apiHostForSshAlias(host: string): string | null | undefined {
export function gitHubApiHostForRemote(remoteUrl: string): string | null {
const remote = parseGitRemoteHost(remoteUrl);
if (remote === null) return null;
const host = new URL(`https://${remote.host}`).host.toLowerCase();
const parsed = URL.parse(`https://${remote.host}`);
if (parsed === null) return null;
const host = parsed.host.toLowerCase();
if (isSshRemoteUrl(remoteUrl)) {
const aliased = apiHostForSshAlias(host);
if (aliased !== undefined) return aliased;
Expand Down
Loading