Skip to content

Commit 601a957

Browse files
fix(shared): preserve HTTPS ports in repository identities
1 parent b8c1ef6 commit 601a957

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

‎apps/server/src/git/GitManager.test.ts‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4504,17 +4504,6 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
45044504
ghRepo: null,
45054505
ghResolved: null,
45064506
},
4507-
// With a port on the remote's host the provider ignores gh-resolved and picks the remote.
4508-
{
4509-
remoteUrl: "https://github.example.com:8443/pingdotgg/codething-mvp.git",
4510-
ghRepo: null,
4511-
ghResolved: "acme/demo",
4512-
},
4513-
{
4514-
remoteUrl: "https://github.example.com:8443/pingdotgg/codething-mvp.git",
4515-
ghRepo: "base",
4516-
ghResolved: "acme/demo",
4517-
},
45184507
] as const)(
45194508
"reuses the open same-repository PR when the only remote is not named origin (remote $remoteUrl, GH_REPO $ghRepo, gh-resolved $ghResolved)",
45204509
({ remoteUrl, ghRepo, ghResolved }) =>
@@ -4684,12 +4673,17 @@ it.layer(layerGitManagerTest)("GitManager", (it) => {
46844673
ghResolved: null,
46854674
head: "dev",
46864675
},
4687-
// The provider ignores gh-resolved only when the remote's host carries a port.
46884676
{
46894677
remoteUrl: "https://github.example.com:8443/contributor/demo.git",
46904678
ghRepo: null,
46914679
ghResolved: "acme/demo",
4692-
head: "dev",
4680+
head: "contributor:dev",
4681+
},
4682+
{
4683+
remoteUrl: "https://github.example.com:8443/contributor/demo.git",
4684+
ghRepo: "base",
4685+
ghResolved: "acme/demo",
4686+
head: "contributor:dev",
46934687
},
46944688
{
46954689
remoteUrl: "https://github.example.com/contributor/demo.git",

‎apps/server/src/project/RepositoryIdentityResolver.test.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,21 +414,30 @@ it.layer(NodeServices.layer)("RepositoryIdentityResolverLive", (it) => {
414414
"remote",
415415
"add",
416416
"origin",
417-
"git@github.example.com:julius/t3code-fork.git",
417+
"https://github.example.com:8443/julius/t3code-fork.git",
418418
]);
419419
yield* git(cwd, ["config", "remote.origin.gh-resolved", "T3Tools/t3code"]);
420420

421421
const resolver = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
422422
const identity = yield* resolver.resolve(cwd);
423423

424-
expect(identity?.canonicalKey).toBe("github.example.com/t3tools/t3code");
424+
expect(identity?.canonicalKey).toBe("github.example.com:8443/t3tools/t3code");
425425
expect(identity?.displayName).toBe("T3Tools/t3code");
426426
expect(identity?.owner).toBe("T3Tools");
427427
expect(identity?.name).toBe("t3code");
428428
expect(identity?.origin).toEqual({
429-
canonicalKey: "github.example.com/julius/t3code-fork",
429+
canonicalKey: "github.example.com:8443/julius/t3code-fork",
430430
displayName: "julius/t3code-fork",
431431
});
432+
const remotes = yield* git(cwd, ["remote", "-v"]);
433+
expect(
434+
resolveGitHubRepository({
435+
remotes: remotes.stdout,
436+
resolved: "remote.origin.gh-resolved T3Tools/t3code",
437+
hostHint: undefined,
438+
defaultHost: "github.com",
439+
}).locator,
440+
).toEqual({ host: "github.example.com:8443", owner: "t3tools", name: "t3code" });
432441
}).pipe(Effect.provide(RepositoryIdentityResolver.layer)),
433442
);
434443

‎packages/shared/src/git.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ describe("normalizeGitRemoteUrl", () => {
3838
);
3939
});
4040

41-
it("drops explicit ports from URL-shaped remotes", () => {
41+
it("preserves nondefault HTTPS ports in repository identities", () => {
4242
expect(normalizeGitRemoteUrl("https://gitlab.company.com:8443/team/project.git")).toBe(
43-
"gitlab.company.com/team/project",
43+
"gitlab.company.com:8443/team/project",
4444
);
45+
});
46+
47+
it("does not use SSH ports in repository identities", () => {
4548
expect(normalizeGitRemoteUrl("ssh://[email protected]:2222/team/project.git")).toBe(
4649
"gitlab.company.com/team/project",
4750
);

‎packages/shared/src/git.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ export function normalizeGitRemoteUrl(value: string): string {
151151
if (/^(?:ssh|https?|git):\/\//i.test(normalized)) {
152152
try {
153153
const url = new URL(normalized);
154+
const host = url.protocol === "http:" || url.protocol === "https:" ? url.host : url.hostname;
154155
const repositorySegments = url.pathname.split("/").filter((segment) => segment.length > 0);
155-
if (url.hostname && repositorySegments.length > 1) {
156+
if (host && repositorySegments.length > 1) {
156157
return (
157-
azureDevOpsRepositoryKey(url.hostname, repositorySegments) ??
158-
`${url.hostname}/${repositorySegments.join("/")}`
158+
azureDevOpsRepositoryKey(host, repositorySegments) ??
159+
`${host}/${repositorySegments.join("/")}`
159160
);
160161
}
161162
} catch {

0 commit comments

Comments
 (0)