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

Method #restPaginateArray

src/github/github_fetch.mjs:265–293  ·  view source on GitHub ↗
({ endpoint, params = {}, useCache })

Source from the content-addressed store, hash-verified

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 });

Callers 1

listPRCommentsMethod · 0.95

Calls 6

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

Tested by

no test coverage detected