From ee02f28c874ec1d869d00be42473a4e5818bdab4 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Fri, 4 Dec 2026 10:09:36 +0800 Subject: [PATCH] Paginate GitHub comment reactions Read every page of issue comment reactions so feedback from a reporter beyond the first 100 reactions is visible to the poller. Cover later pages and the exact-page boundary. Co-Authored-By: Claude Code --- .../__tests__/github-client.test.ts | 58 +++++++++++++++++++ .../shared/src/integrations/github-client.ts | 41 ++++++++----- 2 files changed, 86 insertions(+), 13 deletions(-) diff --git a/packages/outpost/shared/src/integrations/__tests__/github-client.test.ts b/packages/outpost/shared/src/integrations/__tests__/github-client.test.ts index 82244e3..bce774e 100644 --- a/packages/outpost/shared/src/integrations/__tests__/github-client.test.ts +++ b/packages/outpost/shared/src/integrations/__tests__/github-client.test.ts @@ -26,6 +26,64 @@ describe('listCommentReactions', () => { repo: 'repo', comment_id: 12345, per_page: 100, + page: 1, + }); + }); + + it('follows pagination when the reporter reacted after the first 100 reactions', async () => { + const firstPage = Array.from({ length: 100 }, (_, index) => ({ + content: '+1', + user: { login: `user-${index}` }, + })); + const listForIssueComment = vi + .fn() + .mockResolvedValueOnce({ data: firstPage }) + .mockResolvedValueOnce({ + data: [{ content: '-1', user: { login: 'reporter-user' } }], + }); + const mockClient = { reactions: { listForIssueComment } }; + + const result = await listCommentReactions(mockClient as never, 'owner', 'repo', 12345); + + expect(result).toHaveLength(101); + expect(result.at(-1)).toEqual({ content: '-1', login: 'reporter-user' }); + expect(listForIssueComment).toHaveBeenNthCalledWith(1, { + owner: 'owner', + repo: 'repo', + comment_id: 12345, + per_page: 100, + page: 1, + }); + expect(listForIssueComment).toHaveBeenNthCalledWith(2, { + owner: 'owner', + repo: 'repo', + comment_id: 12345, + per_page: 100, + page: 2, + }); + }); + + it('requests another page when the previous page has exactly 100 reactions', async () => { + const firstPage = Array.from({ length: 100 }, (_, index) => ({ + content: '+1', + user: { login: `user-${index}` }, + })); + const listForIssueComment = vi + .fn() + .mockResolvedValueOnce({ data: firstPage }) + .mockResolvedValueOnce({ data: [] }); + const mockClient = { reactions: { listForIssueComment } }; + + const result = await listCommentReactions(mockClient as never, 'owner', 'repo', 12345); + + expect(result).toHaveLength(100); + expect(listForIssueComment).toHaveBeenCalledTimes(2); + expect(listForIssueComment).toHaveBeenNthCalledWith(2, { + owner: 'owner', + repo: 'repo', + comment_id: 12345, + per_page: 100, + page: 2, }); }); }); diff --git a/packages/outpost/shared/src/integrations/github-client.ts b/packages/outpost/shared/src/integrations/github-client.ts index 14c4721..b65d916 100644 --- a/packages/outpost/shared/src/integrations/github-client.ts +++ b/packages/outpost/shared/src/integrations/github-client.ts @@ -28,6 +28,7 @@ export interface GithubReactionClient { repo: string; comment_id: number; per_page?: number; + page?: number; }): Promise<{ data: Array<{ content: string; user: { login: string } | null }> }>; }; } @@ -49,10 +50,10 @@ export interface CommentReaction { } /** - * List reactions on a GitHub issue comment. Only works for issue comments - * (numeric REST comment IDs) — discussion-comment reactions are addressed - * by GraphQL node_ids, not numeric REST IDs, and require the GraphQL API, - * which is out of scope for this client. + * List every page of reactions on a GitHub issue comment. Only works for issue + * comments (numeric REST comment IDs) — discussion-comment reactions are addressed + * by GraphQL node_ids, not numeric REST IDs, and require the GraphQL API, which + * is out of scope for this client. */ export async function listCommentReactions( client: GithubReactionClient, @@ -60,16 +61,30 @@ export async function listCommentReactions( repo: string, commentId: number, ): Promise { - const response = await client.reactions.listForIssueComment({ - owner, - repo, - comment_id: commentId, - per_page: 100, - }); + const reactions: CommentReaction[] = []; + const perPage = 100; + let page = 1; - return response.data - .filter((r) => r.user !== null) - .map((r) => ({ content: r.content, login: r.user!.login })); + while (true) { + const response = await client.reactions.listForIssueComment({ + owner, + repo, + comment_id: commentId, + per_page: perPage, + page, + }); + + reactions.push( + ...response.data + .filter((r) => r.user !== null) + .map((r) => ({ content: r.content, login: r.user!.login })), + ); + + if (response.data.length < perPage) break; + page += 1; + } + + return reactions; } /**