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
17 changes: 17 additions & 0 deletions packages/shared/src/sourceControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
});
});

it("does not reuse SSH ports for HTTPS provider URLs", () => {
expect(
detectSourceControlProviderFromRemoteUrl("ssh://git@gitlab.example.test:24/group/repo.git"),
).toEqual({
kind: "gitlab",
name: "GitLab Self-Hosted",
baseUrl: "https://gitlab.example.test",
});
expect(
detectSourceControlProviderFromRemoteUrl("ssh://git@code.example.test:24/team/project.git"),
).toEqual({
kind: "unknown",
name: "code.example.test",
baseUrl: "https://code.example.test",
});
});

it("matches self-hosted providers by complete DNS labels", () => {
expect(
detectSourceControlProviderFromRemoteUrl("https://github.example.com/owner/repo.git")?.kind,
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/sourceControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export function isSshRemoteUrl(remoteUrl: string): boolean {
return SCP_SSH_REMOTE_PATTERN.test(trimmed) || trimmed.toLowerCase().startsWith("ssh://");
}

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

try {
return new URL(trimmed).host.toLowerCase();
const url = new URL(trimmed);
return (url.protocol === "ssh:" ? url.hostname : url.host).toLowerCase();
} catch {
return null;
}
Expand Down
Loading