@devries-cameron20 / t3code-1 / commits / 1d4765ba2a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(gitlab): remove reactions beyond the first award page (#30700)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Johan Vaz committed Nov 15, 2026 at 08:13 UTC 1d4765ba2a1eb5984852043c7dcbb1b94cc9f905
4 files changed +63 -40
packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+29 -19
@@ -1721,39 +1721,49 @@ layer("GitLabPullRequestCli.layer", (it) => {
1721 }),
1722 );
1723
1724 - it.effect("removes an award by listing them and deleting the reader's own id", () =>
1724 + it.effect("removes the reader's own award from a later page, and stops at an empty page", () =>
1725 Effect.gen(function* () {
1726 + const others = Array.from({ length: 100 }, (_, index) =>
1727 + index === 0 ? null : { id: index, name: "thumbsup", user: { username: "julius" } },
1728 + );
1729 + const page = (awards: ReadonlyArray<unknown>) =>
1730 + Effect.succeed(output(JSON.stringify(awards)));
1731 mockedExecute.mockReturnValueOnce(
1732 Effect.succeed(output(JSON.stringify({ username: "bilal" }))),
1733 );
1734 + mockedExecute.mockReturnValueOnce(page(others));
1735 mockedExecute.mockReturnValueOnce(
1730 - Effect.succeed(
1731 - output(
1732 - JSON.stringify([
1733 - { id: 5, name: "thumbsup", user: { username: "bilal" } },
1734 - { id: 6, name: "thumbsup", user: { username: "julius" } },
1735 - ]),
1736 - ),
1737 - ),
1736 + page([{ id: 500, name: "thumbsup", user: { username: "bilal" } }]),
1737 );
1738 mockedExecute.mockReturnValueOnce(Effect.succeed(output("{}")));
1739 + mockedExecute.mockReturnValueOnce(
1740 + Effect.succeed(output(JSON.stringify({ username: "bilal" }))),
1741 + );
1742 + mockedExecute.mockReturnValueOnce(page(others));
1743 + mockedExecute.mockReturnValueOnce(page([]));
1744 const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1741 -
1742 - yield* cli.setReaction({
1745 + const remove = {
1746 cwd: "/w",
1747 repository: "acme/web",
1748 number: 7,
1749 content: "thumbs-up",
1750 reacted: false,
1748 - });
1749 -
1750 - assert.strictEqual(mockedExecute.mock.calls.length, 3);
1751 - expect(argsOfCall(2)).toEqual([
1752 - "api",
1753 - "projects/acme%2Fweb/merge_requests/7/award_emoji/5",
1754 - "--method",
1755 - "DELETE",
1751 + } as const;
1752 +
1753 + yield* cli.setReaction(remove);
1754 + yield* cli.setReaction(remove);
1755 +
1756 + const awards = "projects/acme%2Fweb/merge_requests/7/award_emoji";
1757 + expect(mockedExecute.mock.calls.map((_, index) => argsOfCall(index)[1])).toEqual([
1758 + "user",
1759 + `${awards}?per_page=100&page=1`,
1760 + `${awards}?per_page=100&page=2`,
1761 + `${awards}/500`,
1762 + "user",
1763 + `${awards}?per_page=100&page=1`,
1764 + `${awards}?per_page=100&page=2`,
1765 ]);
1766 + expect(argsOfCall(3)).toContain("DELETE");
1767 }),
1768 );
1769
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+30 -17
@@ -2353,26 +2353,39 @@ export const make = Effect.gen(function* () {
2353 // GitLab deletes an award by its id and takes no emoji name there, so the reader's own
2354 // award of that name is looked up first.
2355 const viewer = yield* viewerUsername(input);
2356 - const listed = yield* api({ cwd: input.cwd, host: input.host, path: subject });
2357 - const own = decodeOwnAwardIdJson(listed.stdout.trim(), {
2358 - content: input.content,
2359 - viewer,
2360 - });
2361 - if (!Result.isSuccess(own)) {
2362 - return yield* new GitLabMergeRequestReadError({
2363 - command: "glab",
2356 + for (let page = 1; ; page++) {
2357 + const listed = yield* api({
2358 cwd: input.cwd,
2365 - operation: "setReaction",
2366 - cause: own.failure,
2359 + host: input.host,
2360 + path: `${subject}?${query([
2361 + ["per_page", String(MAX_PAGE_SIZE)],
2362 + ["page", String(page)],
2363 + ])}`,
2364 + });
2365 + const own = decodeOwnAwardIdJson(listed.stdout.trim(), {
2366 + content: input.content,
2367 + viewer,
2368 });
2369 + if (!Result.isSuccess(own)) {
2370 + return yield* new GitLabMergeRequestReadError({
2371 + command: "glab",
2372 + cwd: input.cwd,
2373 + operation: "setReaction",
2374 + cause: own.failure,
2375 + });
2376 + }
2377 + if (own.success.id !== null) {
2378 + yield* api({
2379 + cwd: input.cwd,
2380 + host: input.host,
2381 + path: `${subject}/${own.success.id}`,
2382 + method: "DELETE",
2383 + });
2384 + return;
2385 + }
2386 + // An empty raw page establishes exhaustion even when the host caps page size.
2387 + if (own.success.empty) return;
2388 }
2369 - if (own.success === null) return;
2370 - yield* api({
2371 - cwd: input.cwd,
2372 - host: input.host,
2373 - path: `${subject}/${own.success}`,
2374 - method: "DELETE",
2375 - });
2389 }),
2390
2391 listCommits: Effect.fn("GitLabPullRequestCli.listCommits")(function (input) {
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts
+1 -1
@@ -828,7 +828,7 @@ describe("decodeOwnAwardIdJson", () => {
828 it("finds the reader's own award of that name, which is the one a removal deletes", () => {
829 expect(
830 expectSuccess(decodeOwnAwardIdJson(awards, { content: "thumbs-up", viewer: "bilal" })),
831 - ).toBe(102);
831 + ).toEqual({ id: 102, empty: false });
832 });
833 });
834
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+3 -3
@@ -1293,7 +1293,7 @@ const decodeAward = Schema.decodeUnknownExit(RawAwardSchema);
1293 export function decodeOwnAwardIdJson(
1294 raw: string,
1295 input: { readonly content: PullRequestReactionContent; readonly viewer: string },
1296 -): Result.Result<number | null, DecodeFailure> {
1296 +): Result.Result<{ readonly id: number | null; readonly empty: boolean }, DecodeFailure> {
1297 const decoded = decodeUnknownList(raw);
1298 if (!Result.isSuccess(decoded)) {
1299 return Result.fail(decoded.failure);
@@ -1305,9 +1305,9 @@ export function decodeOwnAwardIdJson(
1305 const value = award.value;
1306 if (trimmed(value.name)?.toLowerCase() !== name) continue;
1307 if (trimmed(value.user?.username) !== input.viewer) continue;
1308 - return Result.succeed(value.id);
1308 + return Result.succeed({ id: value.id, empty: false });
1309 }
1310 - return Result.succeed(null);
1310 + return Result.succeed({ id: null, empty: decoded.success.length === 0 });
1311 }
1312
1313 export const REPOSITORY_BLOBS_GRAPHQL_QUERY = `query($fullPath: ID!, $ref: String!, $paths: [String!]!) {