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