@bensandee/forgejo-cli 0.5.5 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.mjs +20 -10
  2. package/package.json +1 -1
package/dist/bin.mjs CHANGED
@@ -162,7 +162,7 @@ function loadEnvFileForBin(rawArgs, bin, io = processIo) {
162
162
  //#region src/version.ts
163
163
  const parsed = z.object({ version: z.string() }).safeParse({
164
164
  name: "@bensandee/forgejo-cli",
165
- version: "0.5.5",
165
+ version: "0.5.6",
166
166
  description: "bst-fj: Forgejo API commands without the rest of bst",
167
167
  license: "MIT",
168
168
  repository: {
@@ -1664,6 +1664,16 @@ const commitStatusCommand = defineCommand({
1664
1664
  }
1665
1665
  });
1666
1666
  //#endregion
1667
+ //#region ../forgejo/src/fetcher.ts
1668
+ const LONG_FETCH_TIMEOUT_MS = 6e5;
1669
+ function morePagesFollow(res, pageLength, received, pageSize) {
1670
+ if (pageLength === 0) return false;
1671
+ const raw = res.headers.get("x-total-count")?.trim() ?? "";
1672
+ const total = raw === "" ? NaN : Number(raw);
1673
+ if (!Number.isSafeInteger(total) || total < 0) return pageLength >= pageSize;
1674
+ return received < total;
1675
+ }
1676
+ //#endregion
1667
1677
  //#region ../forgejo/src/label-provisioning.ts
1668
1678
  const LabelSchema = z.object({
1669
1679
  id: z.number(),
@@ -1673,7 +1683,7 @@ const LabelSchema = z.object({
1673
1683
  exclusive: z.boolean().optional()
1674
1684
  });
1675
1685
  const LabelListSchema = z.array(LabelSchema);
1676
- const LABELS_PAGE_SIZE = 100;
1686
+ const LABELS_PAGE_SIZE = 50;
1677
1687
  const LABELS_MAX_PAGES = 20;
1678
1688
  async function fetchAllForgejoLabels(executor, conn) {
1679
1689
  const labels = [];
@@ -1686,7 +1696,7 @@ async function fetchAllForgejoLabels(executor, conn) {
1686
1696
  const parsed = LabelListSchema.safeParse(await res.json());
1687
1697
  if (!parsed.success) throw new UnexpectedError(`Unexpected label-list response: ${parsed.error.message}`);
1688
1698
  labels.push(...parsed.data);
1689
- if (parsed.data.length < LABELS_PAGE_SIZE) break;
1699
+ if (!morePagesFollow(res, parsed.data.length, labels.length, LABELS_PAGE_SIZE)) break;
1690
1700
  }
1691
1701
  return labels;
1692
1702
  }
@@ -1900,7 +1910,10 @@ async function fetchIssueListPage(executor, conn, params) {
1900
1910
  verb: "list issues",
1901
1911
  resource: conn.repository
1902
1912
  }, repoNotFoundMessage(conn));
1903
- return parseIssueListOrThrow(await res.json());
1913
+ return {
1914
+ raw: parseIssueListOrThrow(await res.json()),
1915
+ res
1916
+ };
1904
1917
  }
1905
1918
  function normalizeDetailedIssues(raw, type) {
1906
1919
  const normalized = raw.map(normalizeIssue);
@@ -1911,7 +1924,7 @@ const DETAILED_LIST_MAX_PAGES = 20;
1911
1924
  async function listForgejoIssuesDetailedPaged(executor, conn, query, options) {
1912
1925
  const issues = [];
1913
1926
  for (let page = 1; page <= DETAILED_LIST_MAX_PAGES; page++) {
1914
- const raw = await fetchIssueListPage(executor, conn, issueListParams(query.type, {
1927
+ const { raw } = await fetchIssueListPage(executor, conn, issueListParams(query.type, {
1915
1928
  ...query,
1916
1929
  limit: DETAILED_LIST_PAGE_SIZE,
1917
1930
  page
@@ -2301,9 +2314,6 @@ const labelsCommand = defineCommand({
2301
2314
  }
2302
2315
  });
2303
2316
  //#endregion
2304
- //#region ../forgejo/src/fetcher.ts
2305
- const LONG_FETCH_TIMEOUT_MS = 6e5;
2306
- //#endregion
2307
2317
  //#region ../forgejo/src/releases.ts
2308
2318
  const SETTLE_ATTEMPTS = 4;
2309
2319
  const SETTLE_BASE_DELAY_MS = 2e3;
@@ -2891,7 +2901,7 @@ async function paginate(executor, conn, endpoint, verb, extract) {
2891
2901
  }));
2892
2902
  const items = extract(await res.json());
2893
2903
  all.push(...items);
2894
- if (items.length < PAGE_LIMIT) break;
2904
+ if (!morePagesFollow(res, items.length, all.length, PAGE_LIMIT)) break;
2895
2905
  if (page === 101) throw new UnexpectedError(`${endpoint} still returns full pages after ${String(MAX_PAGES)} pages; refusing to report a prefix of it`);
2896
2906
  }
2897
2907
  return all;
@@ -3876,7 +3886,7 @@ async function listForgejoComments(executor, conn, number, options = {}) {
3876
3886
  }, issueNotFoundMessage(conn, number));
3877
3887
  const parsed = parseCommentListOrThrow(await res.json());
3878
3888
  comments.push(...parsed.map(normalizeComment));
3879
- if (parsed.length < COMMENTS_PAGE_SIZE) break;
3889
+ if (!morePagesFollow(res, parsed.length, comments.length, COMMENTS_PAGE_SIZE)) break;
3880
3890
  if (page === COMMENTS_MAX_PAGES) {
3881
3891
  log.warn(`Comment listing for #${String(number)} hit the ${String(COMMENTS_MAX_PAGES)}-page cap; results may be truncated`);
3882
3892
  options.onPageCap?.();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bensandee/forgejo-cli",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "bst-fj: Forgejo API commands without the rest of bst",
5
5
  "license": "MIT",
6
6
  "repository": {