Skip to content

Commit

Permalink
[CI]: support pagination when fetching the files changed in the PR (u…
Browse files Browse the repository at this point in the history
  • Loading branch information
rscohn2 authored and normallytangent committed Aug 6, 2024
1 parent 5322614 commit dc24972
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions .github/scripts/domain-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit dc24972

Please sign in to comment.