The best way to control Claude Code, Codex and more from any computer or phone
fix(server): self-hosted GitLab projects resolve bare pull request numbers (#15395)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Antony committed
Oct 19, 2026 at 22:26 UTC
221831ff8ff419ed6618b25abbf7adeb2ab4987e
4 files changed
+134
-5
packages/shared/src/git.test.ts
+8
@@ -54,6 +54,14 @@ describe("normalizeGitRemoteUrl", () => {
54
expect(normalizeGitRemoteUrl("deploy@bitbucket.org:workspace/repo.git")).toBe(
55
"bitbucket.org/workspace/repo",
56
);
57
+ expect(normalizeGitRemoteUrl("code.example.test:team/repo.git")).toBe(
58
+ "code.example.test/team/repo",
59
+ );
60
+ expect(normalizeGitRemoteUrl("git@code.example.test:/team/repo.git")).toBe(
61
+ "code.example.test/team/repo",
62
+ );
63
+ expect(normalizeGitRemoteUrl("C:/repos/project")).toBe("c:/repos/project");
64
+ expect(normalizeGitRemoteUrl("git@x:team/project.git")).toBe("x/team/project");
65
});
66
67
it("gives an Azure DevOps repository the same key over SSH as over HTTPS", () => {
packages/shared/src/git.ts
+4
-3
@@ -163,9 +163,10 @@ export function normalizeGitRemoteUrl(value: string): string {
163
}
164
}
165
166
- const scpStyleHostAndPath = /^[a-zA-Z0-9._-]+@([^:/\s]+):([^/\s]+(?:\/[^/\s]+)+)$/i.exec(
167
- normalized,
168
- );
166
+ // A userless one-letter prefix is a Windows drive, not an SCP host.
167
+ const scpStyleHostAndPath = /^[a-z]:/i.test(normalized)
168
+ ? null
169
+ : /^(?:[a-zA-Z0-9._-]+@)?([^@:/\\\s]+):\/?([^/\s]+(?:\/[^/\s]+)+)$/i.exec(normalized);
170
const scpHost = scpStyleHostAndPath?.[1];
171
const scpPath = scpStyleHostAndPath?.[2];
172
if (scpHost && scpPath) {
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts
+80
@@ -1,4 +1,11 @@
1
import { SourceControlProviderKind } from "@t3tools/contracts";
2
+import { changeRequestUrlFor } from "@t3tools/shared/changeRequestUrl";
3
+import {
4
+ detectSourceControlProviderFromGitRemoteUrl,
5
+ normalizeGitRemoteUrl,
6
+} from "@t3tools/shared/git";
7
+import { refineUnknownRemoteProvider } from "@t3tools/source-control-core/server/discovery";
8
+import { processOutput } from "@t3tools/source-control-testing/TestSourceControlHost";
9
import { assert, it } from "@effect/vitest";
10
import * as Effect from "effect/Effect";
11
import * as Layer from "effect/Layer";
@@ -241,6 +248,79 @@ it("tells a host glab has no login for apart from output that cannot say", () =>
248
assert.strictEqual(refine("git.example.test\n x API call failed: 503"), undefined);
249
});
250
251
+it.effect.each([
252
+ [
253
+ "https://code.example.test:8443@Code.Example.Test:8443/Team/Repo.git",
254
+ true,
255
+ "gitlab",
256
+ "Code.Example.Test:8443",
257
+ ],
258
+ ["git@code.example.test:team/repo.git", true, "gitlab"],
259
+ ["code.example.test:team/repo.git", true, "gitlab"],
260
+ ["git@code.example.test:/team/repo.git", true, "gitlab"],
261
+ ["https://code.example.test/team/repo.git", false, "unknown"],
262
+ ["https://github.com/team/repo.git", true, "github"],
263
+] as const)(
264
+ "resolves MR numbers for %s with authenticated=%s as %s",
265
+ ([remoteUrl, authenticated, expectedProvider, expectedAuthHost = "code.example.test"]) =>
266
+ Effect.gen(function* () {
267
+ const provider = yield* makeProvider({});
268
+ const identity = {
269
+ canonicalKey: normalizeGitRemoteUrl(remoteUrl),
270
+ locator: { source: "git-remote" as const, remoteName: "upstream", remoteUrl },
271
+ rootPath: "/repo",
272
+ provider: detectSourceControlProviderFromGitRemoteUrl(remoteUrl)?.kind ?? "unknown",
273
+ };
274
+ let authCalls = 0;
275
+ const refined = yield* (
276
+ provider.refineRepositoryIdentity?.({
277
+ identity,
278
+ resolveContext: (input) =>
279
+ refineUnknownRemoteProvider({
280
+ ...input,
281
+ specs: [GitLabSourceControlProvider.discovery],
282
+ process: {
283
+ run: ({ command, args, cwd }) => {
284
+ authCalls++;
285
+ assert.deepStrictEqual(
286
+ { command, args, cwd },
287
+ {
288
+ command: "glab",
289
+ args: ["auth", "status", "--hostname", expectedAuthHost],
290
+ cwd: "/repo",
291
+ },
292
+ );
293
+ return Effect.succeed(
294
+ processOutput(
295
+ authenticated
296
+ ? `${expectedAuthHost}\n ✓ Logged in to ${expectedAuthHost} as gitlab-user\n`
297
+ : "x code.example.test has not been authenticated with glab.",
298
+ { exitCode: ChildProcessSpawner.ExitCode(authenticated ? 0 : 1) },
299
+ ),
300
+ );
301
+ },
302
+ },
303
+ }).pipe(
304
+ Effect.map(({ provider }) =>
305
+ provider ? { ...input.context, provider } : input.context,
306
+ ),
307
+ ),
308
+ }) ?? Effect.succeed(identity)
309
+ );
310
+ const [host, ...repository] = refined.canonicalKey.split("/");
311
+ assert.strictEqual(
312
+ changeRequestUrlFor(refined.provider, host!, repository.join("/"), 42),
313
+ expectedProvider === "gitlab"
314
+ ? "https://code.example.test/team/repo/-/merge_requests/42"
315
+ : expectedProvider === "github"
316
+ ? "https://github.com/team/repo/pull/42"
317
+ : null,
318
+ );
319
+ assert.deepStrictEqual(refined, { ...identity, provider: expectedProvider });
320
+ if (expectedProvider === "github") assert.strictEqual(authCalls, 0);
321
+ }),
322
+);
323
+
324
it("parses authenticated GitLab auth status hosts with ports and single-label names", () => {
325
assert.deepStrictEqual(
326
parseGitLabAuthStatusHosts(`localhost:8080
packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts
+42
-2
@@ -3,6 +3,7 @@ import * as Schema from "effect/Schema";
3
import * as Effect from "effect/Effect";
4
import * as Option from "effect/Option";
5
import { SourceControlProviderError, type ChangeRequest } from "@t3tools/contracts";
6
+import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";
7
8
import * as GitLabCli from "./GitLabCli.ts";
9
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
@@ -101,6 +102,39 @@ function refineUnknownGitLabRemote(input: SourceControlUnknownRemoteRefinementIn
102
} as const;
103
}
104
105
+function unknownRemoteProvider(remoteUrl: string) {
106
+ // The shared detector does not recognize userless SCP remotes.
107
+ const scpHost = /^([^@:/\\\s]{2,}):\/?[^/\s]+(?:\/[^/\s]+)+$/u.exec(remoteUrl.trim())?.[1];
108
+ const provider = detectSourceControlProviderFromRemoteUrl(
109
+ scpHost ? `ssh://${scpHost}` : remoteUrl,
110
+ );
111
+ return provider?.kind === "unknown" ? provider : null;
112
+}
113
+
114
+// A glab login confirms a self-hosted GitLab whose hostname does not identify its provider.
115
+const refineRepositoryIdentity: NonNullable<
116
+ SourceControlProvider.SourceControlProvider["Service"]["refineRepositoryIdentity"]
117
+> = Effect.fn("GitLabSourceControlProvider.refineRepositoryIdentity")(function* ({
118
+ identity,
119
+ resolveContext,
120
+}) {
121
+ if (!identity.rootPath || (identity.provider !== undefined && identity.provider !== "unknown"))
122
+ return identity;
123
+ const provider = unknownRemoteProvider(identity.locator.remoteUrl);
124
+ if (!provider) return identity;
125
+ const context = yield* resolveContext({
126
+ cwd: identity.rootPath,
127
+ context: {
128
+ provider,
129
+ remoteName: identity.locator.remoteName,
130
+ remoteUrl: identity.locator.remoteUrl,
131
+ },
132
+ });
133
+ return context?.provider.kind === "gitlab"
134
+ ? { ...identity, provider: SourceControlProviderKind.make("gitlab") }
135
+ : identity;
136
+});
137
+
138
export const discovery = {
139
type: "cli",
140
kind: SourceControlProviderKind.make("gitlab"),
@@ -110,8 +144,13 @@ export const discovery = {
144
authArgs: ["auth", "status"],
145
// glab matches its configured hosts by exact name, so ask with the remote's own spelling.
146
remoteRefinementArgs: ({ provider, remoteUrl }) => {
113
- const at = remoteUrl.toLowerCase().indexOf(provider.name.toLowerCase());
114
- const host = at < 0 ? provider.name : remoteUrl.slice(at, at + provider.name.length);
147
+ const authority = /^[a-z][a-z0-9+.-]*:\/\/([^/]+)/iu.exec(remoteUrl.trim())?.[1];
148
+ const remoteHost = authority
149
+ ? authority.slice(authority.lastIndexOf("@") + 1)
150
+ : remoteUrl.trim().replace(/^[^@:/]+@/u, "");
151
+ const host = remoteHost.toLowerCase().startsWith(provider.name.toLowerCase())
152
+ ? remoteHost.slice(0, provider.name.length)
153
+ : provider.name;
154
return ["auth", "status", "--hostname", host];
155
},
156
parseAuth: parseGitLabAuth,
@@ -163,6 +202,7 @@ export const make = Effect.gen(function* () {
202
203
return SourceControlProvider.SourceControlProvider.of({
204
kind: SourceControlProviderKind.make("gitlab"),
205
+ refineRepositoryIdentity,
206
resolveLink: (input) => {
207
// Automatic enrichment must not send ambient CLI credentials to a host from message text.
208
if (input.url.host !== "gitlab.com") return undefined;