From d2d18d2e7e63fe1c72809bd4e4a41e46eb651437 Mon Sep 17 00:00:00 2001 From: iqb430 <1qbal4nwarr@gmail.com> Date: Wed, 22 Jul 2026 02:14:13 +0700 Subject: [PATCH] fix(github): cap repo pagination to prevent rate limit exhaustion --- lib/github.ts | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/lib/github.ts b/lib/github.ts index bc6ac634e..0a8ee95a6 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -1415,7 +1415,7 @@ async function fetchReposUncached( options: FetchOptions ): Promise { const firstPageRes = await fetchWithRetry( - `${GITHUB_REST_URL}/users/${encodedUsername}/repos?per_page=100&page=1&sort=pushed`, + `${GITHUB_REST_URL}/users/${encodedUsername}/repos?per_page=100&sort=pushed`, { headers: getHeaders(options.token), cache: 'no-store', @@ -1434,44 +1434,6 @@ async function fetchReposUncached( const firstPageRepos = (await firstPageRes.json()) as GitHubRepo[]; const allRepos: GitHubRepo[] = firstPageRepos.map(sanitizeRepo); - const MAX_PAGES = Number(process.env.GITHUB_MAX_PAGES ?? '3'); - - if (firstPageRepos.length === 100) { - const remainingPages = Array.from({ length: MAX_PAGES - 1 }, (_, i) => i + 2); - - const responses = await Promise.all( - remainingPages.map((page) => - fetchWithRetry( - `${GITHUB_REST_URL}/users/${encodedUsername}/repos?per_page=100&page=${page}&sort=pushed`, - { - headers: getHeaders(options.token), - cache: 'no-store', - signal: options.signal, - }, - 0, - undefined, - options.token - ) - ) - ); - - const pagesRepos = await Promise.all( - responses.map(async (response) => { - if (!response.ok) { - throwIfRateLimited(response); - throw new Error(`GitHub REST API error: ${response.status}`); - } - - const repos = (await response.json()) as GitHubRepo[]; - return repos.map(sanitizeRepo); - }) - ); - - for (const repos of pagesRepos) { - allRepos.push(...repos); - } - } - if (!options.bypassCache) await reposCache.set(key, allRepos, GITHUB_CACHE_TTL_MS); return allRepos; }