({ method, endpoint, params = undefined, useCache })
| 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]; |
no test coverage detected