()
| 272 | } |
| 273 | |
| 274 | async function ensureCleanupLabel() { |
| 275 | const response = await fetch( |
| 276 | `https://api.github.com/repos/${repo.owner}/${repo.name}/labels/${encodeURIComponent(cleanupLabel)}`, |
| 277 | { |
| 278 | headers, |
| 279 | }, |
| 280 | ) |
| 281 | if (response.ok) return |
| 282 | if (response.status !== 404) |
| 283 | throw new Error(`Failed to check cleanup label: ${response.status} ${response.statusText}`) |
| 284 | |
| 285 | await githubRequest(`/repos/${repo.owner}/${repo.name}/labels`, { |
| 286 | method: "POST", |
| 287 | body: JSON.stringify({ |
| 288 | name: cleanupLabel, |
| 289 | color: "ededed", |
| 290 | description: "PR was closed by automated cleanup", |
| 291 | }), |
| 292 | }) |
| 293 | } |
| 294 | |
| 295 | async function githubRequest(path: string, init: RequestInit, attempt = 0): Promise<Response> { |
| 296 | const response = await fetch(path.startsWith("https://") ? path : `https://api.github.com${path}`, { |
no test coverage detected