MCPcopy Create free account
hub / github.com/Martian-Engineering/pr-sheriff / #restRequest

Method #restRequest

src/github/github_fetch.mjs:330–345  ·  view source on GitHub ↗
({ method, endpoint, params = undefined, useCache })

Source from the content-addressed store, hash-verified

328 }
329
330 async #restRequest({ method, endpoint, params = undefined, useCache }) {
331 const key = cacheKey({ kind: 'rest', method, endpoint, params, repo: this.repo });
332 if (useCache) {
333 const cached = readJsonCache({ cacheDir: this.cacheDir, key, ttlSeconds: this.cacheTtlSeconds });
334 if (cached) return cached;
335 }
336
337 const fullEndpoint = params ? `${endpoint}${encodeQuery(params)}` : endpoint;
338 const { status, body } = await this.#restRequestRaw({ method, endpoint: fullEndpoint });
339 if (status && status >= 400) {
340 throw new Error(`GitHub API error ${status} for ${endpoint}`);
341 }
342
343 if (useCache) writeJsonCache({ cacheDir: this.cacheDir, key, value: body });
344 return body;
345 }
346
347 async #restRequestRaw({ method, endpoint }) {
348 const args = ['api', '--include', '-X', method, endpoint];

Callers 2

getPRMethod · 0.95
getIssueMethod · 0.95

Calls 5

#restRequestRawMethod · 0.95
cacheKeyFunction · 0.90
readJsonCacheFunction · 0.90
writeJsonCacheFunction · 0.90
encodeQueryFunction · 0.85

Tested by

no test coverage detected