createGitHubClient (maintainer/github.ts)

TanStack/ai · scripts/maintainer/github.ts · typescript · MIT
integration

Factory for GitHub API client with injected token and fetch for testability.

// Source: https://github.com/TanStack/ai | License: MIT | Copyright 2025 Tanner Linsley
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Thin GitHub API client. Token and fetch are injected so tests never touch
 * the network and callers control auth.
 */

export interface GitHubClient {
  graphql: <T>(query: string, variables: Record<string, unknown>) => Promise<T>
  rest: (
    method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
    path: string,
    body?: unknown,
  ) => Promise<unknown>
}

export interface GitHubClientOptions {
  token: string
  fetchImpl?: typeof fetch
  baseUrl?: string
  /** Per-request deadline; a stalled connection aborts instead of hanging the job. */
  timeoutMs?: number
}

export function createGitHubClient(options: GitHubClientOptions

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key