[READ-ONLY] Mirror of https://github.com/flo-bit/edge-function-github-contribution. edge-function-github-contribution.vercel.app
0

Configure Feed

Select the types of activity you want to include in your feed.

remove pages

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