Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI]: support pagination when fetching the files changed in the PR #540

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading