MCPcopy Index your code
hub / github.com/utterance/utterances / loadJsonFile

Function loadJsonFile

src/github.ts:110–131  ·  view source on GitHub ↗
(path: string, html = false)

Source from the content-addressed store, hash-verified

108}
109
110export function loadJsonFile<T>(path: string, html = false) {
111 const request = githubRequest(`repos/${owner}/${repo}/contents/${path}?ref=${branch}`);
112 if (html) {
113 request.headers.set('accept', GITHUB_ENCODING__HTML);
114 }
115 return githubFetch(request).then<FileContentsResponse | string>(response => {
116 if (response.status === 404) {
117 throw new Error(`Repo "${owner}/${repo}" does not have a file named "${path}" in the "${branch}" branch.`);
118 }
119 if (!response.ok) {
120 throw new Error(`Error fetching ${path}.`);
121 }
122 return html ? response.text() : response.json();
123 }).then<T>(file => {
124 if (html) {
125 return file;
126 }
127 const { content } = file as FileContentsResponse;
128 const decoded = decodeBase64UTF8(content);
129 return JSON.parse(decoded);
130 });
131}
132
133export function loadIssueByTerm(term: string) {
134 const q = `"${term}" type:issue in:title repo:${owner}/${repo}`;

Callers 1

getRepoConfigFunction · 0.90

Calls 3

decodeBase64UTF8Function · 0.90
githubRequestFunction · 0.85
githubFetchFunction · 0.85

Tested by

no test coverage detected