fix: return page as object {page, next, total, hasMore, nextUrl} for routes.js compat

routes.js reads resp.page?.hasMore and resp.page?.nextUrl — the old
HTTP client returned page as an object from parsePageInfo. The CLI
pivot accidentally returned page as a number, making hasMore always
undefined in routes.js. Restore the object shape in both gitea and
gitlab clients. Update tests to assert the object shape.
This commit is contained in:
2026-09-05 20:36:46 +00:00
parent 9032c9245a
commit 75687dc9b0
4 changed files with 73 additions and 33 deletions
+15 -6
View File
@@ -135,19 +135,28 @@ async function glabApiCall(endpoint, { method = 'GET', body, raw, glabBin, token
data = bodyText;
}
// Derive pagination from the Link header (H2 fix).
// Derive pagination info object matching the pre-pivot parsePageInfo shape.
// routes.js reads resp.page?.hasMore, resp.page?.nextUrl, etc.
const { next } = parseLinkHeader(headers.link);
const listIsArray = Array.isArray(data);
const hasMore = listIsArray ? next !== null : false;
let page = 1;
if (next) {
const totalRaw = headers['x-total'] || headers['x-total-count'];
const total = totalRaw ? Number(totalRaw) : null;
let currentPage = null;
if (listIsArray && next) {
const pageMatch = next.match(/[?&]page=(\d+)/);
if (pageMatch) {
page = Math.max(1, Number(pageMatch[1]) - 1);
currentPage = Math.max(1, Number(pageMatch[1]) - 1);
}
}
const pageInfo = {
page: currentPage,
next: next || null,
total: total !== null && Number.isFinite(total) ? total : null,
hasMore: listIsArray ? next !== null : false,
nextUrl: next || undefined,
};
return { status, headers, data, page: listIsArray ? page : null, hasMore: listIsArray ? hasMore : undefined };
return { status, headers, data, page: pageInfo };
}
// ---- Rate-limit helpers (no-ops with CLI transport) ----