Skip to content

Commit 3ef2625

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): a GraphQL list of a project the reader cannot see fails
GitLab answers project: null for a project the token cannot see. The list decoder read that as an empty page, where REST reports an error. It now fails the read, so a first page falls back to REST and surfaces that error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6f780be commit 3ef2625

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

‎packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,15 @@ describe("decodeMergeRequestGraphqlListJson", () => {
921921
]);
922922
expect(page).toMatchObject({ rawCount: 2, hasNextPage: true, endCursor: "eyJpZCI6IjcifQ" });
923923
});
924+
it("fails on a project the reader cannot see, rather than reading it as empty", () => {
925+
expect(
926+
Result.isFailure(
927+
decodeMergeRequestGraphqlListJson(
928+
JSON.stringify({ data: { metadata: { enterprise: true }, project: null } }),
929+
),
930+
),
931+
).toBe(true);
932+
});
924933
});
925934

926935
describe("decodeGraphqlListSupportJson", () => {

‎packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,24 +1187,19 @@ const RawGraphqlListNodeSchema = Schema.Struct({
11871187
),
11881188
});
11891189

1190+
// GitLab answers `project: null` for a project the reader cannot see, which REST reports as an error.
11901191
const RawGraphqlListSchema = Schema.Struct({
11911192
data: Schema.Struct({
11921193
metadata: RawMetadataSchema,
1193-
project: Schema.NullOr(
1194-
Schema.Struct({
1195-
mergeRequests: Schema.optional(
1196-
Schema.NullOr(
1197-
Schema.Struct({
1198-
pageInfo: Schema.Struct({
1199-
hasNextPage: Schema.Boolean,
1200-
endCursor: Schema.optional(Schema.NullOr(Schema.String)),
1201-
}),
1202-
nodes: Schema.Array(Schema.Unknown),
1203-
}),
1204-
),
1205-
),
1194+
project: Schema.Struct({
1195+
mergeRequests: Schema.Struct({
1196+
pageInfo: Schema.Struct({
1197+
hasNextPage: Schema.Boolean,
1198+
endCursor: Schema.optional(Schema.NullOr(Schema.String)),
1199+
}),
1200+
nodes: Schema.Array(Schema.Unknown),
12061201
}),
1207-
),
1202+
}),
12081203
}),
12091204
});
12101205

@@ -1227,11 +1222,11 @@ export function decodeMergeRequestGraphqlListJson(
12271222
if (!Result.isSuccess(decoded)) {
12281223
return Result.fail(decoded.failure);
12291224
}
1230-
const page = decoded.success.data.project?.mergeRequests;
1225+
const page = decoded.success.data.project.mergeRequests;
12311226
const enterprise = decoded.success.data.metadata?.enterprise;
12321227
const items: GitLabMergeRequestListItem[] = [];
12331228
const states = new Map<number, GitLabMergeRequestListState>();
1234-
for (const entry of page?.nodes ?? []) {
1229+
for (const entry of page.nodes) {
12351230
const exit = decodeGraphqlListNode(entry);
12361231
if (!Exit.isSuccess(exit)) continue;
12371232
const node = exit.value;
@@ -1273,9 +1268,9 @@ export function decodeMergeRequestGraphqlListJson(
12731268
return Result.succeed({
12741269
items,
12751270
states,
1276-
rawCount: page?.nodes.length ?? 0,
1277-
hasNextPage: page?.pageInfo.hasNextPage ?? false,
1278-
endCursor: trimmed(page?.pageInfo.endCursor),
1271+
rawCount: page.nodes.length,
1272+
hasNextPage: page.pageInfo.hasNextPage,
1273+
endCursor: trimmed(page.pageInfo.endCursor),
12791274
});
12801275
}
12811276

0 commit comments

Comments
 (0)