From a83d52b1a43e619989ba05a1e2dcdcee0f7541c3 Mon Sep 17 00:00:00 2001 From: Carolyn Zech Date: Tue, 10 Dec 2024 20:31:00 -0500 Subject: [PATCH] fetch multiple pages of reviews --- .github/workflows/pr_approval.yml | 40 +++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr_approval.yml b/.github/workflows/pr_approval.yml index 3094f4b6baf66..70089fed5ec3f 100644 --- a/.github/workflows/pr_approval.yml +++ b/.github/workflows/pr_approval.yml @@ -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) );