Skip to content

Extract duplicated API query helpers into a shared utilities module #145

@blinkeye-lcm

Description

@blinkeye-lcm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions