The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 03:15 UTC
feat(gitlab): reviews can request changes (#30549)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>
Antony committed
Nov 6, 2026 at 02:40 UTC
f829c05943e53e2d2ce07c234f50c50031d21ad8
5 files changed
+145
-9
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+44
@@ -1421,6 +1421,50 @@ layer("GitLabPullRequestCli.layer", (it) => {
1421
}),
1422
);
1423
1424
+ it.effect("requests changes as a reviewer and reports what GitLab refused", () =>
1425
+ Effect.gen(function* () {
1426
+ mockedExecute
1427
+ .mockReturnValueOnce(Effect.succeed(output(JSON.stringify({ username: "bilal" }))))
1428
+ .mockReturnValueOnce(
1429
+ Effect.succeed(
1430
+ output(JSON.stringify({ data: { mergeRequestSetReviewers: { errors: [] } } })),
1431
+ ),
1432
+ )
1433
+ .mockReturnValueOnce(
1434
+ Effect.succeed(
1435
+ output(
1436
+ JSON.stringify({
1437
+ data: { mergeRequestRequestChanges: { errors: ["Merge request is locked"] } },
1438
+ }),
1439
+ ),
1440
+ ),
1441
+ );
1442
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1443
+
1444
+ const error = yield* Effect.flip(
1445
+ cli.submitReview({
1446
+ cwd: "/w",
1447
+ repository: "acme/web",
1448
+ number: 7,
1449
+ verdict: "request-changes",
1450
+ body: "Needs work",
1451
+ comments: [{ path: "src/a.ts", position: { kind: "added", newLine: 4 }, body: "nit" }],
1452
+ }),
1453
+ );
1454
+
1455
+ expect(mockedExecute).toHaveBeenCalledTimes(3);
1456
+ const target = { projectPath: "acme/web", iid: "7" };
1457
+ const setReviewers = JSON.parse(callAt(1).stdin ?? "");
1458
+ expect(setReviewers.query).toContain("operationMode: APPEND");
1459
+ expect(setReviewers.variables).toEqual({ ...target, reviewers: ["bilal"] });
1460
+ const requestChanges = JSON.parse(callAt(2).stdin ?? "");
1461
+ expect(requestChanges.query).toContain("mergeRequestRequestChanges");
1462
+ expect(requestChanges.variables).toEqual(target);
1463
+ assert.strictEqual(error._tag, "GitLabMutationRefusedError");
1464
+ expect(error.detail).toBe("GitLab refused it: Merge request is locked");
1465
+ }),
1466
+ );
1467
+
1468
it.effect("removes an award by listing them and deleting the reader's own id", () =>
1469
Effect.gen(function* () {
1470
mockedExecute.mockReturnValueOnce(
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+76
-5
@@ -51,6 +51,7 @@ import {
51
decodeMergeRequestListJson,
52
decodeMergeRequestFileStatsJson,
53
decodeMergeRequestStatsJson,
54
+ decodeMutationErrorsJson,
55
decodeNotesJson,
56
decodeOwnAwardIdJson,
57
decodePipelineStageChecksJson,
@@ -204,6 +205,34 @@ export class GitLabDiffFileContentsUnavailableError extends Schema.TaggedError<G
205
}
206
}
207
208
+export class GitLabMutationRefusedError extends Schema.TaggedError<GitLabMutationRefusedError>()(
209
+ "GitLabMutationRefusedError",
210
+ {
211
+ command: Schema.Literal("glab"),
212
+ cwd: Schema.String,
213
+ operation: Schema.String,
214
+ reasons: Schema.Array(Schema.String),
215
+ },
216
+) {
217
+ get detail(): string {
218
+ return `GitLab refused it: ${this.reasons.join("; ")}`;
219
+ }
220
+
221
+ override get message(): string {
222
+ return `GitLab CLI failed in ${this.operation}: ${this.detail}`;
223
+ }
224
+}
225
+
226
+const SET_SELF_AS_REVIEWER_MUTATION = `mutation($projectPath: ID!, $iid: String!, $reviewers: [String!]!) {
227
+ mergeRequestSetReviewers(
228
+ input: { projectPath: $projectPath, iid: $iid, reviewerUsernames: $reviewers, operationMode: APPEND }
229
+ ) { errors }
230
+}`;
231
+
232
+const REQUEST_CHANGES_MUTATION = `mutation($projectPath: ID!, $iid: String!) {
233
+ mergeRequestRequestChanges(input: { projectPath: $projectPath, iid: $iid }) { errors }
234
+}`;
235
+
236
export class GitLabBranchDeletionRefusedError extends Schema.TaggedError<GitLabBranchDeletionRefusedError>()(
237
"GitLabBranchDeletionRefusedError",
238
{
@@ -266,7 +295,8 @@ export type GitLabPullRequestCliError =
295
| GitLabDiffCommitParentUnavailableError
296
| GitLabDiffFileContentsUnavailableError
297
| GitLabDiffRefsUnavailableError
269
- | GitLabViewerUnavailableError;
298
+ | GitLabViewerUnavailableError
299
+ | GitLabMutationRefusedError;
300
301
/** GitLab's `per_page` limit. */
302
const MAX_PAGE_SIZE = 100;
@@ -1454,6 +1484,28 @@ export const make = Effect.gen(function* () {
1484
}),
1485
);
1486
1487
+ const graphqlMutation = (input: {
1488
+ readonly cwd: string;
1489
+ readonly host?: string | undefined;
1490
+ readonly operation: string;
1491
+ readonly query: string;
1492
+ readonly variables: Record<string, unknown>;
1493
+ }) =>
1494
+ graphqlRead({ ...input, decode: decodeMutationErrorsJson }).pipe(
1495
+ Effect.flatMap((reasons) =>
1496
+ reasons.length === 0
1497
+ ? Effect.void
1498
+ : Effect.fail(
1499
+ new GitLabMutationRefusedError({
1500
+ command: "glab",
1501
+ cwd: input.cwd,
1502
+ operation: input.operation,
1503
+ reasons,
1504
+ }),
1505
+ ),
1506
+ ),
1507
+ );
1508
+
1509
const graphqlListPage = (input: {
1510
readonly cwd: string;
1511
readonly host?: string | undefined;
@@ -2337,10 +2389,29 @@ export const make = Effect.gen(function* () {
2389
submitReview: Effect.fn("GitLabPullRequestCli.submitReview")(function* (input) {
2390
const project = projectPath(input.repository);
2391
const mergeRequest = `projects/${project}/merge_requests/${input.number}`;
2340
- // GitLab has no pending review to attach comments to, so a review is replayed as the
2341
- // requests it is made of: the line comments, then the summary, then the verdict. A
2342
- // failure part-way therefore leaves what was already posted in place, which is why
2343
- // the verdict goes last — a half-sent review is never an approval.
2392
+ // GitLab has no pending review, so a review is replayed as separate requests and a failure
2393
+ // leaves earlier ones posted. Requesting changes (GitLab 18.9+) goes first so an older
2394
+ // server fails before any comment lands; approval goes last so a half-sent review never
2395
+ // approves.
2396
+ if (input.verdict === "request-changes") {
2397
+ // GitLab keeps the verdict on the reviewer, so the viewer joins the reviewers first.
2398
+ const viewer = yield* viewerUsername(input);
2399
+ const target = { projectPath: input.repository, iid: String(input.number) };
2400
+ yield* graphqlMutation({
2401
+ cwd: input.cwd,
2402
+ host: input.host,
2403
+ operation: "submitReview",
2404
+ query: SET_SELF_AS_REVIEWER_MUTATION,
2405
+ variables: { ...target, reviewers: [viewer] },
2406
+ });
2407
+ yield* graphqlMutation({
2408
+ cwd: input.cwd,
2409
+ host: input.host,
2410
+ operation: "submitReview",
2411
+ query: REQUEST_CHANGES_MUTATION,
2412
+ variables: target,
2413
+ });
2414
+ }
2415
if (input.comments.length > 0) {
2416
const refs = yield* getDiffRefs(input);
2417
yield* Effect.forEach(
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts
+2
-2
@@ -143,7 +143,7 @@ describe("gitLabViewerPermissions", () => {
143
],
144
comment: true,
145
resolve: true,
146
- verdicts: ["comment", "approve"],
146
+ verdicts: ["comment", "approve", "request-changes"],
147
requestReviewers: true,
148
labels: true,
149
updateMethods: ["rebase"],
@@ -155,7 +155,7 @@ describe("gitLabViewerPermissions", () => {
155
actions: ["ready", "draft", "close", "reopen"],
156
comment: true,
157
resolve: true,
158
- verdicts: ["comment", "approve"],
158
+ verdicts: ["comment", "approve", "request-changes"],
159
requestReviewers: true,
160
labels: false,
161
});
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+1
-2
@@ -39,8 +39,7 @@ const CAPABILITIES: PullRequestCapabilities = {
39
inlineComment: true,
40
reply: true,
41
resolve: true,
42
- // GitLab has no requested-changes verdict.
43
- verdicts: ["comment", "approve"],
42
+ verdicts: ["comment", "approve", "request-changes"],
43
},
44
reviewers: { request: true, listCandidates: true },
45
labels: true,
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+22
@@ -1712,6 +1712,28 @@ export function decodeGraphqlListSupportJson(raw: string): Result.Result<boolean
1712
return Result.succeed(major > 17 || (major === 17 && minor >= 9));
1713
}
1714
1715
+const decodeMutationPayloads = decodeJsonResult(
1716
+ Schema.Struct({
1717
+ data: Schema.Record(
1718
+ Schema.String,
1719
+ Schema.NullOr(
1720
+ Schema.Struct({ errors: Schema.optional(Schema.NullOr(Schema.Array(Schema.String))) }),
1721
+ ),
1722
+ ),
1723
+ }),
1724
+);
1725
+
1726
+/** GitLab answers a refused mutation with HTTP 200 and the reasons in each payload's `errors`. */
1727
+export function decodeMutationErrorsJson(
1728
+ raw: string,
1729
+): Result.Result<ReadonlyArray<string>, DecodeFailure> {
1730
+ const decoded = decodeMutationPayloads(raw);
1731
+ if (!Result.isSuccess(decoded)) return Result.fail(decoded.failure);
1732
+ return Result.succeed(
1733
+ Object.values(decoded.success.data).flatMap((payload) => payload?.errors ?? []),
1734
+ );
1735
+}
1736
+
1737
/**
1738
* Line counts for merge requests of one project. The REST listing carries no line counts, and
1739
* reading each diff to count them would cost a request per row, so GraphQL's per-merge-request