From 8d77b62e6e22ef97bbc92cca47c43edca60b911e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Mar 2026 06:37:14 +0000 Subject: [PATCH] refactor: extract getRateLimitReset helper function Extract duplicated rate limit reset timestamp calculation into a single helper function. Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com> --- src/lib/github.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/github.ts b/src/lib/github.ts index 86ec3b4..2183691 100644 --- a/src/lib/github.ts +++ b/src/lib/github.ts @@ -22,6 +22,12 @@ import { const GITHUB_API = "https://api.github.com"; const GITHUB_GRAPHQL = "https://api.github.com/graphql"; + +function getRateLimitReset(res: Response): number { + const resetHeader = res.headers.get("X-RateLimit-Reset"); + return resetHeader ? parseInt(resetHeader, 10) : Math.floor(Date.now() / 1000) + 3600; +} + function headers(token?: string): HeadersInit { const h: HeadersInit = { Accept: "application/vnd.github+json", @@ -38,9 +44,7 @@ async function handleResponse(res: Response): Promise { throw new UserNotFoundError("unknown"); } if (res.status === 403) { - const resetHeader = res.headers.get("X-RateLimit-Reset"); - const resetTimestamp = resetHeader ? parseInt(resetHeader, 10) : Math.floor(Date.now() / 1000) + 3600; - throw new RateLimitError(resetTimestamp); + throw new RateLimitError(getRateLimitReset(res)); } if (!res.ok) { const body = await res.text().catch(() => "Unknown error"); @@ -65,9 +69,7 @@ async function graphql(query: string, token?: string, variables?: Record "Unknown error");