The best way to control Claude Code, Codex and more from any computer or phone
fix(gitlab): merge request and issue labels keep their colour (#38746)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Ernest0N committed
Nov 19, 2026 at 07:26 UTC
c57aab6fd7815d86cdca2d49545cbe5890ea7f80
7 files changed
+250
-52
packages/source-control-gitlab/src/server/GitLabIssueTracker.test.ts
+16
-4
@@ -26,7 +26,17 @@ const ISSUE = {
26
/** Every endpoint the detail read touches, answered by the path `glab api` is given. */
27
function answer(path: string): string {
28
if (path === "user") return encode({ username: "julius" });
29
- if (path === "projects/acme%2Fweb/issues/42") return encode(ISSUE);
29
+ if (path === "projects/acme%2Fweb/issues?iids[]=42&with_labels_details=true&per_page=1") {
30
+ return encode([
31
+ {
32
+ ...ISSUE,
33
+ labels: [
34
+ { name: "bug", color: "#E24329", description: "Something is broken" },
35
+ { name: " ", color: "#000000" },
36
+ ],
37
+ },
38
+ ]);
39
+ }
40
if (path.startsWith("projects/acme%2Fweb/issues/42/notes")) {
41
return encode([
42
{
@@ -175,7 +185,7 @@ describe("GitLabIssueTracker", () => {
185
],
186
author: { login: "octocat", name: "Octo Cat" },
187
assignees: [{ login: "theo" }],
178
- labels: [{ name: "bug", color: null }],
188
+ labels: [{ name: "bug", color: "#E24329", description: "Something is broken" }],
189
commentCount: 3,
190
viewer: "julius",
191
viewerPermissions: { setState: true, edit: true, labels: true, assignees: true },
@@ -309,7 +319,7 @@ describe("GitLabIssueTracker", () => {
319
cursor: "3",
320
});
321
expect(paths[0]).toBe(
312
- "projects/acme%2Fweb/issues?state=opened&assignee_username=julius&order_by=updated_at&sort=desc&per_page=1&page=3",
322
+ "projects/acme%2Fweb/issues?state=opened&assignee_username=julius&order_by=updated_at&sort=desc&with_labels_details=true&per_page=1&page=3",
323
);
324
// A named assignee takes the one parameter GitLab reads, so "assigned to me" drops rows here.
325
const both = yield* api.listIssues({
@@ -325,10 +335,12 @@ describe("GitLabIssueTracker", () => {
335
limit: 1,
336
});
337
expect(paths[1]).toBe(
328
- "projects/acme%2Fweb/issues?state=opened&labels=bug%2Cneeds%20triage&assignee_username=theo&order_by=created_at&sort=desc&per_page=1&page=1",
338
+ "projects/acme%2Fweb/issues?state=opened&labels=bug%2Cneeds%20triage&assignee_username=theo&order_by=created_at&sort=desc&with_labels_details=true&per_page=1&page=1",
339
);
340
expect(both.items).toEqual([]);
341
expect(page.items[0]?.key).toBe("42");
342
+ // A host that ignores with_labels_details still sends names, which keep their chips.
343
+ expect(page.items[0]?.labels).toEqual([{ name: "bug", color: null }]);
344
expect(page.nextCursor).toBe("4");
345
}),
346
);
packages/source-control-gitlab/src/server/GitLabIssueTracker.ts
+14
-4
@@ -22,7 +22,7 @@ import * as GitLabCli from "./GitLabCli.ts";
22
import {
23
decodeCreatedIssueJson,
24
decodeUserIdsJson,
25
- decodeIssueDetailJson,
25
+ decodeIssueDetailListJson,
26
decodeIssueListJson,
27
decodeIssueNotesJson,
28
decodeLabelEventsJson,
@@ -464,6 +464,7 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
464
: [["assignee_username", input.assignee] as const]),
465
["order_by", input.sort === "created" ? "created_at" : "updated_at"],
466
["sort", "desc"],
467
+ ["with_labels_details", "true"],
468
["per_page", String(perPage)],
469
["page", String(page)],
470
])}`,
@@ -490,9 +491,18 @@ export const make: Effect.Effect<IssueTrackerApi, never, GitLabCli.GitLabCli> =
491
cwd: input.cwd,
492
host: input.host,
493
operation: "getIssue",
493
- path,
494
- decode: decodeIssueDetailJson,
495
- }),
494
+ path: `projects/${projectPath(input.scope)}/issues?${query([
495
+ ["iids[]", String(number)],
496
+ ["with_labels_details", "true"],
497
+ ["per_page", "1"],
498
+ ])}`,
499
+ decode: decodeIssueDetailListJson,
500
+ }).pipe(
501
+ Effect.filterOrFail(
502
+ (issue) => issue !== null,
503
+ () => notFound("getIssue"),
504
+ ),
505
+ ),
506
viewer({ cwd: input.cwd, host: input.host, operation: "getIssue" }),
507
notesPage({
508
cwd: input.cwd,
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+58
@@ -495,6 +495,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
495
const path = argsOfCall(0)[1] ?? "";
496
expect(path).not.toContain("updated_before=");
497
expect(path).toContain("order_by=updated_at");
498
+ expect(path).toContain("with_labels_details=true");
499
expect(path).toContain("per_page=11");
500
expect(path).toContain("page=1");
501
}),
@@ -2333,6 +2334,63 @@ layer("GitLabPullRequestCli.layer", (it) => {
2334
}),
2335
);
2336
2337
+ it.effect("asks GraphQL for merge request label colours the single REST GET cannot return", () =>
2338
+ Effect.gen(function* () {
2339
+ const restLabels = ["bug", ...Array.from({ length: 100 }, (_, index) => `extra-${index}`)];
2340
+ const graphqlNodes = [
2341
+ { title: "bug", color: "#E24329", description: "Something is broken" },
2342
+ ...Array.from({ length: 99 }, (_, index) => ({
2343
+ title: `extra-${index}`,
2344
+ color: "#FFFFFF",
2345
+ })),
2346
+ ];
2347
+ mockedExecute.mockImplementation(({ args }) =>
2348
+ Effect.succeed(
2349
+ output(
2350
+ args[1] === "graphql"
2351
+ ? JSON.stringify({
2352
+ data: {
2353
+ project: {
2354
+ mergeRequest: {
2355
+ userPermissions: { adminMergeRequest: false },
2356
+ labels: { nodes: graphqlNodes },
2357
+ },
2358
+ },
2359
+ },
2360
+ })
2361
+ : mergeRequestJson({ labels: restLabels }),
2362
+ ),
2363
+ ),
2364
+ );
2365
+ const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
2366
+
2367
+ const detail = yield* cli.getMergeRequestDetail({
2368
+ cwd: "/w",
2369
+ repository: "acme/web",
2370
+ number: 7,
2371
+ downstreamChecks: false,
2372
+ maintainerEdits: false,
2373
+ });
2374
+
2375
+ const graphql = mockedExecute.mock.calls.find(([call]) => call.args[1] === "graphql");
2376
+ assert.isDefined(graphql);
2377
+ expect(JSON.parse(graphql[0].stdin ?? "").query).toContain(
2378
+ "labels(first: 100) { nodes { title color description } }",
2379
+ );
2380
+ expect(
2381
+ mockedExecute.mock.calls.some(([call]) => call.args[1]?.includes("with_labels_details")),
2382
+ ).toBe(false);
2383
+ expect(detail.labels).toHaveLength(101);
2384
+ expect(detail.labels[0]).toEqual({
2385
+ name: "bug",
2386
+ color: "#E24329",
2387
+ description: "Something is broken",
2388
+ });
2389
+ expect(detail.labels[1]).toEqual({ name: "extra-0", color: "#FFFFFF", description: null });
2390
+ expect(detail.labels.at(-1)).toEqual({ name: "extra-99", color: null });
2391
+ }),
2392
+ );
2393
+
2394
it.effect("skips a fork's maintainer edits permission read when the caller opts out", () =>
2395
Effect.gen(function* () {
2396
mockedExecute
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+30
-14
@@ -1002,6 +1002,16 @@ function query(params: ReadonlyArray<readonly [string, string]>): string {
1002
return params.map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join("&");
1003
}
1004
1005
+/** REST names every label; GraphQL's `labels(first: 100)` only colours the ones on its page. */
1006
+function colourLabels(
1007
+ rest: ReadonlyArray<PullRequestLabel>,
1008
+ graphql: ReadonlyArray<PullRequestLabel> | null,
1009
+): ReadonlyArray<PullRequestLabel> {
1010
+ if (graphql === null) return rest;
1011
+ const byName = new Map(graphql.map((label) => [label.name, label]));
1012
+ return rest.map((label) => byName.get(label.name) ?? label);
1013
+}
1014
+
1015
function actionArgs(
1016
action: PullRequestAction,
1017
mergeMethod: PullRequestMergeMethod | undefined,
@@ -1106,6 +1116,7 @@ export const make = Effect.gen(function* () {
1116
...filterParams(input),
1117
["order_by", "updated_at"],
1118
["sort", "desc"],
1119
+ ["with_labels_details", "true"],
1120
["per_page", String(perPage)],
1121
["page", String(input.page)],
1122
])}`,
@@ -2016,14 +2027,17 @@ export const make = Effect.gen(function* () {
2027
readonly repository: string;
2028
readonly number: number;
2029
}) =>
2019
- graphqlRead({
2020
- cwd: input.cwd,
2021
- host: input.host,
2022
- operation: "getLabelPermission",
2023
- query: LABEL_PERMISSION_GRAPHQL_QUERY,
2024
- variables: { fullPath: input.repository, iid: String(input.number) },
2025
- decode: decodeLabelPermissionJson,
2026
- }).pipe(Effect.catchIf(isOptionalReadFailure, () => Effect.succeed(false)));
2030
+ orWhenUnanswered(
2031
+ graphqlRead({
2032
+ cwd: input.cwd,
2033
+ host: input.host,
2034
+ operation: "getLabelPermission",
2035
+ query: LABEL_PERMISSION_GRAPHQL_QUERY,
2036
+ variables: { fullPath: input.repository, iid: String(input.number) },
2037
+ decode: decodeLabelPermissionJson,
2038
+ }),
2039
+ { viewerCanEditLabels: false, labels: null },
2040
+ );
2041
2042
const sourceBranch = (input: {
2043
readonly cwd: string;
@@ -2327,18 +2341,20 @@ export const make = Effect.gen(function* () {
2341
2342
getMergeRequestDetail: Effect.fn("GitLabPullRequestCli.getMergeRequestDetail")(
2343
function* (input) {
2330
- const [read, viewerCanEditLabels] = yield* Effect.all(
2344
+ const [read, extras] = yield* Effect.all(
2345
[mergeRequestDetail(input), labelPermission(input)],
2346
{ concurrency: 2 },
2347
);
2348
+ const labeled = { ...read, labels: colourLabels(read.labels, extras.labels) };
2349
+ const viewerCanEditLabels = extras.viewerCanEditLabels;
2350
// Only a closed or merged merge request offers its branch for deletion, and only an open
2351
// fork's has maintainer edits to change, so each extra read is skipped elsewhere.
2352
const detail =
2337
- read.state === "open"
2338
- ? input.maintainerEdits === false || read.maintainerCanModify === undefined
2339
- ? { ...read, viewerCanEditLabels }
2353
+ labeled.state === "open"
2354
+ ? input.maintainerEdits === false || labeled.maintainerCanModify === undefined
2355
+ ? { ...labeled, viewerCanEditLabels }
2356
: {
2341
- ...read,
2357
+ ...labeled,
2358
viewerCanEditLabels,
2359
viewerCanEditMaintainerEdits: yield* orWhenUnanswered(
2360
graphqlRead({
@@ -2353,7 +2369,7 @@ export const make = Effect.gen(function* () {
2369
),
2370
}
2371
: {
2356
- ...read,
2372
+ ...labeled,
2373
viewerCanEditLabels,
2374
viewerCanDeleteBranch: yield* orWhenUnanswered(
2375
sourceBranch(input).pipe(Effect.map((source) => source?.canDelete === true)),
packages/source-control-gitlab/src/server/gitLabIssueJson.ts
+30
-12
@@ -35,6 +35,16 @@ const RawUserSchema = Schema.Struct({
35
avatar_url: Schema.optional(Schema.NullOr(Schema.String)),
36
});
37
38
+/** `with_labels_details=true` returns label objects; hosts that ignore it still send names. */
39
+const RawLabelRefSchema = Schema.Union([
40
+ Schema.String,
41
+ Schema.Struct({
42
+ name: Schema.String,
43
+ color: Schema.optional(Schema.NullOr(Schema.String)),
44
+ description: Schema.optional(Schema.NullOr(Schema.String)),
45
+ }),
46
+]);
47
+
48
const RawIssueSchema = Schema.Struct({
49
iid: Schema.Int,
50
title: Schema.String,
@@ -46,7 +56,7 @@ const RawIssueSchema = Schema.Struct({
56
updated_at: Schema.String,
57
closed_at: Schema.optional(Schema.NullOr(Schema.String)),
58
assignees: Schema.optional(Schema.NullOr(Schema.Array(RawUserSchema))),
49
- labels: Schema.optional(Schema.NullOr(Schema.Array(Schema.String))),
59
+ labels: Schema.optional(Schema.NullOr(Schema.Array(RawLabelRefSchema))),
60
user_notes_count: Schema.optional(Schema.NullOr(Schema.Int)),
61
});
62
@@ -97,6 +107,7 @@ const RawTemplateSchema = Schema.Struct({ content: Schema.optional(Schema.NullOr
107
108
const decodeUnknownList = decodeJsonResult(Schema.Array(Schema.Unknown));
109
const decodeIssue = decodeJsonResult(RawIssueSchema);
110
+const decodeIssueList = decodeJsonResult(Schema.Array(RawIssueSchema));
111
const decodeIssueEntry = Schema.decodeUnknownExit(RawIssueSchema);
112
const decodeNoteEntry = Schema.decodeUnknownExit(RawNoteSchema);
113
const decodeLabelEventEntry = Schema.decodeUnknownExit(RawLabelEventSchema);
@@ -121,11 +132,18 @@ function toActor(raw: typeof RawUserSchema.Type | null | undefined): IssueActor
132
: { login, name: trimmed(raw?.name), avatarUrl: trimmed(raw?.avatar_url) };
133
}
134
124
-/** GitLab returns label names only on an issue, so there is no colour to carry. */
125
-function toLabels(raw: ReadonlyArray<string> | null | undefined): ReadonlyArray<IssueLabel> {
126
- return (raw ?? []).flatMap((label) => {
127
- const name = trimmed(label);
128
- return name === null ? [] : [{ name, color: null }];
135
+function toLabels(
136
+ raw: ReadonlyArray<typeof RawLabelRefSchema.Type> | null | undefined,
137
+): ReadonlyArray<IssueLabel> {
138
+ return (raw ?? []).flatMap((label): ReadonlyArray<IssueLabel> => {
139
+ if (typeof label === "string") {
140
+ const name = trimmed(label);
141
+ return name === null ? [] : [{ name, color: null }];
142
+ }
143
+ const name = trimmed(label.name);
144
+ return name === null
145
+ ? []
146
+ : [{ name, color: trimmed(label.color), description: trimmed(label.description) }];
147
});
148
}
149
@@ -173,13 +191,13 @@ interface GitLabIssueDetail extends TrackerIssueSummary {
191
readonly body: string;
192
}
193
176
-export function decodeIssueDetailJson(
194
+/** GitLab's GET /issues/:iid ignores `with_labels_details`, so the detail is read as an `iids[]` list. */
195
+export function decodeIssueDetailListJson(
196
raw: string,
178
-): Result.Result<GitLabIssueDetail, DecodeFailure> {
179
- return Result.map(decodeIssue(raw), (issue) => ({
180
- ...toSummary(issue),
181
- body: issue.description ?? "",
182
- }));
197
+): Result.Result<GitLabIssueDetail | null, DecodeFailure> {
198
+ return Result.map(decodeIssueList(raw), ([issue]) =>
199
+ issue === undefined ? null : { ...toSummary(issue), body: issue.description ?? "" },
200
+ );
201
}
202
203
/** The ids of the users a `/users?username=` lookup answered with: one, or none. */
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts
+13
-3
@@ -70,11 +70,18 @@ describe("decodeMergeRequestListJson", () => {
70
reviewers: [{ username: "julius" }],
71
labels: ["backend", " "],
72
},
73
+ {
74
+ iid: 43,
75
+ labels: [
76
+ { name: "bug", color: "#E24329", description: "Something is broken" },
77
+ { name: " ", color: "#000000" },
78
+ ],
79
+ },
80
]),
81
),
82
);
83
77
- expect(batch.items).toHaveLength(1);
84
+ expect(batch.items).toHaveLength(2);
85
expect(batch.items[0]).toMatchObject({
86
number: 42,
87
author: { login: "bilal", name: "Bilal" },
@@ -86,6 +93,9 @@ describe("decodeMergeRequestListJson", () => {
93
reviewRequestLogins: ["julius"],
94
labels: [{ name: "backend", color: null }],
95
});
96
+ expect(batch.items[1]?.labels).toEqual([
97
+ { name: "bug", color: "#E24329", description: "Something is broken" },
98
+ ]);
99
});
100
101
it("treats a merged timestamp as merged whatever the state says", () => {
@@ -1188,7 +1198,7 @@ describe("decodeMergeRequestGraphqlListJson", () => {
1198
conflicts: true,
1199
mergeStatusEnum: "CHECKING",
1200
author: { username: "bilal", name: "Bilal", avatarUrl: null },
1191
- labels: { nodes: [{ title: "bug" }] },
1201
+ labels: { nodes: [{ title: "bug", color: "#E24329", description: null }] },
1202
approved: false,
1203
approvedBy: { nodes: [] },
1204
reviewers: {
@@ -1217,7 +1227,7 @@ describe("decodeMergeRequestGraphqlListJson", () => {
1227
isDraft: true,
1228
mergeability: "conflicting",
1229
reviewRequestLogins: ["julius"],
1220
- labels: [expect.objectContaining({ name: "bug" })],
1230
+ labels: [{ name: "bug", color: "#E24329", description: null }],
1231
}),
1232
]);
1233
expect([...page.states]).toEqual([
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+89
-15
@@ -61,6 +61,16 @@ const RawMergeRequestDiffRefs = Schema.Struct({
61
start_sha: Schema.NullOr(Schema.String),
62
});
63
64
+/** `with_labels_details=true` returns label objects; hosts that ignore it still send names. */
65
+const RawLabelRefSchema = Schema.Union([
66
+ Schema.String,
67
+ Schema.Struct({
68
+ name: Schema.String,
69
+ color: Schema.optional(Schema.NullOr(Schema.String)),
70
+ description: Schema.optional(Schema.NullOr(Schema.String)),
71
+ }),
72
+]);
73
+
74
const RawMergeRequestSchema = Schema.Struct({
75
iid: Schema.Int,
76
title: Schema.String,
@@ -81,7 +91,7 @@ const RawMergeRequestSchema = Schema.Struct({
91
merged_at: Schema.optional(Schema.NullOr(Schema.String)),
92
closed_at: Schema.optional(Schema.NullOr(Schema.String)),
93
reviewers: Schema.optional(Schema.NullOr(Schema.Array(RawUserSchema))),
84
- labels: Schema.optional(Schema.NullOr(Schema.Array(Schema.String))),
94
+ labels: Schema.optional(Schema.NullOr(Schema.Array(RawLabelRefSchema))),
95
// GitLab reports "1000+" past its counting limit.
96
changes_count: Schema.optional(Schema.NullOr(Schema.String)),
97
head_pipeline: Schema.optional(Schema.NullOr(RawPipelineSchema)),
@@ -282,10 +292,18 @@ function toMergeability(
292
}
293
}
294
285
-function toLabels(raw: ReadonlyArray<string> | null | undefined): ReadonlyArray<PullRequestLabel> {
286
- return (raw ?? []).flatMap((label) => {
287
- const name = trimmed(label);
288
- return name === null ? [] : [{ name, color: null }];
295
+function toLabels(
296
+ raw: ReadonlyArray<typeof RawLabelRefSchema.Type> | null | undefined,
297
+): ReadonlyArray<PullRequestLabel> {
298
+ return (raw ?? []).flatMap((label): ReadonlyArray<PullRequestLabel> => {
299
+ if (typeof label === "string") {
300
+ const name = trimmed(label);
301
+ return name === null ? [] : [{ name, color: null }];
302
+ }
303
+ const name = trimmed(label.name);
304
+ return name === null
305
+ ? []
306
+ : [{ name, color: trimmed(label.color), description: trimmed(label.description) }];
307
});
308
}
309
@@ -1707,7 +1725,7 @@ export function decodeListStatesJson(
1725
/** The fields a listed merge request needs, so one GraphQL read stands in for REST and states. */
1726
export const LIST_ITEM_GRAPHQL_FIELDS = `${LIST_STATE_GRAPHQL_FIELDS}
1727
title webUrl state draft createdAt updatedAt mergedAt sourceBranch targetBranch
1710
- conflicts mergeStatusEnum author { username name avatarUrl } labels(first: 100) { nodes { title } }`;
1728
+ conflicts mergeStatusEnum author { username name avatarUrl } labels(first: 100) { nodes { title color description } }`;
1729
1730
const RawGraphqlListNodeSchema = Schema.Struct({
1731
...RawListStateFields,
@@ -1735,7 +1753,17 @@ const RawGraphqlListNodeSchema = Schema.Struct({
1753
Schema.NullOr(
1754
Schema.Struct({
1755
nodes: Schema.optional(
1738
- Schema.NullOr(Schema.Array(Schema.NullOr(Schema.Struct({ title: Schema.String })))),
1756
+ Schema.NullOr(
1757
+ Schema.Array(
1758
+ Schema.NullOr(
1759
+ Schema.Struct({
1760
+ title: Schema.String,
1761
+ color: Schema.optional(Schema.NullOr(Schema.String)),
1762
+ description: Schema.optional(Schema.NullOr(Schema.String)),
1763
+ }),
1764
+ ),
1765
+ ),
1766
+ ),
1767
),
1768
}),
1769
),
@@ -1816,7 +1844,11 @@ export function decodeMergeRequestGraphqlListJson(
1844
const login = trimmed(reviewer?.username);
1845
return login === null ? [] : [login];
1846
}),
1819
- labels: toLabels((node.labels?.nodes ?? []).flatMap((label) => (label ? [label.title] : []))),
1847
+ labels: toLabels(
1848
+ (node.labels?.nodes ?? []).flatMap((label) =>
1849
+ label ? [{ name: label.title, color: label.color, description: label.description }] : [],
1850
+ ),
1851
+ ),
1852
});
1853
states.set(number, toListState(node, enterprise));
1854
}
@@ -1940,11 +1972,15 @@ export function decodeMergeRequestStatsJson(
1972
return Result.succeed(stats);
1973
}
1974
1943
-/** GitLab lets whoever may change a merge request's metadata set its labels. */
1975
+/**
1976
+ * GitLab lets whoever may change a merge request's metadata set its labels. The labels ride along
1977
+ * because GET /merge_requests/:iid ignores `with_labels_details` and so carries no colours.
1978
+ */
1979
export const LABEL_PERMISSION_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
1980
project(fullPath: $fullPath) {
1981
mergeRequest(iid: $iid) {
1982
userPermissions { adminMergeRequest }
1983
+ labels(first: 100) { nodes { title color description } }
1984
}
1985
}
1986
}`;
@@ -1957,6 +1993,25 @@ const decodeLabelPermission = decodeJsonResult(
1993
mergeRequest: Schema.NullOr(
1994
Schema.Struct({
1995
userPermissions: Schema.Struct({ adminMergeRequest: Schema.Boolean }),
1996
+ labels: Schema.optional(
1997
+ Schema.NullOr(
1998
+ Schema.Struct({
1999
+ nodes: Schema.optional(
2000
+ Schema.NullOr(
2001
+ Schema.Array(
2002
+ Schema.NullOr(
2003
+ Schema.Struct({
2004
+ title: Schema.String,
2005
+ color: Schema.optional(Schema.NullOr(Schema.String)),
2006
+ description: Schema.optional(Schema.NullOr(Schema.String)),
2007
+ }),
2008
+ ),
2009
+ ),
2010
+ ),
2011
+ ),
2012
+ }),
2013
+ ),
2014
+ ),
2015
}),
2016
),
2017
}),
@@ -1965,13 +2020,32 @@ const decodeLabelPermission = decodeJsonResult(
2020
}),
2021
);
2022
1968
-export function decodeLabelPermissionJson(raw: string): Result.Result<boolean, DecodeFailure> {
2023
+export interface GitLabLabelPermission {
2024
+ readonly viewerCanEditLabels: boolean;
2025
+ readonly labels: ReadonlyArray<PullRequestLabel> | null;
2026
+}
2027
+
2028
+export function decodeLabelPermissionJson(
2029
+ raw: string,
2030
+): Result.Result<GitLabLabelPermission, DecodeFailure> {
2031
const decoded = decodeLabelPermission(raw);
1970
- return Result.isSuccess(decoded)
1971
- ? Result.succeed(
1972
- decoded.success.data.project?.mergeRequest?.userPermissions.adminMergeRequest === true,
1973
- )
1974
- : Result.fail(decoded.failure);
2032
+ if (!Result.isSuccess(decoded)) {
2033
+ return Result.fail(decoded.failure);
2034
+ }
2035
+ const mergeRequest = decoded.success.data.project?.mergeRequest;
2036
+ return Result.succeed({
2037
+ viewerCanEditLabels: mergeRequest?.userPermissions.adminMergeRequest === true,
2038
+ labels:
2039
+ mergeRequest?.labels == null
2040
+ ? null
2041
+ : toLabels(
2042
+ (mergeRequest.labels.nodes ?? []).flatMap((label) =>
2043
+ label
2044
+ ? [{ name: label.title, color: label.color, description: label.description }]
2045
+ : [],
2046
+ ),
2047
+ ),
2048
+ });
2049
}
2050
2051
/**