* Simple wrapper around `fetch()` for making GitHub API requests, e.g. `fetchGitHubAPI('/repos/withastro')`. * Throws an error if the fetch does not succeed. * @param {string} endpoint GitHub API endpoint to fetch
(endpoint)
| 493 | * @param {string} endpoint GitHub API endpoint to fetch |
| 494 | */ |
| 495 | async function fetchGitHubAPI(endpoint) { |
| 496 | const response = await fetch(`https://api.github.com${endpoint}`, { |
| 497 | headers: { |
| 498 | Accept: 'application/vnd.github.v3+json', |
| 499 | Authorization: `token ${GITHUB_TOKEN}` |
| 500 | } |
| 501 | }) |
| 502 | if (!response.ok) { |
| 503 | throw new Error(`GitHub API request failed: ${response.statusText}`) |
| 504 | } |
| 505 | return response.json() |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * Create and add the co-authors button. |