From dc249724871820b23703f572131c3cbecca902eb Mon Sep 17 00:00:00 2001 From: Robert Cohn Date: Tue, 30 Jul 2024 05:11:51 -0400 Subject: [PATCH] [CI]: support pagination when fetching the files changed in the PR (#540) --- .github/scripts/domain-check.js | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/scripts/domain-check.js b/.github/scripts/domain-check.js index abf933f2f..ed68c2e42 100644 --- a/.github/scripts/domain-check.js +++ b/.github/scripts/domain-check.js @@ -24,13 +24,32 @@ function matchesPattern(domain, filePaths) { // Return the list of files modified in the pull request async function prFiles(github, context) { - const response = await github.rest.pulls.listFiles({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.payload.pull_request.number, - }); - const prFiles = response.data.map((file) => file.filename); - return prFiles; + let allFiles = []; + let page = 0; + let filesPerPage = 100; // GitHub's maximum per page + + while (true) { + page++; + const response = await github.rest.pulls.listFiles({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + per_page: filesPerPage, + page: page, + }); + + if (response.data.length === 0) { + break; // Exit the loop if no more files are returned + } + + allFiles = allFiles.concat(response.data.map((file) => file.filename)); + + if (response.data.length < filesPerPage) { + break; // Exit the loop if last page + } + } + + return allFiles; } // Called by pr.yml. See: