Skip to content

PR Approvals Workflow: Fetch Multiple Pages #223

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

Merged
merged 1 commit into from
Dec 11, 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
40 changes: 33 additions & 7 deletions .github/workflows/pr_approval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,42 @@ jobs:
return;
}

// Get all reviews
const reviews = await github.rest.pulls.listReviews({
owner,
repo,
pull_number
});
// Get all reviews with pagination
async function getAllReviews() {
let allReviews = [];
let page = 1;
let page_limit = 100;

while (page < page_limit) {
const response = await github.rest.pulls.listReviews({
owner,
repo,
pull_number,
per_page: 100,
page
});

allReviews = allReviews.concat(response.data);

if (response.data.length < 100) {
break;
}

page++;
}

if (page == page_limit) {
console.log(`WARNING: Reached page limit of ${page_limit} while fetching reviews data; approvals count may be less than the real total.`)
}

return allReviews;
}

const reviews = await getAllReviews();

// Example: approvers = ["celina", "zyad"]
const approvers = new Set(
reviews.data
reviews
.filter(review => review.state === 'APPROVED')
.map(review => review.user.login)
);
Expand Down
Loading