@devries-cameron20 / t3code-1 / commits / 9ea95c1c4d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(gitlab): keep pull request actions on the selected host (#23695)

Co-authored-by: Tejas Parmar <parmartejas@vanojay.in> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

parmartejas committed Oct 31, 2026 at 03:14 UTC 9ea95c1c4d68eef5e2815264d31a392b62736132
4 files changed +260 -30
packages/source-control-gitlab/src/server/GitLabCli.ts
+3
@@ -267,6 +267,7 @@ export class GitLabCli extends Context.Service<
267 {
268 readonly execute: (input: {
269 readonly cwd: string;
270 + readonly host?: string | undefined;
271 readonly args: ReadonlyArray<string>;
272 readonly timeoutMs?: number;
273 /** Keeps sensitive payloads out of argv. */
@@ -432,6 +433,8 @@ export const make = Effect.gen(function* () {
433 command: "glab",
434 args: input.args,
435 cwd: input.cwd,
436 + // glab may otherwise prefer a different checkout remote.
437 + ...(input.host === undefined ? {} : { env: { GITLAB_HOST: input.host } }),
438 classifyFailure: classifyGlabFailure,
439 notFoundDetail: "Merge request not found.",
440 timeoutMs: input.timeoutMs ?? DEFAULT_TIMEOUT_MS,
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+83 -6
@@ -224,10 +224,12 @@ export class GitLabPullRequestCli extends Context.Service<
224 {
225 readonly getViewerUsername: (input: {
226 readonly cwd: string;
227 + readonly host?: string | undefined;
228 }) => Effect.Effect<string, GitLabPullRequestCliError>;
229
230 readonly listMergeRequests: (input: {
231 readonly cwd: string;
232 + readonly host?: string | undefined;
233 readonly repository: string;
234 readonly state: PullRequestListState;
235 readonly involvement: PullRequestInvolvement;
@@ -240,6 +242,7 @@ export class GitLabPullRequestCli extends Context.Service<
242
243 readonly getMergeRequestDetail: (input: {
244 readonly cwd: string;
245 + readonly host?: string | undefined;
246 readonly repository: string;
247 readonly number: number;
248 }) => Effect.Effect<GitLabMergeRequestDetail, GitLabPullRequestCliError>;
@@ -247,6 +250,7 @@ export class GitLabPullRequestCli extends Context.Service<
250 /** Line counts for the given merge requests; one with no answer is left out. */
251 readonly listMergeRequestStats: (input: {
252 readonly cwd: string;
253 + readonly host?: string | undefined;
254 readonly changeRequests: ReadonlyArray<{
255 readonly repository: string;
256 readonly number: number;
@@ -263,12 +267,14 @@ export class GitLabPullRequestCli extends Context.Service<
267
268 readonly getMergeRequestFileStats: (input: {
269 readonly cwd: string;
270 + readonly host?: string | undefined;
271 readonly repository: string;
272 readonly number: number;
273 }) => Effect.Effect<ProviderFileStats, GitLabPullRequestCliError>;
274
275 readonly listNotes: (input: {
276 readonly cwd: string;
277 + readonly host?: string | undefined;
278 readonly repository: string;
279 readonly number: number;
280 }) => Effect.Effect<
@@ -278,12 +284,14 @@ export class GitLabPullRequestCli extends Context.Service<
284
285 readonly listCommits: (input: {
286 readonly cwd: string;
287 + readonly host?: string | undefined;
288 readonly repository: string;
289 readonly number: number;
290 }) => Effect.Effect<ReadonlyArray<PullRequestCommit>, GitLabPullRequestCliError>;
291
292 readonly getMergeRequestDiff: (input: {
293 readonly cwd: string;
294 + readonly host?: string | undefined;
295 readonly repository: string;
296 readonly number: number;
297 readonly cursor?: string | undefined;
@@ -292,6 +300,7 @@ export class GitLabPullRequestCli extends Context.Service<
300
301 readonly getMergeRequestDiffFileContents: (input: {
302 readonly cwd: string;
303 + readonly host?: string | undefined;
304 readonly repository: string;
305 readonly number: number;
306 readonly commit?: string | undefined;
@@ -305,11 +314,13 @@ export class GitLabPullRequestCli extends Context.Service<
314
315 readonly getProjectMergeCapabilities: (input: {
316 readonly cwd: string;
317 + readonly host?: string | undefined;
318 readonly repository: string;
319 }) => Effect.Effect<PullRequestMergeCapabilities, GitLabPullRequestCliError>;
320
321 readonly getFileRevisions: (input: {
322 readonly cwd: string;
323 + readonly host?: string | undefined;
324 readonly repository: string;
325 readonly number: number;
326 readonly paths: ReadonlyArray<string>;
@@ -317,12 +328,14 @@ export class GitLabPullRequestCli extends Context.Service<
328
329 readonly listReviewerCandidates: (input: {
330 readonly cwd: string;
331 + readonly host?: string | undefined;
332 readonly repository: string;
333 readonly number: number;
334 }) => Effect.Effect<PullRequestReviewerCandidateList, GitLabPullRequestCliError>;
335
336 readonly listProjectLabels: (input: {
337 readonly cwd: string;
338 + readonly host?: string | undefined;
339 readonly repository: string;
340 readonly search?: string | undefined;
341 }) => Effect.Effect<
@@ -332,6 +345,7 @@ export class GitLabPullRequestCli extends Context.Service<
345
346 readonly listProjectUsers: (input: {
347 readonly cwd: string;
348 + readonly host?: string | undefined;
349 readonly repository: string;
350 readonly search?: string | undefined;
351 }) => Effect.Effect<
@@ -341,6 +355,7 @@ export class GitLabPullRequestCli extends Context.Service<
355
356 readonly setReviewerRequest: (input: {
357 readonly cwd: string;
358 + readonly host?: string | undefined;
359 readonly repository: string;
360 readonly number: number;
361 readonly reviewers: ReadonlyArray<{ readonly id: string }>;
@@ -349,6 +364,7 @@ export class GitLabPullRequestCli extends Context.Service<
364
365 readonly runMergeRequestAction: (input: {
366 readonly cwd: string;
367 + readonly host?: string | undefined;
368 readonly repository: string;
369 readonly number: number;
370 readonly action: PullRequestAction;
@@ -357,6 +373,7 @@ export class GitLabPullRequestCli extends Context.Service<
373
374 readonly updateMergeRequest: (input: {
375 readonly cwd: string;
376 + readonly host?: string | undefined;
377 readonly repository: string;
378 readonly number: number;
379 readonly title?: string | undefined;
@@ -365,6 +382,7 @@ export class GitLabPullRequestCli extends Context.Service<
382
383 readonly commentOnMergeRequest: (input: {
384 readonly cwd: string;
385 + readonly host?: string | undefined;
386 readonly repository: string;
387 readonly number: number;
388 readonly body: string;
@@ -372,6 +390,7 @@ export class GitLabPullRequestCli extends Context.Service<
390
391 readonly updateNote: (input: {
392 readonly cwd: string;
393 + readonly host?: string | undefined;
394 readonly repository: string;
395 readonly number: number;
396 readonly noteId: string;
@@ -380,6 +399,7 @@ export class GitLabPullRequestCli extends Context.Service<
399
400 readonly listDiscussions: (input: {
401 readonly cwd: string;
402 + readonly host?: string | undefined;
403 readonly repository: string;
404 readonly number: number;
405 }) => Effect.Effect<
@@ -389,6 +409,7 @@ export class GitLabPullRequestCli extends Context.Service<
409
410 readonly submitReview: (input: {
411 readonly cwd: string;
412 + readonly host?: string | undefined;
413 readonly repository: string;
414 readonly number: number;
415 readonly verdict: PullRequestReviewVerdict;
@@ -398,6 +419,7 @@ export class GitLabPullRequestCli extends Context.Service<
419
420 readonly replyToDiscussion: (input: {
421 readonly cwd: string;
422 + readonly host?: string | undefined;
423 readonly repository: string;
424 readonly number: number;
425 readonly discussionId: string;
@@ -406,6 +428,7 @@ export class GitLabPullRequestCli extends Context.Service<
428
429 readonly setDiscussionResolution: (input: {
430 readonly cwd: string;
431 + readonly host?: string | undefined;
432 readonly repository: string;
433 readonly number: number;
434 readonly discussionId: string;
@@ -414,6 +437,7 @@ export class GitLabPullRequestCli extends Context.Service<
437
438 readonly listReactions: (input: {
439 readonly cwd: string;
440 + readonly host?: string | undefined;
441 readonly repository: string;
442 readonly number: number;
443 }) => Effect.Effect<
@@ -426,6 +450,7 @@ export class GitLabPullRequestCli extends Context.Service<
450
451 readonly setReaction: (input: {
452 readonly cwd: string;
453 + readonly host?: string | undefined;
454 readonly repository: string;
455 readonly number: number;
456 readonly noteId?: string | undefined;
@@ -566,6 +591,7 @@ export const make = Effect.gen(function* () {
591
592 const api = (input: {
593 readonly cwd: string;
594 + readonly host?: string | undefined;
595 readonly path: string;
596 readonly method?: string;
597 readonly stdin?: string;
@@ -574,6 +600,7 @@ export const make = Effect.gen(function* () {
600 }) =>
601 gitlab.execute({
602 cwd: input.cwd,
603 + host: input.host,
604 args: [
605 "api",
606 input.path,
@@ -590,6 +617,7 @@ export const make = Effect.gen(function* () {
617
618 const listPage = (input: {
619 readonly cwd: string;
620 + readonly host?: string | undefined;
621 readonly repository: string;
622 readonly state: PullRequestListState;
623 readonly involvement: PullRequestInvolvement;
@@ -611,6 +639,7 @@ export const make = Effect.gen(function* () {
639 const lastPage = Math.floor((delivered + input.limit) / perPage) + 1;
640 return api({
641 cwd: input.cwd,
642 + host: input.host,
643 path: `projects/${projectPath(input.repository)}/merge_requests?${query([
644 ["state", stateParam(input.state)],
645 ...involvementParams(input),
@@ -692,6 +721,7 @@ export const make = Effect.gen(function* () {
721
722 const diffPage = (input: {
723 readonly cwd: string;
724 + readonly host?: string | undefined;
725 readonly repository: string;
726 readonly number: number;
727 readonly page: number;
@@ -699,6 +729,7 @@ export const make = Effect.gen(function* () {
729 }): Effect.Effect<GitLabMergeRequestDiffSlice, GitLabPullRequestCliError> =>
730 api({
731 cwd: input.cwd,
732 + host: input.host,
733 path: `projects/${projectPath(input.repository)}/${
734 input.commit === undefined
735 ? `merge_requests/${input.number}/diffs`
@@ -724,6 +755,7 @@ export const make = Effect.gen(function* () {
755 // GitLab before 15.7 has no /diffs endpoint. /changes returns one complete slice.
756 return api({
757 cwd: input.cwd,
758 + host: input.host,
759 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/changes?access_raw_diffs=true`,
760 maxOutputBytes: DIFF_MAX_OUTPUT_BYTES,
761 timeoutMs: DIFF_TIMEOUT_MS,
@@ -772,6 +804,7 @@ export const make = Effect.gen(function* () {
804
805 const notesPage = (input: {
806 readonly cwd: string;
807 + readonly host?: string | undefined;
808 readonly repository: string;
809 readonly number: number;
810 readonly page: number;
@@ -782,6 +815,7 @@ export const make = Effect.gen(function* () {
815 > =>
816 api({
817 cwd: input.cwd,
818 + host: input.host,
819 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/notes?${query(
820 [
821 ["per_page", String(MAX_PAGE_SIZE)],
@@ -815,6 +849,7 @@ export const make = Effect.gen(function* () {
849
850 const discussionsPage = (input: {
851 readonly cwd: string;
852 + readonly host?: string | undefined;
853 readonly repository: string;
854 readonly number: number;
855 readonly page: number;
@@ -825,6 +860,7 @@ export const make = Effect.gen(function* () {
860 > =>
861 api({
862 cwd: input.cwd,
863 + host: input.host,
864 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/discussions?${query(
865 [
866 ["per_page", String(MAX_PAGE_SIZE)],
@@ -857,11 +893,13 @@ export const make = Effect.gen(function* () {
893
894 const getDiffRefs = (input: {
895 readonly cwd: string;
896 + readonly host?: string | undefined;
897 readonly repository: string;
898 readonly number: number;
899 }): Effect.Effect<GitLabDiffRefs, GitLabPullRequestCliError> =>
900 api({
901 cwd: input.cwd,
902 + host: input.host,
903 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}`,
904 }).pipe(
905 Effect.flatMap((result): Effect.Effect<GitLabDiffRefs, GitLabPullRequestCliError> => {
@@ -890,12 +928,14 @@ export const make = Effect.gen(function* () {
928
929 const getCommitDiffRefs = (input: {
930 readonly cwd: string;
931 + readonly host?: string | undefined;
932 readonly repository: string;
933 readonly commit: string;
934 readonly allowRoot: boolean;
935 }): Effect.Effect<GitLabDiffRefs, GitLabPullRequestCliError> =>
936 api({
937 cwd: input.cwd,
938 + host: input.host,
939 path: `projects/${projectPath(input.repository)}/repository/commits/${input.commit}`,
940 }).pipe(
941 Effect.flatMap((result): Effect.Effect<GitLabDiffRefs, GitLabPullRequestCliError> => {
@@ -930,11 +970,13 @@ export const make = Effect.gen(function* () {
970
971 const mergeRequestDetail = (input: {
972 readonly cwd: string;
973 + readonly host?: string | undefined;
974 readonly repository: string;
975 readonly number: number;
976 }): Effect.Effect<GitLabMergeRequestDetail, GitLabPullRequestCliError> =>
977 api({
978 cwd: input.cwd,
979 + host: input.host,
980 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}?${query([
981 ["include_diverged_commits_count", "true"],
982 ])}`,
@@ -956,11 +998,13 @@ export const make = Effect.gen(function* () {
998
999 const projectUsers = (input: {
1000 readonly cwd: string;
1001 + readonly host?: string | undefined;
1002 readonly repository: string;
1003 readonly search?: string | undefined;
1004 }): Effect.Effect<GitLabProjectUsers, GitLabPullRequestCliError> =>
1005 api({
1006 cwd: input.cwd,
1007 + host: input.host,
1008 path: `projects/${projectPath(input.repository)}/users?${query([
1009 ["per_page", String(MAX_PAGE_SIZE)],
1010 ...searchParams(input.search),
@@ -994,6 +1038,7 @@ export const make = Effect.gen(function* () {
1038
1039 const awardsPage = (input: {
1040 readonly cwd: string;
1041 + readonly host?: string | undefined;
1042 readonly repository: string;
1043 readonly number: number;
1044 readonly cursor: string | null;
@@ -1011,6 +1056,7 @@ export const make = Effect.gen(function* () {
1056 > =>
1057 api({
1058 cwd: input.cwd,
1059 + host: input.host,
1060 path: "graphql",
1061 method: "POST",
1062 stdin: JSON.stringify({
@@ -1056,6 +1102,7 @@ export const make = Effect.gen(function* () {
1102
1103 const graphqlRead = <A>(input: {
1104 readonly cwd: string;
1105 + readonly host?: string | undefined;
1106 readonly operation: string;
1107 readonly query: string;
1108 readonly variables: Record<string, unknown>;
@@ -1063,6 +1110,7 @@ export const make = Effect.gen(function* () {
1110 }) =>
1111 api({
1112 cwd: input.cwd,
1113 + host: input.host,
1114 path: "graphql",
1115 method: "POST",
1116 stdin: JSON.stringify({ query: input.query, variables: input.variables }),
@@ -1084,11 +1132,13 @@ export const make = Effect.gen(function* () {
1132
1133 const mergeRequestStats = (input: {
1134 readonly cwd: string;
1135 + readonly host?: string | undefined;
1136 readonly repository: string;
1137 readonly numbers: ReadonlyArray<number>;
1138 }) =>
1139 graphqlRead({
1140 cwd: input.cwd,
1141 + host: input.host,
1142 operation: "listMergeRequestStats",
1143 query: MERGE_REQUEST_STATS_GRAPHQL_QUERY,
1144 variables: { fullPath: input.repository, iids: input.numbers.map(String) },
@@ -1117,7 +1167,7 @@ export const make = Effect.gen(function* () {
1167 return Effect.forEach(
1168 reads,
1169 (read) =>
1120 - mergeRequestStats({ cwd: input.cwd, ...read }).pipe(
1170 + mergeRequestStats({ cwd: input.cwd, host: input.host, ...read }).pipe(
1171 Effect.map((stats) =>
1172 read.numbers.flatMap((number) => {
1173 const stat = stats.get(number);
@@ -1147,12 +1197,14 @@ export const make = Effect.gen(function* () {
1197
1198 const blobsAt = (input: {
1199 readonly cwd: string;
1200 + readonly host?: string | undefined;
1201 readonly repository: string;
1202 readonly ref: string;
1203 readonly paths: ReadonlyArray<string>;
1204 }): Effect.Effect<ReadonlyMap<string, string> | null, GitLabPullRequestCliError> =>
1205 api({
1206 cwd: input.cwd,
1207 + host: input.host,
1208 path: "graphql",
1209 method: "POST",
1210 stdin: JSON.stringify({
@@ -1179,6 +1231,7 @@ export const make = Effect.gen(function* () {
1231
1232 const fileRevisions = (input: {
1233 readonly cwd: string;
1234 + readonly host?: string | undefined;
1235 readonly repository: string;
1236 readonly number: number;
1237 readonly paths: ReadonlyArray<string>;
@@ -1215,8 +1268,8 @@ export const make = Effect.gen(function* () {
1268 }),
1269 );
1270
1218 - const viewerUsername = (input: { readonly cwd: string }) =>
1219 - api({ cwd: input.cwd, path: "user" }).pipe(
1271 + const viewerUsername = (input: { readonly cwd: string; readonly host?: string | undefined }) =>
1272 + api({ cwd: input.cwd, host: input.host, path: "user" }).pipe(
1273 Effect.flatMap((result): Effect.Effect<string, GitLabPullRequestCliError> => {
1274 const decoded = decodeViewerJson(result.stdout.trim());
1275 if (!Result.isSuccess(decoded)) {
@@ -1251,6 +1304,7 @@ export const make = Effect.gen(function* () {
1304 getMergeRequestFileStats: Effect.fn("GitLabPullRequestCli.getMergeRequestFileStats")((input) =>
1305 graphqlRead({
1306 cwd: input.cwd,
1307 + host: input.host,
1308 operation: "getMergeRequestFileStats",
1309 query: MERGE_REQUEST_FILE_STATS_GRAPHQL_QUERY,
1310 variables: { fullPath: input.repository, iid: String(input.number) },
@@ -1273,6 +1327,7 @@ export const make = Effect.gen(function* () {
1327 if (input.reacted) {
1328 yield* api({
1329 cwd: input.cwd,
1330 + host: input.host,
1331 path: `${subject}?${query([["name", gitLabAwardName(input.content)]])}`,
1332 method: "POST",
1333 });
@@ -1280,8 +1335,8 @@ export const make = Effect.gen(function* () {
1335 }
1336 // GitLab deletes an award by its id and takes no emoji name there, so the reader's own
1337 // award of that name is looked up first.
1283 - const viewer = yield* viewerUsername({ cwd: input.cwd });
1284 - const listed = yield* api({ cwd: input.cwd, path: subject });
1338 + const viewer = yield* viewerUsername(input);
1339 + const listed = yield* api({ cwd: input.cwd, host: input.host, path: subject });
1340 const own = decodeOwnAwardIdJson(listed.stdout.trim(), {
1341 content: input.content,
1342 viewer,
@@ -1297,6 +1352,7 @@ export const make = Effect.gen(function* () {
1352 if (own.success === null) return;
1353 yield* api({
1354 cwd: input.cwd,
1355 + host: input.host,
1356 path: `${subject}/${own.success}`,
1357 method: "DELETE",
1358 });
@@ -1305,6 +1361,7 @@ export const make = Effect.gen(function* () {
1361 listCommits: Effect.fn("GitLabPullRequestCli.listCommits")(function (input) {
1362 return api({
1363 cwd: input.cwd,
1364 + host: input.host,
1365 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/commits?${query(
1366 [
1367 ["per_page", String(COMMIT_PAGE_SIZE)],
@@ -1334,6 +1391,7 @@ export const make = Effect.gen(function* () {
1391 }
1392 const target = {
1393 cwd: input.cwd,
1394 + host: input.host,
1395 repository: input.repository,
1396 number: input.number,
1397 ...(input.commit === undefined ? {} : { commit: input.commit }),
@@ -1357,6 +1415,7 @@ export const make = Effect.gen(function* () {
1415 ? getDiffRefs(input)
1416 : getCommitDiffRefs({
1417 cwd: input.cwd,
1418 + host: input.host,
1419 repository: input.repository,
1420 commit: input.commit,
1421 allowRoot: input.changeType === "new",
@@ -1365,6 +1424,7 @@ export const make = Effect.gen(function* () {
1424 const readFile = (revision: string, filePath: string) =>
1425 api({
1426 cwd: input.cwd,
1427 + host: input.host,
1428 path: `projects/${projectPath(input.repository)}/repository/files/${encodeURIComponent(
1429 filePath,
1430 )}/raw?ref=${encodeURIComponent(revision)}`,
@@ -1403,6 +1463,7 @@ export const make = Effect.gen(function* () {
1463 function (input) {
1464 return api({
1465 cwd: input.cwd,
1466 + host: input.host,
1467 path: `projects/${projectPath(input.repository)}?license=false`,
1468 }).pipe(
1469 Effect.flatMap((result) => {
@@ -1425,6 +1486,7 @@ export const make = Effect.gen(function* () {
1486 listProjectLabels: Effect.fn("GitLabPullRequestCli.listProjectLabels")(function (input) {
1487 return api({
1488 cwd: input.cwd,
1489 + host: input.host,
1490 path: `projects/${projectPath(input.repository)}/labels?${query([
1491 ["per_page", String(MAX_PAGE_SIZE)],
1492 ...searchParams(input.search),
@@ -1493,6 +1555,7 @@ export const make = Effect.gen(function* () {
1555 }
1556 return api({
1557 cwd: input.cwd,
1558 + host: input.host,
1559 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}`,
1560 method: "PUT",
1561 stdin: JSON.stringify({ reviewer_ids: [...ids] }),
@@ -1510,6 +1573,7 @@ export const make = Effect.gen(function* () {
1573 if (input.action === "disable-auto-merge") {
1574 return yield* api({
1575 cwd: input.cwd,
1576 + host: input.host,
1577 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/cancel_merge_when_pipeline_succeeds`,
1578 method: "POST",
1579 }).pipe(Effect.asVoid);
@@ -1517,6 +1581,7 @@ export const make = Effect.gen(function* () {
1581 const executeMr = (subcommand: string, ...flags: ReadonlyArray<string>) =>
1582 gitlab.execute({
1583 cwd: input.cwd,
1584 + host: input.host,
1585 args: ["mr", subcommand, String(input.number), "--repo", input.repository, ...flags],
1586 });
1587 const [subcommand, ...flags] = actionArgs(input.action, input.mergeMethod);
@@ -1535,6 +1600,7 @@ export const make = Effect.gen(function* () {
1600 updateMergeRequest: Effect.fn("GitLabPullRequestCli.updateMergeRequest")(function (input) {
1601 return api({
1602 cwd: input.cwd,
1603 + host: input.host,
1604 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}`,
1605 method: "PUT",
1606 // Omitted fields remain unchanged; empty values clear them.
@@ -1549,6 +1615,7 @@ export const make = Effect.gen(function* () {
1615 function (input) {
1616 return api({
1617 cwd: input.cwd,
1618 + host: input.host,
1619 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/notes`,
1620 method: "POST",
1621 // JSON avoids glab's coercion of numeric/boolean comment bodies.
@@ -1560,6 +1627,7 @@ export const make = Effect.gen(function* () {
1627 updateNote: Effect.fn("GitLabPullRequestCli.updateNote")(function (input) {
1628 return api({
1629 cwd: input.cwd,
1630 + host: input.host,
1631 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/notes/${encodeURIComponent(
1632 input.noteId,
1633 )}`,
@@ -1586,6 +1654,7 @@ export const make = Effect.gen(function* () {
1654 (comment) =>
1655 api({
1656 cwd: input.cwd,
1657 + host: input.host,
1658 path: `${mergeRequest}/discussions`,
1659 method: "POST",
1660 stdin: JSON.stringify({
@@ -1610,6 +1679,7 @@ export const make = Effect.gen(function* () {
1679 if (input.body.trim().length > 0) {
1680 yield* api({
1681 cwd: input.cwd,
1682 + host: input.host,
1683 path: `${mergeRequest}/notes`,
1684 method: "POST",
1685 // @effect-diagnostics-next-line preferSchemaOverJson:off
@@ -1617,13 +1687,19 @@ export const make = Effect.gen(function* () {
1687 });
1688 }
1689 if (input.verdict === "approve") {
1620 - yield* api({ cwd: input.cwd, path: `${mergeRequest}/approve`, method: "POST" });
1690 + yield* api({
1691 + cwd: input.cwd,
1692 + host: input.host,
1693 + path: `${mergeRequest}/approve`,
1694 + method: "POST",
1695 + });
1696 }
1697 }),
1698
1699 replyToDiscussion: Effect.fn("GitLabPullRequestCli.replyToDiscussion")(function (input) {
1700 return api({
1701 cwd: input.cwd,
1702 + host: input.host,
1703 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/discussions/${encodeURIComponent(
1704 input.discussionId,
1705 )}/notes`,
@@ -1636,6 +1712,7 @@ export const make = Effect.gen(function* () {
1712 function (input) {
1713 return api({
1714 cwd: input.cwd,
1715 + host: input.host,
1716 path: `projects/${projectPath(input.repository)}/merge_requests/${input.number}/discussions/${encodeURIComponent(
1717 input.discussionId,
1718 )}`,
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts
+124 -7
@@ -3,10 +3,123 @@ import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as TestClock from "effect/testing/TestClock";
5
6 +import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";
7 +
8 import * as GitLabCli from "./GitLabCli.ts";
9 import * as GitLabPullRequestCli from "./GitLabPullRequestCli.ts";
10 import { gitLabViewerPermissions, make } from "./GitLabPullRequestProvider.ts";
11
12 +it.effect.each(["merge", "disable-auto-merge"] as const)(
13 + "keeps reads and %s on the selected host when glab prefers another remote",
14 + (action) =>
15 + Effect.gen(function* () {
16 + const selectedHost = "gitlab.example.test:8443";
17 + const otherHost = "other.gitlab.example.test";
18 + const readHosts: string[] = [];
19 + const mergedHosts: string[] = [];
20 + const native = yield* GitLabCli.make.pipe(
21 + Effect.provide(
22 + TestSourceControlHost.layer({
23 + process: {
24 + run: (input) => {
25 + // glab prefers a remote named `gitlab` to `origin`. The checkout's
26 + // selected repository must still own every request and mutation.
27 + const host = input.env?.GITLAB_HOST ?? otherHost;
28 + const path = input.args[1];
29 + const mutation =
30 + input.args[0] === "mr" || (input.args.includes("POST") && path !== "graphql");
31 + if (mutation) mergedHosts.push(host);
32 + else readHosts.push(host);
33 + const response = mutation
34 + ? {}
35 + : path === "graphql"
36 + ? {
37 + data: {
38 + project: {
39 + mergeRequests: {
40 + nodes: [
41 + { iid: "7", diffStatsSummary: { additions: 2, deletions: 1 } },
42 + ],
43 + },
44 + mergeRequest: {
45 + diffStatsSummary: { fileCount: 1 },
46 + diffStats: [{ path: "src/a.ts", additions: 2, deletions: 1 }],
47 + },
48 + },
49 + },
50 + }
51 + : path?.includes("merge_requests/")
52 + ? {
53 + iid: 7,
54 + title: "Merge request 7",
55 + web_url: `https://${host}/acme/web/-/merge_requests/7`,
56 + source_branch: "feature",
57 + target_branch: "main",
58 + created_at: "2026-07-01T00:00:00Z",
59 + updated_at: "2026-07-02T00:00:00Z",
60 + user: { can_merge: true },
61 + diff_refs: {
62 + head_sha: "a".repeat(40),
63 + base_sha: "b".repeat(40),
64 + start_sha: "b".repeat(40),
65 + },
66 + }
67 + : path === "user"
68 + ? { username: "reviewer" }
69 + : path?.includes("/labels?") || path?.includes("/users?")
70 + ? []
71 + : { merge_method: "merge", squash_option: "default_off" };
72 + return Effect.succeed(
73 + TestSourceControlHost.processOutput(JSON.stringify(response)),
74 + );
75 + },
76 + },
77 + }),
78 + ),
79 + );
80 + const cli = yield* GitLabPullRequestCli.make.pipe(
81 + Effect.provideService(GitLabCli.GitLabCli, native),
82 + );
83 + const provider = yield* make.pipe(
84 + Effect.provideService(GitLabPullRequestCli.GitLabPullRequestCli, cli),
85 + );
86 + const reference = {
87 + cwd: "/repo",
88 + repository: "acme/web",
89 + host: selectedHost,
90 + number: 7,
91 + };
92 + const detail = yield* provider.getChangeRequest(reference);
93 + expect({ additions: detail.additions, deletions: detail.deletions }).toEqual({
94 + additions: 2,
95 + deletions: 1,
96 + });
97 + assert.isDefined(provider.getChangeRequestSummary);
98 + expect((yield* provider.getChangeRequestSummary(reference)).additions).toBe(2);
99 + assert.isDefined(provider.listChangeRequestStats);
100 + expect(
101 + yield* provider.listChangeRequestStats({ ...reference, changeRequests: [reference] }),
102 + ).toEqual([{ repository: reference.repository, number: 7, additions: 2, deletions: 1 }]);
103 + assert.isDefined(provider.getFileStats);
104 + expect(yield* provider.getFileStats(reference)).toEqual({
105 + files: [{ path: "src/a.ts", additions: 2, deletions: 1 }],
106 + truncated: false,
107 + });
108 + expect(yield* provider.getViewer(reference)).toBe("reviewer");
109 + assert.isDefined(provider.listRepositoryLabels);
110 + yield* provider.listRepositoryLabels(reference);
111 + assert.isDefined(provider.searchRepositoryAuthors);
112 + yield* provider.searchRepositoryAuthors(reference);
113 + yield* provider.runAction({ ...reference, action });
114 +
115 + expect(readHosts).toEqual(Array(action === "merge" ? 11 : 10).fill(selectedHost));
116 + expect({ url: detail.url, mutatedHosts: mergedHosts }).toEqual({
117 + url: `https://${selectedHost}/acme/web/-/merge_requests/7`,
118 + mutatedHosts: [selectedHost],
119 + });
120 + }),
121 +);
122 +
123 describe("gitLabViewerPermissions", () => {
124 it("offers everything to a viewer GitLab says can merge", () => {
125 expect(gitLabViewerPermissions({ viewerCanMerge: true })).toEqual({
@@ -282,15 +395,19 @@ describe("merge request reads", () => {
395 }),
396 );
397
285 - it.effect("does not share reads between checkouts", () =>
286 - Effect.gen(function* () {
287 - const { provider, calls } = yield* countingProvider;
398 + it.effect.each([{ cwd: "/other" }, { host: "other.gitlab.test" }])(
399 + "does not share reads with %j",
400 + (other) =>
401 + Effect.gen(function* () {
402 + const { provider, calls } = yield* countingProvider;
403
289 - yield* provider.getChangeRequest(reference);
290 - yield* provider.getChangeRequest({ ...reference, cwd: "/other" });
404 + yield* provider.getChangeRequest(reference);
405 + yield* provider.getChangeRequest({ ...reference, ...other });
406 + yield* provider.getChangeRequest(reference);
407 + yield* provider.getChangeRequest({ ...reference, ...other });
408
292 - expect(calls).toEqual({ detail: 2, mergeCapabilities: 2 });
293 - }),
409 + expect(calls).toEqual({ detail: 2, mergeCapabilities: 2 });
410 + }),
411 );
412
413 it.effect("reads a merge request again once a minute has passed", () =>
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+50 -17
@@ -102,8 +102,8 @@ export const make = Effect.gen(function* () {
102 // checkout's remote and config, so two checkouts may read the same project as different people.
103 const mergeRequestDetails = yield* Cache.makeWith(
104 (key: string) => {
105 - const [cwd, repository, number] = JSON.parse(key) as [string, string, number];
106 - return cli.getMergeRequestDetail({ cwd, repository, number });
105 + const [cwd, repository, number, host] = JSON.parse(key) as [string, string, number, string];
106 + return cli.getMergeRequestDetail({ cwd, repository, number, host });
107 },
108 {
109 capacity: READ_CACHE_CAPACITY,
@@ -112,8 +112,8 @@ export const make = Effect.gen(function* () {
112 );
113 const projectMergeCapabilities = yield* Cache.makeWith(
114 (key: string) => {
115 - const [cwd, repository] = JSON.parse(key) as [string, string];
116 - return cli.getProjectMergeCapabilities({ cwd, repository });
115 + const [cwd, repository, host] = JSON.parse(key) as [string, string, string];
116 + return cli.getProjectMergeCapabilities({ cwd, repository, host });
117 },
118 {
119 capacity: READ_CACHE_CAPACITY,
@@ -123,11 +123,13 @@ export const make = Effect.gen(function* () {
123
124 const detailKey = (input: {
125 readonly cwd: string;
126 + readonly host: string;
127 readonly repository: string;
128 readonly number: number;
128 - }) => JSON.stringify([input.cwd, input.repository, input.number]);
129 + }) => JSON.stringify([input.cwd, input.repository, input.number, input.host]);
130 const mergeRequestDetail = (input: {
131 readonly cwd: string;
132 + readonly host: string;
133 readonly repository: string;
134 readonly number: number;
135 }) => Cache.get(mergeRequestDetails, detailKey(input));
@@ -136,7 +138,12 @@ export const make = Effect.gen(function* () {
138 // write is in flight must not outlive it.
139 const writing =
140 <
139 - I extends { readonly cwd: string; readonly repository: string; readonly number: number },
141 + I extends {
142 + readonly cwd: string;
143 + readonly host: string;
144 + readonly repository: string;
145 + readonly number: number;
146 + },
147 A,
148 E,
149 >(
@@ -177,14 +184,21 @@ export const make = Effect.gen(function* () {
184 const mergeRequestWithStats = (
185 input: {
186 readonly cwd: string;
187 + readonly host: string;
188 readonly repository: string;
189 readonly number: number;
190 },
191 detail = cli.getMergeRequestDetail(input),
192 ) =>
185 - Effect.all([detail, cli.listMergeRequestStats({ cwd: input.cwd, changeRequests: [input] })], {
186 - concurrency: 2,
187 - }).pipe(
193 + Effect.all(
194 + [
195 + detail,
196 + cli.listMergeRequestStats({ cwd: input.cwd, host: input.host, changeRequests: [input] }),
197 + ],
198 + {
199 + concurrency: 2,
200 + },
201 + ).pipe(
202 Effect.map(([mergeRequest, [stat]]) =>
203 stat === undefined
204 ? mergeRequest
@@ -197,13 +211,13 @@ export const make = Effect.gen(function* () {
211 capabilities: CAPABILITIES,
212 unavailableRequirement: UNAVAILABLE_REQUIREMENT,
213
200 - getViewer: (input) =>
201 - cli.getViewerUsername({ cwd: input.cwd }).pipe(Effect.mapError(fail("getViewer"))),
214 + getViewer: (input) => cli.getViewerUsername(input).pipe(Effect.mapError(fail("getViewer"))),
215
216 listChangeRequests: (input) =>
217 cli
218 .listMergeRequests({
219 cwd: input.cwd,
220 + host: input.host,
221 repository: input.repository,
222 state: input.state,
223 involvement: input.involvement,
@@ -222,9 +236,7 @@ export const make = Effect.gen(function* () {
236 cli.getMergeRequestFileStats(input).pipe(Effect.mapError(fail("getFileStats"))),
237
238 listChangeRequestStats: (input) =>
225 - cli
226 - .listMergeRequestStats({ cwd: input.cwd, changeRequests: input.changeRequests })
227 - .pipe(Effect.mapError(fail("listChangeRequestStats"))),
239 + cli.listMergeRequestStats(input).pipe(Effect.mapError(fail("listChangeRequestStats"))),
240
241 getChangeRequestChecks: (input) =>
242 mergeRequestDetail(input).pipe(
@@ -243,7 +255,10 @@ export const make = Effect.gen(function* () {
255 Effect.all(
256 [
257 mergeRequestWithStats(input, mergeRequestDetail(input)),
246 - Cache.get(projectMergeCapabilities, JSON.stringify([input.cwd, input.repository])),
258 + Cache.get(
259 + projectMergeCapabilities,
260 + JSON.stringify([input.cwd, input.repository, input.host]),
261 + ),
262 ],
263 { concurrency: 2 },
264 ).pipe(
@@ -339,6 +354,7 @@ export const make = Effect.gen(function* () {
354 cli
355 .listReviewerCandidates({
356 cwd: input.cwd,
357 + host: input.host,
358 repository: input.repository,
359 number: input.number,
360 })
@@ -346,18 +362,29 @@ export const make = Effect.gen(function* () {
362
363 listRepositoryLabels: (input) =>
364 cli
349 - .listProjectLabels({ cwd: input.cwd, repository: input.repository, search: input.query })
365 + .listProjectLabels({
366 + cwd: input.cwd,
367 + host: input.host,
368 + repository: input.repository,
369 + search: input.query,
370 + })
371 .pipe(Effect.mapError(fail("listRepositoryLabels"))),
372
373 searchRepositoryAuthors: (input) =>
374 cli
354 - .listProjectUsers({ cwd: input.cwd, repository: input.repository, search: input.query })
375 + .listProjectUsers({
376 + cwd: input.cwd,
377 + host: input.host,
378 + repository: input.repository,
379 + search: input.query,
380 + })
381 .pipe(Effect.mapError(fail("searchRepositoryAuthors"))),
382
383 setReviewerRequest: writing((input) =>
384 cli
385 .setReviewerRequest({
386 cwd: input.cwd,
387 + host: input.host,
388 repository: input.repository,
389 number: input.number,
390 reviewers: input.reviewers,
@@ -370,6 +397,7 @@ export const make = Effect.gen(function* () {
397 cli
398 .runMergeRequestAction({
399 cwd: input.cwd,
400 + host: input.host,
401 repository: input.repository,
402 number: input.number,
403 action: input.action,
@@ -382,6 +410,7 @@ export const make = Effect.gen(function* () {
410 cli
411 .updateMergeRequest({
412 cwd: input.cwd,
413 + host: input.host,
414 repository: input.repository,
415 number: input.number,
416 ...(input.title === undefined ? {} : { title: input.title }),
@@ -398,6 +427,7 @@ export const make = Effect.gen(function* () {
427 cli
428 .updateNote({
429 cwd: input.cwd,
430 + host: input.host,
431 repository: input.repository,
432 number: input.number,
433 noteId: input.commentId,
@@ -414,6 +444,7 @@ export const make = Effect.gen(function* () {
444 cli
445 .replyToDiscussion({
446 cwd: input.cwd,
447 + host: input.host,
448 repository: input.repository,
449 number: input.number,
450 discussionId: input.threadId,
@@ -426,6 +457,7 @@ export const make = Effect.gen(function* () {
457 cli
458 .setReaction({
459 cwd: input.cwd,
460 + host: input.host,
461 repository: input.repository,
462 number: input.number,
463 ...(input.subjectId === undefined ? {} : { noteId: input.subjectId }),
@@ -439,6 +471,7 @@ export const make = Effect.gen(function* () {
471 cli
472 .setDiscussionResolution({
473 cwd: input.cwd,
474 + host: input.host,
475 repository: input.repository,
476 number: input.number,
477 discussionId: input.threadId,