diff --git a/staging-auto-merge/dist/index.js b/staging-auto-merge/dist/index.js index 186f3f0..b16e4ae 100644 --- a/staging-auto-merge/dist/index.js +++ b/staging-auto-merge/dist/index.js @@ -23290,13 +23290,12 @@ class StagingAutoMerge { await this.exec("git push --force"); } async cleanupClosedPullRequests() { - const closedPullRequests = await this.octokit.rest.pulls.list({ + const closedPullRequests = await this.octokit.paginate(this.octokit.rest.pulls.list, { ...this.repo, state: "closed", - sort: "created", - direction: "desc" + per_page: 100 }); - for (const closedPr of closedPullRequests.data) { + for (const closedPr of closedPullRequests) { if (this.hasStagingLabel(closedPr.labels)) { this.logger.info("removing label from: ", closedPr.title); await this.removeStagingLabel(closedPr.number); diff --git a/staging-auto-merge/src/staging-auto-merge.js b/staging-auto-merge/src/staging-auto-merge.js index db01551..1529582 100644 --- a/staging-auto-merge/src/staging-auto-merge.js +++ b/staging-auto-merge/src/staging-auto-merge.js @@ -95,14 +95,13 @@ export default class StagingAutoMerge { } async cleanupClosedPullRequests() { - const closedPullRequests = await this.octokit.rest.pulls.list({ + const closedPullRequests = await this.octokit.paginate(this.octokit.rest.pulls.list, { ...this.repo, state: 'closed', - sort: 'created', - direction: 'desc', + per_page: 100, }) - for (const closedPr of closedPullRequests.data) { + for (const closedPr of closedPullRequests) { if (this.hasStagingLabel(closedPr.labels)) { this.logger.info('removing label from: ', closedPr.title) await this.removeStagingLabel(closedPr.number) diff --git a/staging-auto-merge/tests/staging-auto-merge.test.js b/staging-auto-merge/tests/staging-auto-merge.test.js index 5bb4a0a..f088dfe 100644 --- a/staging-auto-merge/tests/staging-auto-merge.test.js +++ b/staging-auto-merge/tests/staging-auto-merge.test.js @@ -1,6 +1,7 @@ import StagingAutoMerge from '../src/staging-auto-merge.js' const createOctokit = () => ({ + paginate: vi.fn(), rest: { issues: { listLabelsForRepo: vi.fn(), @@ -47,9 +48,8 @@ describe('StagingAutoMerge', () => { }, ] - octokit.rest.pulls.list.mockImplementation(({ state }) => - Promise.resolve({ data: state === 'open' ? openPulls : closedPulls }), - ) + octokit.rest.pulls.list.mockResolvedValue({ data: openPulls }) + octokit.paginate.mockResolvedValue(closedPulls) const stagingAutoMerge = new StagingAutoMerge(octokit, primaryBranch, repo, logger) const execMock = vi.fn().mockResolvedValue(undefined) @@ -64,6 +64,9 @@ describe('StagingAutoMerge', () => { ) expect(execMock).toHaveBeenCalledWith('git', ['commit', '-m', 'Add feature']) expect(octokit.rest.issues.createComment).not.toHaveBeenCalled() + expect(octokit.rest.issues.removeLabel).not.toHaveBeenCalledWith( + expect.objectContaining({ issue_number: 12 }), + ) expect(octokit.rest.issues.removeLabel).toHaveBeenCalledWith({ owner: 'rolemodel', repo: 'actions', @@ -82,9 +85,8 @@ describe('StagingAutoMerge', () => { }, ] - octokit.rest.pulls.list.mockImplementation(({ state }) => - Promise.resolve({ data: state === 'open' ? openPulls : [] }), - ) + octokit.rest.pulls.list.mockResolvedValue({ data: openPulls }) + octokit.paginate.mockResolvedValue([]) const stagingAutoMerge = new StagingAutoMerge(octokit, primaryBranch, repo, logger) const execMock = vi.fn(async (command, args, options) => {