/** * @file Authenticated GitHub REST fetch. `fetchGitHub` is the single entry * point that the rest of the github/ modules go through for REST calls. It * handles five things the callers shouldn't have to repeat: * * 1. Token resolution (env → `git config` → `gh`, memoized) when the caller * doesn't pass an explicit token. `gh` is in the chain because it holds * the keychain-stored credential that no environment variable carries, and * a request that silently goes out anonymous is served 60 requests an hour * rather than 5000. * 2. Standard `Accept` and `User-Agent` headers merged with caller-supplied * headers. * 3. Rate-limit detection, delegated to `github/error-classification` so all of * its shapes are caught: a 403 with `x-ratelimit-remaining: 0`, a 403 * whose body names the limit, a 429, and the secondary limit. Raised as a * typed `GitHubRateLimitError`, and it names an unauthenticated request as * the cause when that is what it was. * 4. Budget recording — every response's rate-limit headers go to * `github/rate-limit`, so a later preflight can refuse a sweep before it * starts instead of failing partway through. * 5. Empty-body detection — 200 OK + zero-byte body is the documented incident * shape (see GitHubEmptyBodyError JSDoc). Raised as a typed error so the * ref / GHSA modules can fall back to GraphQL on a different backend. * `getGhsaUrl` lives here because it's the URL counterpart to the GHSA * fetch path — the only other consumer is the GHSA module. */ import type { GitHubStatusResult } from '../env/github-status.js'; import type { GitHubFetchOptions } from './types.js'; /** * How long the status probe may take. Short on purpose: the request it explains * has already failed, so this is added latency on an error path, and the probe * fails open when it runs out. */ export declare const GITHUB_STATUS_PROBE_TIMEOUT_MS = 4000; /** * Fetch data from GitHub API with automatic authentication and rate limit * handling. Makes authenticated requests to the GitHub REST API with proper * error handling. * * Features: - Automatic token injection from environment if not provided - Rate * limit detection with helpful error messages - Standard GitHub API `Accept` * and `User-Agent` headers - JSON response parsing. * * @example * ```ts * // Fetch repository information * interface Repo { * name: string * full_name: string * default_branch: string * } * const repo = await fetchGitHub( * 'https://api.github.com/repos/owner/repo', * ) * console.log(`Default branch: ${repo.default_branch}`) * ``` * * @example * ;```ts * // With custom token and headers * const data = await fetchGitHub('https://api.github.com/user', { * token: 'ghp_customtoken', * headers: { 'X-Custom-Header': 'value' }, * }) * ``` * * @example * ```ts * // Handle rate limit errors * try { * await fetchGitHub('https://api.github.com/repos/owner/repo') * } catch (e) { * if (e.status === 403 && e.resetTime) { * console.error(`Rate limited until ${e.resetTime}`) * } * } * ``` * * @template T - Expected response type (defaults to `unknown`) * * @param url - Full GitHub API URL (e.g., * 'https://api.github.com/repos/owner/repo') * @param options - Fetch options including token and custom headers. * * @returns Parsed JSON response of type `T` * * @throws {GitHubRateLimitError} When API rate limit is exceeded (status 403) * @throws {Error} For other API errors with status code and message */ export declare function fetchGitHub(url: string, options?: GitHubFetchOptions | undefined): Promise; /** * The sentence appended to a GitHub failure describing the platform's state. * * Three outcomes, because they call for three different next moves. A degraded * component means waiting is the answer. All-operational means the fault is * probably this request rather than GitHub, which is what stops someone * waiting out an outage that is not happening. An unreachable status page says * so plainly instead of implying health it never confirmed. * * Pure over the probe's result, so every branch is testable without network. */ export declare function formatGitHubStatusNote(health: GitHubStatusResult | undefined): string; /** * Generate GitHub Security Advisory URL from GHSA ID. Constructs the public * advisory URL for a given GHSA identifier. * * @example * ;```ts * const url = getGhsaUrl('GHSA-1234-5678-90ab') * console.log(url) // 'https://github.com/advisories/GHSA-1234-5678-90ab' * ``` * * @param ghsaId - GHSA identifier (e.g., 'GHSA-xxxx-yyyy-zzzz') * * @returns Full URL to the advisory page */ export declare function getGhsaUrl(ghsaId: string): string;