Skip to content

Commit 946203c

Browse files
JackatDJLjuliusmarminge
authored andcommitted
fix: align normalizeGitRemoteUrl SCP pattern with parseRemoteHost
normalizeGitRemoteUrl in packages/shared/src/git.ts still used the old git@ prefix and [:/] separator, inconsistent with the fixed parseRemoteHost which now requires : and accepts any SSH user prefix. - Require : as SCP separator (git@host:path, not git@host/path) - Generalize git@ to [a-zA-Z0-9._-]+@ for gitlab@, deploy@, etc. Addresses Cursor Bugbot review comment on PR #3649.
1 parent e68456b commit 946203c

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎apps/server/src/sourceControl/BitbucketApi.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
} from "@t3tools/contracts";
1515
import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
1616
import { sanitizeBranchFragment } from "@t3tools/shared/git";
17-
import { detectSourceControlProviderFromRemoteUrl, isSshRemoteUrl } from "@t3tools/shared/sourceControl";
17+
import {
18+
detectSourceControlProviderFromRemoteUrl,
19+
isSshRemoteUrl,
20+
} from "@t3tools/shared/sourceControl";
1821

1922
import {
2023
BitbucketPullRequestListSchema,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ describe("normalizeGitRemoteUrl", () => {
4040
"gitlab.company.com/team/project",
4141
);
4242
});
43+
44+
it("normalizes SCP-like remotes with non-git SSH users", () => {
45+
expect(normalizeGitRemoteUrl("[email protected]:group/project.git")).toBe(
46+
"gitlab.example.com/group/project",
47+
);
48+
expect(normalizeGitRemoteUrl("[email protected]:workspace/repo.git")).toBe(
49+
"bitbucket.org/workspace/repo",
50+
);
51+
});
4352
});
4453

4554
describe("parseGitHubRepositoryNameWithOwnerFromRemoteUrl", () => {

‎packages/shared/src/git.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ export function normalizeGitRemoteUrl(value: string): string {
133133
}
134134
}
135135

136-
const scpStyleHostAndPath = /^git@([^:/\s]+)[:/]([^/\s]+(?:\/[^/\s]+)+)$/i.exec(normalized);
136+
const scpStyleHostAndPath = /^[a-zA-Z0-9._-]+@([^:/\s]+):([^/\s]+(?:\/[^/\s]+)+)$/i.exec(
137+
normalized,
138+
);
137139
if (scpStyleHostAndPath?.[1] && scpStyleHostAndPath[2]) {
138140
return `${scpStyleHostAndPath[1]}/${scpStyleHostAndPath[2]}`;
139141
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,15 @@ describe("detectSourceControlProviderFromRemoteUrl", () => {
124124

125125
it("detects SSH remotes with non-git SSH users (e.g. gitlab@, deploy@)", () => {
126126
expect(
127-
detectSourceControlProviderFromRemoteUrl(
128-
"[email protected]:group/project.git",
129-
)?.kind,
127+
detectSourceControlProviderFromRemoteUrl("[email protected]:group/project.git")?.kind,
130128
).toBe("gitlab");
131129
expect(
132-
detectSourceControlProviderFromRemoteUrl(
133-
"[email protected]:group/project.git",
134-
)?.baseUrl,
130+
detectSourceControlProviderFromRemoteUrl("[email protected]:group/project.git")
131+
?.baseUrl,
135132
).toBe("https://gitlab.example.com");
136-
expect(
137-
detectSourceControlProviderFromRemoteUrl("deploy@github.com:owner/repo.git")?.kind,
138-
).toBe("github");
133+
expect(detectSourceControlProviderFromRemoteUrl("[email protected]:owner/repo.git")?.kind).toBe(
134+
"github",
135+
);
139136
expect(
140137
detectSourceControlProviderFromRemoteUrl("[email protected]:workspace/repo.git")?.kind,
141138
).toBe("bitbucket");

0 commit comments

Comments
 (0)