Skip to content

Commit 6f780be

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): list cursors keep their API, and reviewing lists keep changes requested
A cursor now picks the API that handed it out, so a failed version check can no longer send a GraphQL cursor to REST as an offset. Reviewing lists leave reviewStates out, because beside reviewerUsername GitLab matches it on that reviewer alone and would drop merge requests where someone else requested changes. The row filter still narrows them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 242bff6 commit 6f780be

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
295295
"lists through GraphQL with the filters GitLab narrows there, declaring only those",
296296
() =>
297297
Effect.gen(function* () {
298-
mockedExecute.mockReturnValueOnce(
298+
mockedExecute.mockReturnValue(
299299
Effect.succeed(output(graphqlListPage([1], { hasNextPage: false, endCursor: null }))),
300300
);
301301
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
@@ -304,7 +304,7 @@ layer("GitLabPullRequestCli.layer", (it) => {
304304
cwd: "/w",
305305
repository: "acme/web",
306306
state: "open",
307-
involvement: "reviewing",
307+
involvement: "all",
308308
viewer: "bilal",
309309
limit: 10,
310310
query: " page ",
@@ -330,7 +330,6 @@ layer("GitLabPullRequestCli.layer", (it) => {
330330
after: "eyJpZCI6IjEifQ",
331331
state: "opened",
332332
authorUsername: "octocat",
333-
reviewerUsername: "bilal",
334333
search: "page",
335334
labels: ["bug"],
336335
draft: false,
@@ -340,6 +339,20 @@ layer("GitLabPullRequestCli.layer", (it) => {
340339
expect(query).toContain("reviewStates: $reviewStates");
341340
expect(query).toContain("not: { labels: $notLabels }");
342341
expect(query).not.toContain("$approvedBy");
342+
343+
// Beside a reviewer, GitLab would match only that reviewer's own state.
344+
yield* cli.listMergeRequests({
345+
cwd: "/w",
346+
repository: "acme/web",
347+
state: "open",
348+
involvement: "reviewing",
349+
viewer: "bilal",
350+
limit: 10,
351+
graphql: true,
352+
filters: { review: "changes-requested" },
353+
});
354+
expect(graphqlRequestOf(1).variables).toMatchObject({ reviewerUsername: "bilal" });
355+
expect(graphqlRequestOf(1).variables).not.toHaveProperty("reviewStates");
343356
}),
344357
);
345358

@@ -395,13 +408,14 @@ layer("GitLabPullRequestCli.layer", (it) => {
395408
involvement: "all",
396409
viewer: "bilal",
397410
limit: 10,
398-
graphql: true,
411+
// A cursor, not the host's current answer, picks the API.
412+
graphql: cursor?.resumeAfter === undefined,
399413
...(cursor === undefined ? {} : { cursor }),
400414
});
401415

402416
yield* list({ updatedBefore: "2026-07-03T00:00:00Z", delivered: 10 });
403417
const fellBack = yield* list();
404-
// A resumed GraphQL read fails instead, since REST would read `delivered` as an offset.
418+
// A resumed GraphQL read stays on GraphQL and fails, since REST would read `delivered` as an offset.
405419
const resumed = yield* Effect.result(
406420
list({ updatedBefore: "2026-07-03T00:00:00Z", delivered: 10, resumeAfter: "c1" }),
407421
);

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ export class GitLabPullRequestCli extends Context.Service<
251251
readonly query?: string | undefined;
252252
readonly cursor?: ProviderListCursor | undefined;
253253
readonly filters?: PullRequestListFilters | undefined;
254-
/** Read through GraphQL, which narrows more filters; see `supportsGraphqlList`. */
254+
/**
255+
* Read a first page through GraphQL, which narrows more filters; see `supportsGraphqlList`.
256+
* A cursor keeps the API that handed it out.
257+
*/
255258
readonly graphql?: boolean;
256259
}) => Effect.Effect<GitLabMergeRequestListBatch, GitLabPullRequestCliError>;
257260

@@ -615,7 +618,8 @@ function graphqlListQuery(input: {
615618
? []
616619
: [["draft", "Boolean", filters.draft === "only"] as const]),
617620
...(filters.review === "approved" ? [["approvedBy", "[String!]", ["Any"]] as const] : []),
618-
...(filters.review === "changes-requested"
621+
// Beside `reviewerUsername`, GitLab matches review states on that reviewer alone.
622+
...(filters.review === "changes-requested" && input.involvement !== "reviewing"
619623
? [["reviewStates", "[MergeRequestReviewState!]", ["REQUESTED_CHANGES"]] as const]
620624
: []),
621625
];
@@ -1518,13 +1522,12 @@ export const make = Effect.gen(function* () {
15181522
const rest = Effect.suspend(() =>
15191523
listPage({ ...input, page, collected: [], cursorAdvance: 0 }),
15201524
);
1521-
// A cursor REST handed out holds only an offset, which GraphQL cannot resume from.
1522-
if (
1523-
input.graphql !== true ||
1524-
(input.cursor !== undefined && input.cursor.resumeAfter === undefined)
1525-
) {
1526-
return rest;
1527-
}
1525+
// A cursor's offset means something only to the API that handed it out.
1526+
const viaGraphql =
1527+
input.cursor === undefined
1528+
? input.graphql === true
1529+
: input.cursor.resumeAfter !== undefined;
1530+
if (!viaGraphql) return rest;
15281531
const graphql = graphqlListPage({
15291532
...input,
15301533
after: input.cursor?.resumeAfter,

0 commit comments

Comments
 (0)