Skip to content

Commit 2de02c4

Browse files
committed
fix(api): add request limit to topThreeContributors to prevent infinite loops
1 parent 3cdfe79 commit 2de02c4

4 files changed

Lines changed: 10 additions & 28 deletions

File tree

components/index/TopThreeContributors.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,3 @@ const TopThreeContributors: FC = () => {
136136
}
137137

138138
export { TopThreeContributors }
139-
140-
141-
142-
143-
144-
145-
146-
147-

pages/api/topThreeUsers.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,3 @@ export default async (req, res) => {
5050
res.status(500).json({ error: 'Internal Server Error' });
5151
}
5252
};
53-
54-

utils/fetchTopThreeUsersByPullRequests.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
1010

1111
let url = `https://api.github.com/repos/fork-commit-merge/fork-commit-merge/pulls?state=closed&per_page=100`;
1212
const userContributions = new Map();
13+
let requestCount = 0;
14+
const MAX_REQUESTS = 10;
1315

14-
while (url) {
15-
const response = await axios.get(url, { headers });
16-
console.log(`Fetched ${response.data.length} pull requests`);
16+
while (url && requestCount < MAX_REQUESTS) {
17+
const response = await axios.get(url, {
18+
headers,
19+
timeout: 10000
20+
});
21+
requestCount++;
22+
console.log(`Fetched ${response.data.length} pull requests (Request ${requestCount}/${MAX_REQUESTS})`);
1723

1824
const pullRequests = response.data;
1925
pullRequests.forEach((pr: any) => {
2026
const username = pr.user.login;
2127
if (username === "dependabot" || username === "dependabot[bot]" || username === "nikohoffren") {
22-
console.log(`Skipping contribution from ${username}`);
2328
return;
2429
}
2530

@@ -41,7 +46,7 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
4146
.map(([username, count]) => ({
4247
username,
4348
contributions: count,
44-
avatarUrl: `https://avatars.githubusercontent.com/${username}`,
49+
avatarUrl: `https://avatars.githubusercontent.com//${username}`,
4550
}));
4651

4752
console.log('Final sorted users:', sortedUsers);
@@ -56,12 +61,3 @@ export async function fetchTopThreeUsersByPullRequests(repoPath: string) {
5661
return [];
5762
}
5863
}
59-
60-
61-
62-
63-
64-
65-
66-
67-

utils/fetchTopUsersFromDb.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,3 @@ export async function storeTopThreeUsersInDb(data: any[]) {
5353
throw error;
5454
}
5555
}
56-
57-
58-

0 commit comments

Comments
 (0)