Skip to content

Commit 29a3266

Browse files
authored
fix(git): exclude SSH ports from provider URLs (pingdotgg#12537)
1 parent dd8332d commit 29a3266

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
110110
});
111111
});
112112

113+
it("does not reuse SSH ports for HTTPS provider URLs", () => {
114+
expect(
115+
detectSourceControlProviderFromRemoteUrl("ssh://[email protected]:24/group/repo.git"),
116+
).toEqual({
117+
kind: "gitlab",
118+
name: "GitLab Self-Hosted",
119+
baseUrl: "https://gitlab.example.test",
120+
});
121+
expect(
122+
detectSourceControlProviderFromRemoteUrl("ssh://[email protected]:24/team/project.git"),
123+
).toEqual({
124+
kind: "unknown",
125+
name: "code.example.test",
126+
baseUrl: "https://code.example.test",
127+
});
128+
});
129+
113130
it("matches self-hosted providers by complete DNS labels", () => {
114131
expect(
115132
detectSourceControlProviderFromRemoteUrl("https://github.example.com/owner/repo.git")?.kind,

‎packages/shared/src/sourceControl.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export function isSshRemoteUrl(remoteUrl: string): boolean {
146146
return SCP_SSH_REMOTE_PATTERN.test(trimmed) || trimmed.toLowerCase().startsWith("ssh://");
147147
}
148148

149+
/**
150+
* Extracts the normalized host used for provider detection. SCP-style and SSH remotes return the
151+
* hostname only, while other URL schemes retain explicit ports for non-default web endpoints.
152+
*/
149153
function parseRemoteHost(remoteUrl: string): string | null {
150154
const trimmed = remoteUrl.trim();
151155
if (trimmed.length === 0) {
@@ -158,7 +162,8 @@ function parseRemoteHost(remoteUrl: string): string | null {
158162
}
159163

160164
try {
161-
return new URL(trimmed).host.toLowerCase();
165+
const url = new URL(trimmed);
166+
return (url.protocol === "ssh:" ? url.hostname : url.host).toLowerCase();
162167
} catch {
163168
return null;
164169
}

0 commit comments

Comments
 (0)