@theholocron/github-client 1.58.0-alpha.67 → 1.58.0-alpha.69

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/index.mjs +60 -10
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -161,9 +161,21 @@ function checks(rest) {
161
161
  };
162
162
  }
163
163
  // src/environments/environments.ts
164
+ const PAGE_SIZE$2 = 100;
165
+ /** A stop for a response that never ends; 100 pages is 10,000 environments, far past GitHub's limit. */
166
+ const MAX_PAGES$4 = 100;
164
167
  function environments(rest) {
165
168
  return {
166
- listEnvironments: (repo) => rest.request(`${repoBase(repo)}/environments`).then((r) => r.environments),
169
+ /** Every environment, all pages: GitHub lists 30 by default and at most 100 a page. */
170
+ listEnvironments: async (repo) => {
171
+ const all = [];
172
+ for (let page = 1; page <= MAX_PAGES$4; page += 1) {
173
+ const r = await rest.request(`${repoBase(repo)}/environments?per_page=${PAGE_SIZE$2}&page=${page}`);
174
+ all.push(...r.environments);
175
+ if (r.environments.length < PAGE_SIZE$2 || all.length >= r.total_count) break;
176
+ }
177
+ return all;
178
+ },
167
179
  upsertEnvironment: (repo, name, body) => rest.request(`${repoBase(repo)}/environments/${encodeURIComponent(name)}`, {
168
180
  method: "PUT",
169
181
  body
@@ -314,7 +326,7 @@ function git(rest) {
314
326
  /** GitHub's largest page for this listing. */
315
327
  const PAGE$2 = 100;
316
328
  /** A guard so a runaway listing cannot loop forever. */
317
- const MAX_PAGES$2 = 50;
329
+ const MAX_PAGES$3 = 50;
318
330
  function hooksPath(scope) {
319
331
  if (scope.kind === "organization") return `/orgs/${segment(scope.org)}/hooks`;
320
332
  const parts = scope.repo.split("/");
@@ -328,7 +340,7 @@ function hooks(rest) {
328
340
  listHooks: async (scope) => {
329
341
  const path = hooksPath(scope);
330
342
  const all = [];
331
- for (let page = 1; page <= MAX_PAGES$2; page++) {
343
+ for (let page = 1; page <= MAX_PAGES$3; page++) {
332
344
  const batch = await rest.request(path, { query: {
333
345
  per_page: String(PAGE$2),
334
346
  page: String(page)
@@ -503,10 +515,29 @@ function issues(rest) {
503
515
  }
504
516
  };
505
517
  }
518
+ // src/paginate/paginate.ts
519
+ const PAGE_SIZE$1 = 100;
520
+ /** A stop for a response that never ends; 100 pages is 10,000 items, far past what these lists hold. */
521
+ const MAX_PAGES$2 = 100;
522
+ /**
523
+ * Reads a GitHub list page by page (`per_page=100&page=N`) until a short page, the reported total
524
+ * or the page cap, and returns every item. GitHub's default is 30 items a page, so a single
525
+ * request silently drops the rest.
526
+ */
527
+ async function readAllPages(read) {
528
+ const all = [];
529
+ for (let page = 1; page <= MAX_PAGES$2; page += 1) {
530
+ const batch = await read(`per_page=${PAGE_SIZE$1}&page=${page}`);
531
+ all.push(...batch.items);
532
+ if (batch.items.length < PAGE_SIZE$1 || batch.total !== void 0 && all.length >= batch.total) break;
533
+ }
534
+ return all;
535
+ }
506
536
  // src/labels/labels.ts
507
537
  function labels(rest) {
508
538
  return {
509
- listLabels: (repo) => rest.request(`${repoBase(repo)}/labels?per_page=100`),
539
+ /** Every label, all pages. */
540
+ listLabels: (repo) => readAllPages(async (query) => ({ items: await rest.request(`${repoBase(repo)}/labels?${query}`) })),
510
541
  createLabel: (repo, body) => rest.request(`${repoBase(repo)}/labels`, {
511
542
  method: "POST",
512
543
  body
@@ -777,14 +808,33 @@ function scopeBase$1(repo, scope) {
777
808
  }
778
809
  function secrets(rest) {
779
810
  return {
780
- listSecrets: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets`).then((r) => r.secrets.map((s) => s.name)),
781
- /** The organization's secrets with their visibility, names only (first 100). */
782
- listOrgSecretInfo: (org) => rest.request(`/orgs/${org}/actions/secrets?per_page=100`).then((r) => r.secrets.map((s) => ({
811
+ /** Every secret name in the scope, all pages: GitHub lists 30 by default and at most 100 a page. */
812
+ listSecrets: (repo, scope) => readAllPages(async (query) => {
813
+ const r = await rest.request(`${scopeBase$1(repo, scope)}/secrets?${query}`);
814
+ return {
815
+ items: r.secrets,
816
+ total: r.total_count
817
+ };
818
+ }).then((all) => all.map((s) => s.name)),
819
+ /** The organization's secrets with their visibility, names only, all pages. */
820
+ listOrgSecretInfo: (org) => readAllPages(async (query) => {
821
+ const r = await rest.request(`/orgs/${org}/actions/secrets?${query}`);
822
+ return {
823
+ items: r.secrets,
824
+ total: r.total_count
825
+ };
826
+ }).then((all) => all.map((s) => ({
783
827
  name: s.name,
784
828
  visibility: s.visibility
785
829
  }))),
786
- /** The names of the repositories that can read one organization secret of visibility `selected` (first 100). */
787
- listSelectedRepositories: (org, name) => rest.request(`/orgs/${org}/actions/secrets/${name}/repositories?per_page=100`).then((r) => r.repositories.map((repo) => repo.name)),
830
+ /** The names of the repositories that can read one organization secret of visibility `selected`, all pages. */
831
+ listSelectedRepositories: (org, name) => readAllPages(async (query) => {
832
+ const r = await rest.request(`/orgs/${org}/actions/secrets/${name}/repositories?${query}`);
833
+ return {
834
+ items: r.repositories,
835
+ total: r.total_count
836
+ };
837
+ }).then((all) => all.map((repo) => repo.name)),
788
838
  getPublicKey: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets/public-key`),
789
839
  putSecret: (repo, scope, name, body) => rest.request(`${scopeBase$1(repo, scope)}/secrets/${name}`, {
790
840
  method: "PUT",
@@ -904,7 +954,7 @@ function teams(rest) {
904
954
  return all;
905
955
  },
906
956
  /** The teams that have access to a repository, with each team's permission there (read-only). */
907
- listForRepo: (repo) => rest.request(`${repoBase(repo)}/teams`, { query: { per_page: String(PAGE$1) } }),
957
+ listForRepo: (repo) => readAllPages(async (query) => ({ items: await rest.request(`${repoBase(repo)}/teams?${query}`) })),
908
958
  addRepo: (org, teamSlug, owner, repo, permission) => rest.request(`/orgs/${org}/teams/${teamSlug}/repos/${owner}/${repo}`, {
909
959
  method: "PUT",
910
960
  body: { permission }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theholocron/github-client",
3
- "version": "1.58.0-alpha.67",
3
+ "version": "1.58.0-alpha.69",
4
4
  "description": "A TypeScript client for the GitHub REST API",
5
5
  "keywords": [
6
6
  "github",
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@theholocron/http-client": "^1.58.0-alpha.67",
35
+ "@theholocron/http-client": "^1.58.0-alpha.69",
36
36
  "@theholocron/observability": "^0.7.0-alpha.9"
37
37
  },
38
38
  "devDependencies": {