Skip to content

Commit 8330e21

Browse files
fix(github): limit repository host normalization to SSH aliases
1 parent c26cc1c commit 8330e21

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎packages/source-control-github/src/server/gitHubRepositoryResolution.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ describe("selectGitHubBaseRepository", () => {
8888
}
8989
});
9090

91+
it("preserves selection behavior for real hosts with explicit ports", () => {
92+
const input = {
93+
remotes: remotes(["origin", "https://github.example.com:8443/me/web.git"]),
94+
resolved: "remote.origin.gh-resolved acme/other",
95+
};
96+
assert.strictEqual(
97+
selectGitHubBaseRepository({ ...input, host: "github.example.com:8443" }),
98+
null,
99+
);
100+
assert.deepStrictEqual(
101+
resolveGitHubRepository({ ...input, hostHint: undefined, defaultHost: "github.com" }),
102+
{
103+
host: "github.example.com:8443",
104+
locator: { host: "github.example.com:8443", owner: "me", name: "web" },
105+
},
106+
);
107+
});
108+
91109
it("leaves gh to choose when it might weigh the remotes differently", () => {
92110
for (const input of [
93111
{ remotes: "" },

‎packages/source-control-github/src/server/gitHubRepositoryResolution.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export function selectGitHubBaseRepository(input: {
3838
const repositories = new Map<string, { readonly owner: string; readonly name: string }>();
3939
for (const remote of parseFetchRemotes(input.remotes)) {
4040
const [normalizedHost, owner, name, ...rest] = normalizeGitRemoteUrl(remote.url).split("/");
41-
const remoteHost = gitHubApiHostForRemote(remote.url) ?? normalizedHost;
41+
const remoteHost =
42+
normalizedHost && isSshRemoteUrl(remote.url)
43+
? (apiHostForSshAlias(normalizedHost) ?? normalizedHost)
44+
: normalizedHost;
4245
if (remoteHost !== host || !owner || !name || rest.length > 0) return null;
4346
repositories.set(remote.name, { owner, name });
4447
}

0 commit comments

Comments
 (0)