({ endpoint, params = {}, useCache })
| 263 | } |
| 264 | |
| 265 | async #restPaginateArray({ endpoint, params = {}, useCache }) { |
| 266 | const key = cacheKey({ kind: 'rest-array', endpoint, params, repo: this.repo }); |
| 267 | if (useCache) { |
| 268 | const cached = readJsonCache({ cacheDir: this.cacheDir, key, ttlSeconds: this.cacheTtlSeconds }); |
| 269 | if (cached) return cached; |
| 270 | } |
| 271 | |
| 272 | const perPage = 100; |
| 273 | let url = `${endpoint}${encodeQuery({ ...params, per_page: perPage })}`; |
| 274 | /** @type {any[]} */ |
| 275 | const out = []; |
| 276 | for (let page = 0; page < 200; page++) { |
| 277 | const { status, headers, body } = await this.#restRequestRaw({ method: 'GET', endpoint: url }); |
| 278 | if (status && status >= 400) { |
| 279 | throw new Error(`GitHub API error ${status} for ${endpoint}`); |
| 280 | } |
| 281 | if (!Array.isArray(body)) { |
| 282 | throw new Error(`Expected array response for ${endpoint}`); |
| 283 | } |
| 284 | out.push(...body); |
| 285 | |
| 286 | const rels = parseLinkHeader(headers.link); |
| 287 | if (!rels.next) break; |
| 288 | url = rels.next; |
| 289 | } |
| 290 | |
| 291 | if (useCache) writeJsonCache({ cacheDir: this.cacheDir, key, value: out }); |
| 292 | return out; |
| 293 | } |
| 294 | |
| 295 | async #restPaginateSearch({ endpoint, params = {}, useCache }) { |
| 296 | const key = cacheKey({ kind: 'rest-search', endpoint, params, repo: this.repo }); |
no test coverage detected