|
| 1 | +/** |
| 2 | + * Proves that octokit.paginate() is actually walking Link-header pages for the |
| 3 | + * endpoints the action cares about, not just reading page 1. Without this, |
| 4 | + * PRs with >30 comments or >100 commits would silently drop data. |
| 5 | + * |
| 6 | + * The fake now honors ?page / ?per_page query params and emits a |
| 7 | + * `Link: <...>; rel="next"` header when more pages remain; octokit.paginate |
| 8 | + * follows the Link header to fetch all pages. |
| 9 | + */ |
| 10 | +import { installFakeGitHub, FakeGitHub } from '../testHelpers/fakeGithub' |
| 11 | +import { resetEnv, setDefaultInputs } from '../testHelpers/env' |
| 12 | +import { reloadOctokit, setContext } from '../testHelpers/context' |
| 13 | + |
| 14 | +function loadSignatureComment() { |
| 15 | + reloadOctokit() |
| 16 | + for (const path of Object.keys(require.cache)) { |
| 17 | + if (path.includes('/src/')) delete require.cache[path] |
| 18 | + } |
| 19 | + return require('../../src/pullrequest/signatureComment') |
| 20 | + .default as typeof import('../../src/pullrequest/signatureComment').default |
| 21 | +} |
| 22 | + |
| 23 | +describe('pagination', () => { |
| 24 | + let fake: FakeGitHub |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + setDefaultInputs() |
| 28 | + fake = installFakeGitHub() |
| 29 | + setContext({ |
| 30 | + issueNumber: 7, |
| 31 | + payload: { repository: { id: 5555 } } |
| 32 | + }) |
| 33 | + }) |
| 34 | + |
| 35 | + afterEach(async () => { |
| 36 | + await fake.close() |
| 37 | + resetEnv() |
| 38 | + }) |
| 39 | + |
| 40 | + it('signatureComment listComments walks every page', async () => { |
| 41 | + // Add 150 dummy comments (spans 2 pages at per_page=100). |
| 42 | + for (let i = 0; i < 150; i++) { |
| 43 | + fake.repo('acme', 'widgets').addComment(7, { |
| 44 | + body: 'noise', |
| 45 | + user: { login: `user${i}`, id: 10000 + i } |
| 46 | + }) |
| 47 | + } |
| 48 | + // Insert the sign phrase at index 140 — unreachable without pagination. |
| 49 | + fake.repo('acme', 'widgets').addComment(7, { |
| 50 | + body: 'i have read the cla document and i hereby sign the cla', |
| 51 | + user: { login: 'alice', id: 1001 } |
| 52 | + }) |
| 53 | + |
| 54 | + const signatureWithPRComment = loadSignatureComment() |
| 55 | + const result = await signatureWithPRComment( |
| 56 | + { |
| 57 | + signed: [], |
| 58 | + notSigned: [{ name: 'alice', id: 1001, pullRequestNo: 7 }], |
| 59 | + unknown: [] |
| 60 | + }, |
| 61 | + [{ name: 'alice', id: 1001, pullRequestNo: 7 }] |
| 62 | + ) |
| 63 | + // alice's signing comment lives on page 2. If pagination were broken, |
| 64 | + // newSigned would be empty. |
| 65 | + expect(result.newSigned.map((c: { name: string }) => c.name)).toEqual(['alice']) |
| 66 | + }) |
| 67 | + |
| 68 | + it('fake emits rel="next" only when there are more pages', async () => { |
| 69 | + for (let i = 0; i < 50; i++) { |
| 70 | + fake.repo('acme', 'widgets').addComment(7, { |
| 71 | + body: `c${i}`, |
| 72 | + user: { login: `u${i}`, id: i } |
| 73 | + }) |
| 74 | + } |
| 75 | + const all = fake.repo('acme', 'widgets').listComments(7) |
| 76 | + expect(all).toHaveLength(50) |
| 77 | + }) |
| 78 | +}) |
0 commit comments