MCPcopy Index your code
hub / github.com/massCodeIO/massCode / fetchGitHubGistImport

Function fetchGitHubGistImport

src/main/import/snippets/githubGists.ts:175–215  ·  view source on GitHub ↗
(
  urlOrId: string | undefined,
)

Source from the content-addressed store, hash-verified

173}
174
175export async function fetchGitHubGistImport(
176 urlOrId: string | undefined,
177): Promise<SnippetImportParseResult> {
178 if (!urlOrId?.trim()) {
179 throw new Error('GitHub Gist URL is required')
180 }
181
182 const gistId = getGistId(urlOrId)
183 if (!gistId) {
184 throw new Error('Invalid GitHub Gist URL')
185 }
186
187 let response: Response
188 try {
189 response = await fetch(`https://api.github.com/gists/${gistId}`, {
190 headers: {
191 'Accept': 'application/vnd.github+json',
192 'User-Agent': 'massCode',
193 },
194 signal: AbortSignal.timeout(GIST_FETCH_TIMEOUT_MS),
195 })
196 }
197 catch (error) {
198 if (error instanceof Error && error.name === 'TimeoutError') {
199 throw new Error('GitHub Gist request timed out')
200 }
201
202 throw error
203 }
204
205 if (!response.ok) {
206 throw new Error(
207 getGistRequestErrorMessage(response.status, response.headers),
208 )
209 }
210
211 return parseGitHubGistResponse(
212 (await response.json()) as GitHubGistResponse,
213 urlOrId,
214 )
215}

Callers 2

parsers.test.tsFile · 0.90

Calls 3

getGistIdFunction · 0.85
parseGitHubGistResponseFunction · 0.85

Tested by

no test coverage detected