The best way to control Claude Code, Codex and more from any computer or phone
fix(gitlab): the checks panel lists each pipeline job (#28728)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>
Antony committed
Nov 6, 2026 at 02:06 UTC
bda0e7f411246cd483a6900d373f44a5b88c179b
4 files changed
+586
-47
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+219
-46
@@ -1,4 +1,4 @@
1
-import { afterEach, assert, expect, it, vi } from "@effect/vitest";
1
+import { afterEach, assert, describe, expect, it, vi } from "@effect/vitest";
2
import { VcsProcessExitError } from "@t3tools/contracts";
3
import * as Effect from "effect/Effect";
4
import * as Layer from "effect/Layer";
@@ -1494,40 +1494,42 @@ layer("GitLabPullRequestCli.layer", (it) => {
1494
1495
it.effect("shows a failed child pipeline that left the head pipeline green", () =>
1496
Effect.gen(function* () {
1497
- mockedExecute
1498
- .mockReturnValueOnce(
1499
- Effect.succeed(
1500
- output(
1501
- mergeRequestJson({
1502
- // A fork's pipeline runs in the source project, so its id is not the target's.
1503
- head_pipeline: {
1504
- id: 31,
1505
- project_id: 12,
1506
- status: "success",
1507
- web_url: "https://gitlab.com/bilal/web/-/pipelines/31",
1508
- },
1509
- }),
1510
- ),
1511
- ),
1512
- )
1513
- .mockReturnValueOnce(Effect.succeed(labelPermission))
1514
- .mockReturnValueOnce(
1515
- Effect.succeed(
1516
- output(
1517
- JSON.stringify([
1518
- {
1519
- name: "deploy",
1520
- status: "success",
1521
- downstream_pipeline: {
1522
- status: "failed",
1523
- web_url: "https://gitlab.com/bilal/web/-/pipelines/32",
1497
+ mockedExecute.mockImplementation((request) => {
1498
+ switch (request.args[1]) {
1499
+ case "graphql":
1500
+ return Effect.succeed(output("{}"));
1501
+ case "projects/12/pipelines/31/bridges?per_page=100":
1502
+ return Effect.succeed(
1503
+ output(
1504
+ JSON.stringify([
1505
+ {
1506
+ name: "deploy",
1507
+ status: "success",
1508
+ downstream_pipeline: {
1509
+ status: "failed",
1510
+ web_url: "https://gitlab.com/bilal/web/-/pipelines/32",
1511
+ },
1512
},
1525
- },
1526
- { name: "docs", status: "created", downstream_pipeline: null },
1527
- ]),
1528
- ),
1529
- ),
1530
- );
1513
+ { name: "docs", status: "created", downstream_pipeline: null },
1514
+ ]),
1515
+ ),
1516
+ );
1517
+ default:
1518
+ return Effect.succeed(
1519
+ output(
1520
+ mergeRequestJson({
1521
+ // A fork's pipeline runs in the source project, so its id is not the target's.
1522
+ head_pipeline: {
1523
+ id: 31,
1524
+ project_id: 12,
1525
+ status: "success",
1526
+ web_url: "https://gitlab.com/bilal/web/-/pipelines/31",
1527
+ },
1528
+ }),
1529
+ ),
1530
+ );
1531
+ }
1532
+ });
1533
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1534
1535
const detail = yield* cli.getMergeRequestDetail({
@@ -1540,7 +1542,6 @@ layer("GitLabPullRequestCli.layer", (it) => {
1542
["Pipeline", "success", "https://gitlab.com/bilal/web/-/pipelines/31"],
1543
["deploy", "failure", "https://gitlab.com/bilal/web/-/pipelines/32"],
1544
]);
1543
- expect(argsOfCall(2)[1]).toBe("projects/12/pipelines/31/bridges?per_page=100");
1545
}),
1546
);
1547
@@ -1550,10 +1551,11 @@ layer("GitLabPullRequestCli.layer", (it) => {
1551
mergeRequestJson({ head_pipeline: { id: 31, project_id: 12, status: "success" } }),
1552
);
1553
const failedChild = { name: "deploy", downstream_pipeline: { status: "failed" } };
1553
- mockedExecute
1554
- .mockReturnValueOnce(Effect.succeed(detailOutput))
1555
- .mockReturnValueOnce(Effect.succeed(labelPermission))
1556
- .mockReturnValueOnce(
1554
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1555
+
1556
+ for (const [scenario, bridges] of [
1557
+ [
1558
+ "read fails",
1559
Effect.fail(
1560
new GitLabCli.GitLabCliCommandError({
1561
operation: "execute",
@@ -1562,16 +1564,20 @@ layer("GitLabPullRequestCli.layer", (it) => {
1564
cause: new Error("403 Forbidden"),
1565
}),
1566
),
1565
- )
1566
- .mockReturnValueOnce(Effect.succeed(detailOutput))
1567
- .mockReturnValueOnce(Effect.succeed(labelPermission))
1567
+ ],
1568
// A full page may have left out the trigger job whose pipeline failed.
1569
- .mockReturnValueOnce(
1569
+ [
1570
+ "page is full",
1571
Effect.succeed(output(JSON.stringify(Array.from({ length: 100 }, () => failedChild)))),
1572
+ ],
1573
+ ] as const) {
1574
+ mockedExecute.mockImplementation((request) =>
1575
+ request.args[1] === "graphql"
1576
+ ? Effect.succeed(output("{}"))
1577
+ : request.args[1]?.includes("/bridges")
1578
+ ? bridges
1579
+ : Effect.succeed(detailOutput),
1580
);
1572
- const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1573
-
1574
- for (const scenario of ["read fails", "page is full"]) {
1581
const detail = yield* cli.getMergeRequestDetail({
1582
cwd: "/w",
1583
repository: "acme/web",
@@ -2147,4 +2153,171 @@ layer("GitLabPullRequestCli.layer", (it) => {
2153
expect(result).toMatchObject({ _tag: "Failure", failure: error });
2154
}),
2155
);
2156
+ describe("the head pipeline's stages", () => {
2157
+ const pipeline = {
2158
+ id: 9,
2159
+ project_id: 12,
2160
+ status: "failed",
2161
+ web_url: "https://gitlab.com/acme/web/-/pipelines/9",
2162
+ source: "merge_request_event",
2163
+ };
2164
+ const stages = JSON.stringify({
2165
+ data: {
2166
+ project: {
2167
+ mergeRequest: {
2168
+ headPipeline: {
2169
+ path: "/acme/web/-/pipelines/9",
2170
+ stages: {
2171
+ nodes: [
2172
+ { name: "build", status: "success", detailedStatus: { label: "passed" } },
2173
+ {
2174
+ name: "test",
2175
+ status: "failed",
2176
+ jobs: {
2177
+ nodes: [{ name: "unit", status: "FAILED", webPath: "/acme/web/-/jobs/3" }],
2178
+ },
2179
+ },
2180
+ {
2181
+ name: "deploy",
2182
+ status: "success",
2183
+ jobs: {
2184
+ nodes: [
2185
+ // A trigger job without `strategy: depend` succeeds whatever its child does.
2186
+ {
2187
+ name: "child-pipeline",
2188
+ status: "SUCCESS",
2189
+ webPath: null,
2190
+ downstreamPipeline: {
2191
+ status: "FAILED",
2192
+ path: "/acme/child/-/pipelines/10",
2193
+ },
2194
+ },
2195
+ ],
2196
+ },
2197
+ },
2198
+ ],
2199
+ },
2200
+ },
2201
+ },
2202
+ },
2203
+ },
2204
+ });
2205
+
2206
+ function answer(graphql: Effect.Effect<ReturnType<typeof output>, GitLabCli.GitLabCliError>) {
2207
+ mockedExecute.mockImplementation((request) =>
2208
+ request.args[1] === "graphql"
2209
+ ? request.stdin?.includes("adminMergeRequest")
2210
+ ? Effect.succeed(labelPermission)
2211
+ : graphql
2212
+ : request.args[1]?.includes("/bridges")
2213
+ ? Effect.succeed(
2214
+ output(
2215
+ JSON.stringify([
2216
+ {
2217
+ name: "child-pipeline",
2218
+ status: "success",
2219
+ downstream_pipeline: {
2220
+ status: "failed",
2221
+ web_url: "https://gitlab.com/acme/child/-/pipelines/10",
2222
+ },
2223
+ },
2224
+ ]),
2225
+ ),
2226
+ )
2227
+ : Effect.succeed(output(mergeRequestJson({ head_pipeline: pipeline }))),
2228
+ );
2229
+ }
2230
+
2231
+ const read = (downstreamChecks: boolean) =>
2232
+ GitLabPullRequestCli.GitLabPullRequestCli.pipe(
2233
+ Effect.flatMap((cli) =>
2234
+ cli.getMergeRequestDetail({
2235
+ cwd: "/w",
2236
+ repository: "group/acme/web",
2237
+ number: 7,
2238
+ downstreamChecks,
2239
+ }),
2240
+ ),
2241
+ );
2242
+
2243
+ it.effect("shows the stage jobs, and a stage GitLab listed no jobs for", () =>
2244
+ Effect.gen(function* () {
2245
+ answer(Effect.succeed(output(stages)));
2246
+
2247
+ const detail = yield* read(true);
2248
+
2249
+ const graphql = mockedExecute.mock.calls.find(([call]) => call.stdin?.includes("stages"));
2250
+ assert.isDefined(graphql);
2251
+ expect(JSON.parse(graphql[0].stdin ?? "").variables).toEqual({
2252
+ fullPath: "group/acme/web",
2253
+ iid: "7",
2254
+ });
2255
+ expect(detail.checks).toEqual([
2256
+ {
2257
+ name: "build",
2258
+ status: "success",
2259
+ description: "passed",
2260
+ url: "https://gitlab.com/acme/web/-/pipelines/9",
2261
+ },
2262
+ {
2263
+ name: "test / unit",
2264
+ status: "failure",
2265
+ description: null,
2266
+ url: "https://gitlab.com/acme/web/-/jobs/3",
2267
+ },
2268
+ {
2269
+ name: "deploy / child-pipeline",
2270
+ status: "failure",
2271
+ description: "Downstream pipeline",
2272
+ url: "https://gitlab.com/acme/child/-/pipelines/10",
2273
+ },
2274
+ ]);
2275
+ }),
2276
+ );
2277
+
2278
+ it.effect("keeps the pipeline check where the stages cannot be read", () =>
2279
+ Effect.gen(function* () {
2280
+ answer(
2281
+ Effect.fail(
2282
+ new GitLabCli.GitLabCliCommandError({
2283
+ operation: "execute",
2284
+ command: "glab",
2285
+ cwd: "/w",
2286
+ cause: new Error("graphql unavailable"),
2287
+ }),
2288
+ ),
2289
+ );
2290
+
2291
+ const detail = yield* read(true);
2292
+
2293
+ expect(detail.checks).toEqual([
2294
+ {
2295
+ name: "Pipeline",
2296
+ status: "failure",
2297
+ description: "merge_request_event",
2298
+ url: "https://gitlab.com/acme/web/-/pipelines/9",
2299
+ },
2300
+ {
2301
+ name: "child-pipeline",
2302
+ status: "failure",
2303
+ description: "Downstream pipeline",
2304
+ url: "https://gitlab.com/acme/child/-/pipelines/10",
2305
+ },
2306
+ ]);
2307
+ }),
2308
+ );
2309
+
2310
+ it.effect("asks for no stages when the caller only needs the merge request", () =>
2311
+ Effect.gen(function* () {
2312
+ answer(Effect.succeed(output(stages)));
2313
+
2314
+ const detail = yield* read(false);
2315
+
2316
+ expect(
2317
+ mockedExecute.mock.calls.filter(([call]) => call.stdin?.includes("stages")),
2318
+ ).toHaveLength(0);
2319
+ expect(detail.checks.map((check) => check.name)).toEqual(["Pipeline"]);
2320
+ }),
2321
+ );
2322
+ });
2323
});
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+25
-1
@@ -33,6 +33,7 @@ import type {
33
import * as GitLabCli from "./GitLabCli.ts";
34
import {
35
AWARD_EMOJI_GRAPHQL_QUERY,
36
+ PIPELINE_STAGES_GRAPHQL_QUERY,
37
decodeAwardEmojiJson,
38
decodeBranchJson,
39
decodeCommitDiffRefsJson,
@@ -52,6 +53,7 @@ import {
53
decodeMergeRequestStatsJson,
54
decodeNotesJson,
55
decodeOwnAwardIdJson,
56
+ decodePipelineStageChecksJson,
57
decodeProjectMergeCapabilitiesJson,
58
decodeProjectLabelsJson,
59
decodeProjectUsersJson,
@@ -343,7 +345,7 @@ export class GitLabPullRequestCli extends Context.Service<
345
readonly host?: string | undefined;
346
readonly repository: string;
347
readonly number: number;
346
- /** `false` skips the trigger job read; the permission check before every write does. */
348
+ /** `false` skips the stage and trigger job reads, as write permission checks do. */
349
readonly downstreamChecks?: boolean;
350
}) => Effect.Effect<GitLabMergeRequestDetail, GitLabPullRequestCliError>;
351
@@ -1255,6 +1257,25 @@ export const make = Effect.gen(function* () {
1257
Effect.orElseSucceed((): ReadonlyArray<PullRequestCheck> => []),
1258
);
1259
1260
+ // Best-effort: stages that can't be read keep the merge request's single pipeline check.
1261
+ const pipelineStageChecks = (input: {
1262
+ readonly cwd: string;
1263
+ readonly host?: string | undefined;
1264
+ readonly repository: string;
1265
+ readonly number: number;
1266
+ readonly url: string;
1267
+ }): Effect.Effect<ReadonlyArray<PullRequestCheck> | null> =>
1268
+ URL.canParse(input.url)
1269
+ ? graphqlRead({
1270
+ cwd: input.cwd,
1271
+ host: input.host,
1272
+ operation: "getPipelineStageChecks",
1273
+ query: PIPELINE_STAGES_GRAPHQL_QUERY,
1274
+ variables: { fullPath: input.repository, iid: String(input.number) },
1275
+ decode: (raw) => decodePipelineStageChecksJson(raw, new URL(input.url).origin),
1276
+ }).pipe(Effect.orElseSucceed(() => null))
1277
+ : Effect.succeed(null);
1278
+
1279
const projectUsers = (input: {
1280
readonly cwd: string;
1281
readonly host?: string | undefined;
@@ -1848,6 +1869,9 @@ export const make = Effect.gen(function* () {
1869
),
1870
};
1871
if (input.downstreamChecks === false || detail.headPipeline === undefined) return detail;
1872
+ // The stages already carry each trigger job's downstream pipeline.
1873
+ const stages = yield* pipelineStageChecks({ ...input, url: detail.url });
1874
+ if (stages !== null) return { ...detail, checks: stages };
1875
const downstream = yield* triggerJobChecks({
1876
cwd: input.cwd,
1877
pipeline: detail.headPipeline,
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts
+186
@@ -17,6 +17,7 @@ import {
17
decodeOwnAwardIdJson,
18
decodeListStatesJson,
19
decodeTriggerJobChecksJson,
20
+ decodePipelineStageChecksJson,
21
} from "./gitLabMergeRequestJson.ts";
22
23
function listJson(entries: ReadonlyArray<Record<string, unknown>>): string {
@@ -255,6 +256,191 @@ describe("decodeMergeRequestDetailJson", () => {
256
});
257
});
258
259
+describe("decodePipelineStageChecksJson", () => {
260
+ function stagesJson(
261
+ stages: ReadonlyArray<Record<string, unknown> | null> | null,
262
+ hasNextPage = false,
263
+ ): string {
264
+ return JSON.stringify({
265
+ data: {
266
+ project: {
267
+ mergeRequest: {
268
+ headPipeline:
269
+ stages === null
270
+ ? null
271
+ : {
272
+ path: "/fork/web/-/pipelines/9",
273
+ stages: { nodes: stages, pageInfo: { hasNextPage } },
274
+ },
275
+ },
276
+ },
277
+ },
278
+ });
279
+ }
280
+
281
+ it("shows every job under its stage", () => {
282
+ const checks = expectSuccess(
283
+ decodePipelineStageChecksJson(
284
+ stagesJson([
285
+ {
286
+ name: "build",
287
+ status: "success",
288
+ jobs: {
289
+ nodes: [
290
+ { name: "compile", status: "FAILED", retried: true, webPath: "/acme/web/-/jobs/1" },
291
+ {
292
+ name: "compile",
293
+ status: "SUCCESS",
294
+ detailedStatus: { label: "passed" },
295
+ webPath: "/acme/web/-/jobs/2",
296
+ },
297
+ ],
298
+ },
299
+ },
300
+ {
301
+ name: "test",
302
+ status: "failed",
303
+ jobs: {
304
+ nodes: [
305
+ {
306
+ name: "unit",
307
+ status: "FAILED",
308
+ allowFailure: false,
309
+ webPath: "/acme/web/-/jobs/3",
310
+ },
311
+ {
312
+ name: "lint",
313
+ status: "FAILED",
314
+ allowFailure: true,
315
+ webPath: "/acme/web/-/jobs/4",
316
+ },
317
+ { name: "slow", status: "CANCELED", webPath: "/acme/web/-/jobs/5" },
318
+ { name: "e2e", status: "RUNNING", webPath: "/acme/web/-/jobs/6" },
319
+ ],
320
+ },
321
+ },
322
+ {
323
+ name: "deploy",
324
+ status: "manual",
325
+ jobs: { nodes: [{ name: "release", status: "MANUAL", webPath: "/acme/web/-/jobs/7" }] },
326
+ },
327
+ ]),
328
+ "https://gitlab.example.com",
329
+ ),
330
+ );
331
+
332
+ expect(checks?.map((check) => [check.name, check.status, check.url])).toEqual([
333
+ ["build / compile", "success", "https://gitlab.example.com/acme/web/-/jobs/2"],
334
+ ["test / unit", "failure", "https://gitlab.example.com/acme/web/-/jobs/3"],
335
+ ["test / lint", "neutral", "https://gitlab.example.com/acme/web/-/jobs/4"],
336
+ ["test / slow", "cancelled", "https://gitlab.example.com/acme/web/-/jobs/5"],
337
+ ["test / e2e", "pending", "https://gitlab.example.com/acme/web/-/jobs/6"],
338
+ ["deploy / release", "neutral", "https://gitlab.example.com/acme/web/-/jobs/7"],
339
+ ]);
340
+ expect(checks?.[0]?.description).toBe("passed");
341
+ });
342
+
343
+ it.each([
344
+ ["no jobs", undefined],
345
+ ["an empty job list", { nodes: [] }],
346
+ [
347
+ "more jobs than one page",
348
+ { nodes: [{ name: "unit", status: "FAILED" }], pageInfo: { hasNextPage: true } },
349
+ ],
350
+ ["a job GitLab could not resolve", { nodes: [{ name: "unit", status: "FAILED" }, null] }],
351
+ [
352
+ "a job without a name",
353
+ {
354
+ nodes: [
355
+ { name: "unit", status: "FAILED" },
356
+ { name: null, status: "FAILED" },
357
+ ],
358
+ },
359
+ ],
360
+ ])("keeps a stage whole where its jobs come back with %s", (_, jobs) => {
361
+ expect(
362
+ expectSuccess(
363
+ decodePipelineStageChecksJson(
364
+ stagesJson([
365
+ {
366
+ name: "test",
367
+ status: "failed",
368
+ detailedStatus: { label: "failed", detailsPath: "/fork/web/-/pipelines/9#test" },
369
+ ...(jobs === undefined ? {} : { jobs }),
370
+ },
371
+ ]),
372
+ "https://gitlab.com",
373
+ ),
374
+ ),
375
+ ).toEqual([
376
+ {
377
+ name: "test",
378
+ status: "failure",
379
+ description: "failed",
380
+ url: "https://gitlab.com/fork/web/-/pipelines/9#test",
381
+ },
382
+ ]);
383
+ });
384
+
385
+ it("answers nothing where there are no stages to show", () => {
386
+ expect(
387
+ expectSuccess(decodePipelineStageChecksJson(stagesJson(null), "https://gitlab.com")),
388
+ ).toBe(null);
389
+ expect(expectSuccess(decodePipelineStageChecksJson(stagesJson([]), "https://gitlab.com"))).toBe(
390
+ null,
391
+ );
392
+ // A stage past the first page could be the failed one.
393
+ expect(
394
+ expectSuccess(
395
+ decodePipelineStageChecksJson(
396
+ stagesJson([{ name: "build", status: "success" }], true),
397
+ "https://gitlab.com",
398
+ ),
399
+ ),
400
+ ).toBe(null);
401
+ // A stage GitLab failed to resolve comes back null beside an error, and could be the failed one.
402
+ expect(
403
+ expectSuccess(
404
+ decodePipelineStageChecksJson(
405
+ stagesJson([{ name: "build", status: "success" }, null]),
406
+ "https://gitlab.com",
407
+ ),
408
+ ),
409
+ ).toBe(null);
410
+ expect(
411
+ expectSuccess(
412
+ decodePipelineStageChecksJson(
413
+ stagesJson([
414
+ { name: "build", status: "success" },
415
+ { name: null, status: "failed" },
416
+ ]),
417
+ "https://gitlab.com",
418
+ ),
419
+ ),
420
+ ).toBe(null);
421
+ expect(
422
+ expectSuccess(
423
+ decodePipelineStageChecksJson(
424
+ JSON.stringify({
425
+ ...JSON.parse(stagesJson([{ name: "build", status: "success" }])),
426
+ errors: [{ message: "boom" }],
427
+ }),
428
+ "https://gitlab.com",
429
+ ),
430
+ ),
431
+ ).toBe(null);
432
+ // GitLab answers an error it hit with no data at all.
433
+ expect(
434
+ expectSuccess(
435
+ decodePipelineStageChecksJson(
436
+ JSON.stringify({ errors: [{ message: "boom" }] }),
437
+ "https://gitlab.com",
438
+ ),
439
+ ),
440
+ ).toBe(null);
441
+ });
442
+});
443
+
444
describe("decodeNotesJson", () => {
445
it("keeps comments and drops GitLab's own activity notes", () => {
446
const notes = expectSuccess(
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+156
@@ -305,6 +305,162 @@ function toChecks(
305
];
306
}
307
308
+export const PIPELINE_STAGES_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
309
+ project(fullPath: $fullPath) {
310
+ mergeRequest(iid: $iid) {
311
+ headPipeline {
312
+ path
313
+ stages(first: 100) {
314
+ nodes {
315
+ name
316
+ status
317
+ detailedStatus { label detailsPath }
318
+ jobs(first: 100) {
319
+ nodes {
320
+ name status allowFailure retried webPath detailedStatus { label }
321
+ downstreamPipeline { status path }
322
+ }
323
+ pageInfo { hasNextPage }
324
+ }
325
+ }
326
+ pageInfo { hasNextPage }
327
+ }
328
+ }
329
+ }
330
+ }
331
+}`;
332
+
333
+const OptionalString = Schema.optional(Schema.NullOr(Schema.String));
334
+
335
+const RawStageJobSchema = Schema.Struct({
336
+ name: OptionalString,
337
+ status: OptionalString,
338
+ allowFailure: Schema.optional(Schema.NullOr(Schema.Boolean)),
339
+ retried: Schema.optional(Schema.NullOr(Schema.Boolean)),
340
+ webPath: OptionalString,
341
+ detailedStatus: Schema.optional(Schema.NullOr(Schema.Struct({ label: OptionalString }))),
342
+ downstreamPipeline: Schema.optional(
343
+ Schema.NullOr(Schema.Struct({ status: OptionalString, path: OptionalString })),
344
+ ),
345
+});
346
+
347
+const RawStageSchema = Schema.Struct({
348
+ name: OptionalString,
349
+ status: OptionalString,
350
+ detailedStatus: Schema.optional(
351
+ Schema.NullOr(Schema.Struct({ label: OptionalString, detailsPath: OptionalString })),
352
+ ),
353
+ jobs: Schema.optional(
354
+ Schema.NullOr(
355
+ Schema.Struct({
356
+ nodes: Schema.Array(Schema.NullOr(RawStageJobSchema)),
357
+ pageInfo: Schema.optional(
358
+ Schema.NullOr(
359
+ Schema.Struct({ hasNextPage: Schema.optional(Schema.NullOr(Schema.Boolean)) }),
360
+ ),
361
+ ),
362
+ }),
363
+ ),
364
+ ),
365
+});
366
+
367
+const RawPipelineStagesSchema = Schema.Struct({
368
+ errors: Schema.optional(Schema.NullOr(Schema.Array(Schema.Unknown))),
369
+ data: Schema.optional(
370
+ Schema.NullOr(
371
+ Schema.Struct({
372
+ project: Schema.NullOr(
373
+ Schema.Struct({
374
+ mergeRequest: Schema.NullOr(
375
+ Schema.Struct({
376
+ headPipeline: Schema.NullOr(
377
+ Schema.Struct({
378
+ path: OptionalString,
379
+ stages: Schema.optional(
380
+ Schema.NullOr(
381
+ Schema.Struct({
382
+ nodes: Schema.Array(Schema.NullOr(RawStageSchema)),
383
+ pageInfo: Schema.optional(
384
+ Schema.NullOr(
385
+ Schema.Struct({
386
+ hasNextPage: Schema.optional(Schema.NullOr(Schema.Boolean)),
387
+ }),
388
+ ),
389
+ ),
390
+ }),
391
+ ),
392
+ ),
393
+ }),
394
+ ),
395
+ }),
396
+ ),
397
+ }),
398
+ ),
399
+ }),
400
+ ),
401
+ ),
402
+});
403
+
404
+const decodePipelineStages = decodeJsonResult(RawPipelineStagesSchema);
405
+
406
+/**
407
+ * The head pipeline as one check per job, named after its stage. A stage whose jobs GitLab did
408
+ * not list whole stays one check with GitLab's stage status. Null where there are no stages to
409
+ * show, or GitLab returned only some of them, so the caller keeps the single pipeline check.
410
+ */
411
+export function decodePipelineStageChecksJson(
412
+ raw: string,
413
+ origin: string,
414
+): Result.Result<ReadonlyArray<PullRequestCheck> | null, DecodeFailure> {
415
+ const decoded = decodePipelineStages(raw);
416
+ if (!Result.isSuccess(decoded)) {
417
+ return Result.fail(decoded.failure);
418
+ }
419
+ const pipeline = decoded.success.data?.project?.mergeRequest?.headPipeline;
420
+ // Any stage left out could be the failed one, so a partial list is no list.
421
+ if (
422
+ (decoded.success.errors?.length ?? 0) > 0 ||
423
+ pipeline?.stages?.pageInfo?.hasNextPage === true ||
424
+ pipeline?.stages?.nodes.some((stage) => stage === null || trimmed(stage.name) === null) === true
425
+ ) {
426
+ return Result.succeed(null);
427
+ }
428
+ const link = (path: string | null) => (path?.startsWith("/") ? `${origin}${path}` : null);
429
+ const checks: Array<PullRequestCheck> = [];
430
+ for (const stage of pipeline?.stages?.nodes ?? []) {
431
+ const name = trimmed(stage?.name);
432
+ if (stage === null || name === null) continue;
433
+ const jobs = stage.jobs?.nodes ?? [];
434
+ const listedWhole =
435
+ jobs.length > 0 &&
436
+ stage.jobs?.pageInfo?.hasNextPage !== true &&
437
+ jobs.every((job) => job !== null && trimmed(job.name) !== null);
438
+ if (!listedWhole) {
439
+ checks.push({
440
+ name,
441
+ status: toPipelineStatus(stage.status),
442
+ description: trimmed(stage.detailedStatus?.label),
443
+ url: link(trimmed(stage.detailedStatus?.detailsPath) ?? trimmed(pipeline?.path)),
444
+ });
445
+ continue;
446
+ }
447
+ for (const job of jobs) {
448
+ if (job === null || job.retried === true) continue;
449
+ // A trigger job reads as its downstream pipeline, as `decodeTriggerJobChecksJson` explains.
450
+ const downstream = job.downstreamPipeline;
451
+ const status = toPipelineStatus(downstream ? downstream.status : job.status);
452
+ checks.push({
453
+ name: `${name} / ${trimmed(job.name)}`,
454
+ // The same reading as `manual`: GitLab was told this failure does not fail the pipeline.
455
+ status: status === "failure" && job.allowFailure === true ? "neutral" : status,
456
+ description: downstream ? "Downstream pipeline" : trimmed(job.detailedStatus?.label),
457
+ url: link(trimmed(downstream ? downstream.path : job.webPath)),
458
+ });
459
+ }
460
+ }
461
+ return Result.succeed(checks.length === 0 ? null : checks);
462
+}
463
+
464
function toListItem(
465
raw: Schema.Schema.Type<typeof RawMergeRequestSchema>,
466
): GitLabMergeRequestListItem {