MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / paginate

Function paginate

packages/backend/src/gitea.ts:241–264  ·  view source on GitHub ↗
(request: (page: number) => Promise<HttpResponse<T[], any>>)

Source from the content-addressed store, hash-verified

239
240// @see : https://docs.gitea.com/development/api-usage#pagination
241const paginate = async <T>(request: (page: number) => Promise<HttpResponse<T[], any>>) => {
242 let page = 1;
243 const result = await request(page);
244 const output: T[] = result.data;
245
246 const totalCountString = result.headers.get('x-total-count');
247 if (!totalCountString) {
248 const e = new Error("Header 'x-total-count' not found");
249 Sentry.captureException(e);
250 throw e;
251 }
252 const totalCount = parseInt(totalCountString);
253
254 while (output.length < totalCount) {
255 page++;
256 const result = await request(page);
257 if (result.data.length === 0) {
258 break;
259 }
260 output.push(...result.data);
261 }
262
263 return output;
264}

Callers 2

getReposOwnedByUsersFunction · 0.85
getReposForOrgsFunction · 0.85

Calls 1

requestFunction · 0.85

Tested by

no test coverage detected