···
13
13
const { searchParams } = new URL(req.url);
14
14
const owner = searchParams.get('owner');
15
15
const repo = searchParams.get('repo');
16
16
-
const perPage = Math.min(Number(searchParams.get('per_page') || 30), 100);
17
17
-
18
16
if (!owner || !repo) {
19
17
return cors(req, new Response('Missing required query parameters: owner and repo', { status: 400 }), corsOptions);
20
18
}
21
19
22
22
-
const response = await fetch(
23
23
-
`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/contributors?per_page=${perPage}`,
24
24
-
{
25
25
-
headers: {
26
26
-
'Accept': 'application/vnd.github+json',
27
27
-
'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
28
28
-
},
20
20
+
const allContributors: any[] = [];
21
21
+
let page = 1;
22
22
+
23
23
+
while (true) {
24
24
+
const response = await fetch(
25
25
+
`https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/contributors?per_page=100&page=${page}`,
26
26
+
{
27
27
+
headers: {
28
28
+
'Accept': 'application/vnd.github+json',
29
29
+
'Authorization': `Bearer ${process.env.GITHUB_TOKEN}`,
30
30
+
},
31
31
+
}
32
32
+
);
33
33
+
34
34
+
if (!response.ok) {
35
35
+
return cors(req, new Response(`Error fetching contributors from GitHub: ${response.statusText}`, { status: response.status }), corsOptions);
29
36
}
30
30
-
);
37
37
+
38
38
+
const contributors = await response.json();
39
39
+
if (!Array.isArray(contributors) || contributors.length === 0) break;
31
40
32
32
-
if (!response.ok) {
33
33
-
return cors(req, new Response(`Error fetching contributors from GitHub: ${response.statusText}`, { status: response.status }), corsOptions);
41
41
+
allContributors.push(...contributors);
42
42
+
if (contributors.length < 100) break;
43
43
+
page++;
34
44
}
35
45
36
36
-
const contributors = await response.json();
37
37
-
38
38
-
const data = contributors.map((c: any) => ({
46
46
+
const data = allContributors.map((c: any) => ({
39
47
username: c.login,
40
48
avatarUrl: c.avatar_url,
41
49
contributions: c.contributions,