MCPcopy Create free account
hub / github.com/GoogleChrome/samples / ghFetch

Function ghFetch

trailblazers/public/js/github/github-api.js:12–35  ·  view source on GitHub ↗
(ui, path, options = {})

Source from the content-addressed store, hash-verified

10 * @throws {Error} If the response is not OK.
11 */
12export async function ghFetch(ui, path, options = {}) {
13 const url = path.startsWith('https://')
14 ? path
15 : `https://api.github.com/repos/${ui.ghOwnerInput.value}/${ui.ghRepoInput.value}${path}`;
16 const res = await fetch(url, {
17 ...options,
18 headers: {
19 Authorization: `token ${ui.ghTokenInput.value}`,
20 Accept: 'application/vnd.github.v3+json',
21 ...options.headers,
22 },
23 });
24 if (!res.ok) {
25 const txt = await res.text();
26 let err;
27 try {
28 err = JSON.parse(txt);
29 } catch (e) {
30 err = { message: txt };
31 }
32 throw new Error(err.message || res.statusText);
33 }
34 return res.json();
35}

Callers 4

uploadDraftImagesFunction · 0.90
loadPostFromGitHubFunction · 0.90
createPRFunction · 0.90
getShaFunction · 0.90

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected