( endpoint: string, method = "GET", body?: unknown )
| 13 | // -- |
| 14 | |
| 15 | async function githubRequest<T>( |
| 16 | endpoint: string, |
| 17 | method = "GET", |
| 18 | body?: unknown |
| 19 | ): Promise<T> { |
| 20 | const token = process.env.GITHUB_TOKEN; |
| 21 | if (!token) throw new Error("GITHUB_TOKEN required"); |
| 22 | |
| 23 | const response = await fetch(`https://api.github.com${endpoint}`, { |
| 24 | method, |
| 25 | headers: { |
| 26 | Authorization: `Bearer ${token}`, |
| 27 | Accept: "application/vnd.github.v3+json", |
| 28 | "User-Agent": "sweep", |
| 29 | ...(body && { "Content-Type": "application/json" }), |
| 30 | }, |
| 31 | ...(body && { body: JSON.stringify(body) }), |
| 32 | }); |
| 33 | |
| 34 | if (!response.ok) { |
| 35 | if (response.status === 404) return {} as T; |
| 36 | const text = await response.text(); |
| 37 | throw new Error(`GitHub API ${response.status}: ${text}`); |
| 38 | } |
| 39 | |
| 40 | return response.json(); |
| 41 | } |
| 42 | |
| 43 | // -- |
| 44 |
no outgoing calls
no test coverage detected