Skip to content

Commit 191dfb9

Browse files
committed
fix: limit fetchTopUsersByPullRequest to 300 PR:s only
1 parent 9db17aa commit 191dfb9

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

utils/fetchTopUsersByPullRequests.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ type UserStat = {
99
export const fetchTopUsersByPullRequests = async (
1010
repo: string
1111
): Promise<UserStat[]> => {
12-
let url = `https://api.github.com/repos/${repo}/pulls?state=closed&per_page=100`;
13-
const userStats: { [key: string]: { prCount: number; avatarUrl: string } } =
14-
{};
12+
//* Limit to first 300 PRs only
13+
let url = `https://api.github.com/repos/${repo}/pulls?state=closed&per_page=100&page=1`;
14+
const userStats: { [key: string]: { prCount: number; avatarUrl: string } } = {};
15+
let pageCount = 0;
16+
const MAX_PAGES = 3;
1517

16-
while (url) {
17-
const response = await axios.get(url);
18+
while (url && pageCount < MAX_PAGES) {
19+
const response = await axios.get(url, {
20+
timeout: 5000,
21+
headers: {
22+
Authorization: `token ${process.env.GITHUB_TOKEN}`,
23+
}
24+
});
25+
pageCount++;
1826
const prData = response.data;
1927
prData.forEach((pr: any) => {
2028
if (pr.merged_at) {
@@ -55,3 +63,4 @@ export const fetchTopUsersByPullRequests = async (
5563

5664
return sortedUsers;
5765
};
66+

0 commit comments

Comments
 (0)