fix: paginate GitHub issue-comment lookup to avoid duplicate comments#7
Conversation
findExistingComment fetched only the first 100 issue comments, so on a PR with >100 comments the existing Polder Drift comment could be missed and a duplicate posted on the next run. Walk every page of listComments (per_page: 100, incrementing page) until a short page, capped at MAX_COMMENT_PAGES so a misbehaving API can't loop forever. Octokit throws on a non-2xx response, so a transient list error propagates rather than masquerading as "no existing comment" — matching the AzDO findExistingComment behavior fixed in #6. Adds GitHub pagination tests mirroring the AzDO fetch-stub tests, and rebuilds dist/ since the action runs from the bundle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
📝 WalkthroughWalkthrough
ChangesPaginated comment lookup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/platforms.test.ts (1)
166-234: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick winAdd an explicit max-page guard test.
The suite validates later-page discovery, short-page stop, and failure propagation, but it doesn’t assert termination at the hard cap when every page is “full” and marker-free.
As per coding guidelines,
tests/**/*.ts: “Vitest. Prefer behaviour + edge cases over smoke tests.”Suggested test case
+ it('stops at the max page cap when all scanned pages are full and marker is absent', async () => { + const pages = Array.from({ length: 50 }, (_, i) => fullPage(i * 100 + 1)); + const { platform, listComments, updateComment, createComment } = platformWith(pages); + + await expect(platform.upsertComment('body', '<!--polder-drift-->', false)).resolves.toBe(false); + + expect(listComments).toHaveBeenCalledTimes(50); + expect(updateComment).not.toHaveBeenCalled(); + expect(createComment).not.toHaveBeenCalled(); + });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/platforms.test.ts` around lines 166 - 234, Add a new test case within the 'GitHubPlatform.findExistingComment pagination' describe block that validates the max-page termination guard. Create a scenario using platformWith() where you provide multiple full pages (using the fullPage() helper) that all lack the marker comment, ensuring each page returns exactly 100 comments to trigger pagination. Then verify that the listComments spy is called a specific maximum number of times and that the pagination stops rather than continuing infinitely, protecting against unbounded iteration when a marker is never found. This edge case ensures the findExistingComment method respects a configured maximum page limit during its search loop.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/platforms.test.ts`:
- Around line 166-234: Add a new test case within the
'GitHubPlatform.findExistingComment pagination' describe block that validates
the max-page termination guard. Create a scenario using platformWith() where you
provide multiple full pages (using the fullPage() helper) that all lack the
marker comment, ensuring each page returns exactly 100 comments to trigger
pagination. Then verify that the listComments spy is called a specific maximum
number of times and that the pagination stops rather than continuing infinitely,
protecting against unbounded iteration when a marker is never found. This edge
case ensures the findExistingComment method respects a configured maximum page
limit during its search loop.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 288734ba-8845-48c3-bfb4-890c0035ce9e
⛔ Files ignored due to path filters (1)
dist/index.jsis excluded by!**/dist/**,!dist/**
📒 Files selected for processing (2)
src/platforms/github.tstests/platforms.test.ts
What
GitHubPlatform.findExistingComment(src/platforms/github.ts) fetched only the first 100 issue comments viaoctokit.rest.issues.listCommentswith no pagination. On a PR that accumulates more than 100 issue comments, the existing Polder Drift comment (identified by the marker) could be missed, causing a duplicate comment to be posted on the next run.This is the GitHub parallel of the bug class fixed for Azure DevOps in #6 (
AzdoPlatform.findExistingComment, which paginates via thex-ms-continuationtokenheader).How
listComments(per_page: 100, incrementingpage) until a page comes back short, capped atMAX_COMMENT_PAGES = 50so a misbehaving API can't loop forever — same loop-guard shape as AzDO'sMAX_THREAD_PAGES.Tests
Added a
GitHubPlatform.findExistingComment paginationblock in tests/platforms.test.ts, mirroring the AzDO fetch-stub tests (here stubbing octokit + the Action context):npm run typecheckclean;npx vitest rungreen (201 tests). Rebuilt the bundle withnpm run build:allsince the action runs fromdist/.Context
CodeRabbit flagged this as a non-blocking nitpick on #6 ("GitHub comment lookup lacks pagination, risking duplicates on busy PRs"); it was left out of #6 to keep that PR scoped to error-surfacing.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests