From 248cda557cb1ad085fd18b09ff114df3330d481f Mon Sep 17 00:00:00 2001 From: Michal Dorner Date: Tue, 11 Oct 2022 23:48:07 +0200 Subject: [PATCH] Use Octokit pagination --- src/main.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main.ts b/src/main.ts index d2cb678..457765f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import * as fs from 'fs' import * as core from '@actions/core' import * as github from '@actions/github' +import type {Octokit} from '@octokit/rest' import {Webhooks} from '@octokit/webhooks' import {Filter, FilterResults} from './filter' @@ -166,25 +167,19 @@ async function getChangedFilesFromApi( const per_page = 100 const files: File[] = [] - for (let page = 1; ; page++) { - core.info(`Invoking listFiles(pull_number: ${prNumber.number}, page: ${page}, per_page: ${per_page})`) - const response = await client.pulls.listFiles({ + core.info(`Invoking listFiles(pull_number: ${prNumber.number}, per_page: ${per_page})`) + for await (const response of client.paginate.iterator( + client.pulls.listFiles.endpoint.merge({ owner: github.context.repo.owner, repo: github.context.repo.repo, pull_number: prNumber.number, - per_page, - page + per_page }) - + ) as AsyncIterableIterator>) { if (response.status !== 200) { throw new Error(`Fetching list of changed files from GitHub API failed with error code ${response.status}`) } - core.info(`Received ${response.data.length} items`) - if (response.data.length === 0) { - core.info('All changed files has been fetched from GitHub API') - break - } for (const row of response.data) { core.info(`[${row.status}] ${row.filename}`)