Problem
Four API route files each redefine the same low level query helpers with identical bodies:
positiveInt
normalizeRepoList
chunk
resolveRepoScope
Affected routes:
src/app/api/pulls/route.ts
src/app/api/issues/route.ts
src/app/api/repos/[owner]/[name]/authors/[login]/pulls/route.ts
src/app/api/repos/[owner]/[name]/authors/[login]/issues/route.ts
The duplication adds noise to every route file, invites drift between copies, and forces multi file edits whenever the repo scope contract or query parsing rules need a tweak.
Proposal
Create src/lib/api-utils.ts and export the four helpers using the most strictly typed signatures already in the codebase:
positiveInt(value: string | null, fallback: number): number
normalizeRepoList(raw: string | null): string[] | null
chunk<T>(items: T[], size: number): T[][]
resolveRepoScope(reqRepos: string[] | null): Promise<string[]>
Replace the inline copies in the four routes above with a single import. Pages such as src/app/miners/page.tsx and src/app/repositories/page.tsx are out of scope and remain untouched.
Acceptance Criteria
src/lib/api-utils.ts is the single source of truth for the four helpers
- No inline copies remain in the four route files
- Call sites and route behavior stay identical
Problem
Four API route files each redefine the same low level query helpers with identical bodies:
positiveIntnormalizeRepoListchunkresolveRepoScopeAffected routes:
src/app/api/pulls/route.tssrc/app/api/issues/route.tssrc/app/api/repos/[owner]/[name]/authors/[login]/pulls/route.tssrc/app/api/repos/[owner]/[name]/authors/[login]/issues/route.tsThe duplication adds noise to every route file, invites drift between copies, and forces multi file edits whenever the repo scope contract or query parsing rules need a tweak.
Proposal
Create
src/lib/api-utils.tsand export the four helpers using the most strictly typed signatures already in the codebase:Replace the inline copies in the four routes above with a single import. Pages such as
src/app/miners/page.tsxandsrc/app/repositories/page.tsxare out of scope and remain untouched.Acceptance Criteria
src/lib/api-utils.tsis the single source of truth for the four helpers