| 277 | } |
| 278 | |
| 279 | async function createGithubIssue(repo, title, body, token) { |
| 280 | const url = 'https://api.github.com/repos/' + repo + '/issues'; |
| 281 | const response = await fetch(url, { |
| 282 | method: 'POST', |
| 283 | headers: { |
| 284 | 'Authorization': 'Bearer ' + token, |
| 285 | 'Accept': 'application/vnd.github+json', |
| 286 | 'Content-Type': 'application/json', |
| 287 | 'X-GitHub-Api-Version': '2022-11-28', |
| 288 | }, |
| 289 | body: JSON.stringify({ title: title, body: body }), |
| 290 | signal: AbortSignal.timeout(15000), |
| 291 | }); |
| 292 | |
| 293 | if (!response.ok) { |
| 294 | let errText = ''; |
| 295 | try { errText = await response.text(); } catch (_) {} |
| 296 | throw new Error('GitHub API ' + response.status + ': ' + errText.slice(0, 200)); |
| 297 | } |
| 298 | |
| 299 | const data = await response.json(); |
| 300 | return { number: data.number, url: data.html_url }; |
| 301 | } |
| 302 | |
| 303 | function escapeSearchQuery(s) { |
| 304 | return String(s || '').replace(/"/g, '').replace(/[\r\n]+/g, ' ').trim(); |