| 54 | } |
| 55 | |
| 56 | async function githubRequest({ apiUrl, token, method, endpoint, body }) { |
| 57 | const url = `${apiUrl.replace(/\/$/, '')}${endpoint}` |
| 58 | const response = await fetch(url, { |
| 59 | method, |
| 60 | headers: { |
| 61 | Authorization: `Bearer ${token}`, |
| 62 | Accept: 'application/vnd.github+json', |
| 63 | 'User-Agent': 'tanstack-router-bundle-size-bot', |
| 64 | 'Content-Type': 'application/json', |
| 65 | }, |
| 66 | body: body ? JSON.stringify(body) : undefined, |
| 67 | }) |
| 68 | |
| 69 | if (!response.ok) { |
| 70 | const text = await response.text() |
| 71 | throw new Error( |
| 72 | `${method} ${endpoint} failed (${response.status} ${response.statusText}): ${text}`, |
| 73 | ) |
| 74 | } |
| 75 | |
| 76 | if (response.status === 204) { |
| 77 | return undefined |
| 78 | } |
| 79 | |
| 80 | return response.json() |
| 81 | } |
| 82 | |
| 83 | async function listIssueComments({ apiUrl, token, repo, pr }) { |
| 84 | const comments = [] |