From 1784e08e1e71366f8f74ce5996b20d3ddd742a04 Mon Sep 17 00:00:00 2001 From: Javyer Date: Mon, 17 Apr 2023 14:26:12 +0200 Subject: [PATCH] made reviews request synchronous (#5) If we fetch too many PRs (read 50+) and then we call the `Promise.all` method, we will be calling 50+ requests at once. This will save the problem of too many api calls generating a rejection (`API rate limit exceeded for installation ID`). --- src/githubApi.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/githubApi.ts b/src/githubApi.ts index 4b67467..a24440e 100644 --- a/src/githubApi.ts +++ b/src/githubApi.ts @@ -6,11 +6,12 @@ export const getPullRequestWithReviews = async (octokitInstance: github.GitHubIn const prs = await github.getPullRequests({ state: "open", ...repo }, { octokitInstance }); debug(`Found a total of ${prs.length} PRs`); - const reviews = await Promise.all(prs.map(async (pr) => { + let reviews: PullRequest[] = []; + for (const pr of prs) { debug(`Fetching reviews for PR #${pr.number}`); const { data } = await octokitInstance.rest.pulls.listReviews({ pull_number: pr.number, ...repo }); - return { ...pr, reviews: data }; - })) + reviews.push({ ...pr, reviews: data }); + } const sortedPrs = reviews.sort((a, b) => { return b.updated_at > a.updated_at ? -1 : b.updated_at < a.updated_at ? 1 : 0 }); return sortedPrs;