(path: string, token: string, options?: RequestInit)
| 6 | * Wrapper around fetch that adds GitHub auth headers and handles network errors. |
| 7 | */ |
| 8 | export async function ghFetch(path: string, token: string, options?: RequestInit) { |
| 9 | try { |
| 10 | const res = await fetch(`https://api.github.com${path}`, { |
| 11 | ...options, |
| 12 | headers: { |
| 13 | Authorization: `token ${token}`, |
| 14 | Accept: 'application/vnd.github.v3+json', |
| 15 | 'X-GitHub-Api-Version': API_VERSION, |
| 16 | ...(options?.headers || {}), |
| 17 | }, |
| 18 | }); |
| 19 | return res; |
| 20 | } catch (err) { |
| 21 | const message = err instanceof Error ? err.message : 'Network request failed'; |
| 22 | throw new Error(`NETWORK_ERROR: ${message}`); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | export function detectTokenType(token: string): TokenType { |
| 27 | if (token.startsWith('ghp_')) return 'classic'; |
no outgoing calls
no test coverage detected