import { getToken } from './token.js'; import { GithubError } from './client.js'; const BASE = 'https://api.github.com'; export async function restJson(path: string): Promise { const res = await fetch(`${BASE}${path}`, { headers: { authorization: `bearer ${getToken()}`, accept: 'application/vnd.github+json', 'user-agent': 'pr-monitor', }, }); if (!res.ok) { throw new GithubError(`GitHub REST ${path}: ${res.status}`); } return res.json() as Promise; } /** Download an artifact zip (follows the storage redirect). */ export async function restZip(path: string, maxBytes: number): Promise { const res = await fetch(`${BASE}${path}`, { headers: { authorization: `bearer ${getToken()}`, 'user-agent': 'pr-monitor' }, }); if (!res.ok) throw new GithubError(`GitHub REST ${path}: ${res.status}`); const buf = new Uint8Array(await res.arrayBuffer()); if (buf.byteLength > maxBytes) return null; return buf; }