@theholocron/github-client 1.58.0-alpha.68 → 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 +52 -14
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -161,18 +161,18 @@ function checks(rest) {
161
161
  };
162
162
  }
163
163
  // src/environments/environments.ts
164
- const PAGE_SIZE$1 = 100;
164
+ const PAGE_SIZE$2 = 100;
165
165
  /** A stop for a response that never ends; 100 pages is 10,000 environments, far past GitHub's limit. */
166
- const MAX_PAGES$3 = 100;
166
+ const MAX_PAGES$4 = 100;
167
167
  function environments(rest) {
168
168
  return {
169
169
  /** Every environment, all pages: GitHub lists 30 by default and at most 100 a page. */
170
170
  listEnvironments: async (repo) => {
171
171
  const all = [];
172
- for (let page = 1; page <= MAX_PAGES$3; page += 1) {
173
- const r = await rest.request(`${repoBase(repo)}/environments?per_page=${PAGE_SIZE$1}&page=${page}`);
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
174
  all.push(...r.environments);
175
- if (r.environments.length < PAGE_SIZE$1 || all.length >= r.total_count) break;
175
+ if (r.environments.length < PAGE_SIZE$2 || all.length >= r.total_count) break;
176
176
  }
177
177
  return all;
178
178
  },
@@ -326,7 +326,7 @@ function git(rest) {
326
326
  /** GitHub's largest page for this listing. */
327
327
  const PAGE$2 = 100;
328
328
  /** A guard so a runaway listing cannot loop forever. */
329
- const MAX_PAGES$2 = 50;
329
+ const MAX_PAGES$3 = 50;
330
330
  function hooksPath(scope) {
331
331
  if (scope.kind === "organization") return `/orgs/${segment(scope.org)}/hooks`;
332
332
  const parts = scope.repo.split("/");
@@ -340,7 +340,7 @@ function hooks(rest) {
340
340
  listHooks: async (scope) => {
341
341
  const path = hooksPath(scope);
342
342
  const all = [];
343
- for (let page = 1; page <= MAX_PAGES$2; page++) {
343
+ for (let page = 1; page <= MAX_PAGES$3; page++) {
344
344
  const batch = await rest.request(path, { query: {
345
345
  per_page: String(PAGE$2),
346
346
  page: String(page)
@@ -515,10 +515,29 @@ function issues(rest) {
515
515
  }
516
516
  };
517
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
+ }
518
536
  // src/labels/labels.ts
519
537
  function labels(rest) {
520
538
  return {
521
- 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}`) })),
522
541
  createLabel: (repo, body) => rest.request(`${repoBase(repo)}/labels`, {
523
542
  method: "POST",
524
543
  body
@@ -789,14 +808,33 @@ function scopeBase$1(repo, scope) {
789
808
  }
790
809
  function secrets(rest) {
791
810
  return {
792
- listSecrets: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets`).then((r) => r.secrets.map((s) => s.name)),
793
- /** The organization's secrets with their visibility, names only (first 100). */
794
- 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) => ({
795
827
  name: s.name,
796
828
  visibility: s.visibility
797
829
  }))),
798
- /** The names of the repositories that can read one organization secret of visibility `selected` (first 100). */
799
- 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)),
800
838
  getPublicKey: (repo, scope) => rest.request(`${scopeBase$1(repo, scope)}/secrets/public-key`),
801
839
  putSecret: (repo, scope, name, body) => rest.request(`${scopeBase$1(repo, scope)}/secrets/${name}`, {
802
840
  method: "PUT",
@@ -916,7 +954,7 @@ function teams(rest) {
916
954
  return all;
917
955
  },
918
956
  /** The teams that have access to a repository, with each team's permission there (read-only). */
919
- 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}`) })),
920
958
  addRepo: (org, teamSlug, owner, repo, permission) => rest.request(`/orgs/${org}/teams/${teamSlug}/repos/${owner}/${repo}`, {
921
959
  method: "PUT",
922
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.68",
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.68",
35
+ "@theholocron/http-client": "^1.58.0-alpha.69",
36
36
  "@theholocron/observability": "^0.7.0-alpha.9"
37
37
  },
38
38
  "devDependencies": {