Skip to content

Commit

Permalink
made reviews request synchronous (#5)
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
Bullrich authored Apr 17, 2023
1 parent 0d21577 commit 1784e08
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/githubApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1784e08

Please sign in to comment.