@remogram/provider-github-api 0.1.0-beta.0 → 0.1.0-beta.1

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/index.js +32 -7
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import {
2
2
  fetchJson,
3
+ fetchJsonWithMeta,
4
+ parseLinkHeader,
3
5
  sanitizeField,
4
6
  sanitizeUrl,
5
7
  assertGitRef,
@@ -9,6 +11,7 @@ import {
9
11
  gitAheadBehind,
10
12
  ERROR_CODES,
11
13
  forgeError,
14
+ forgeIngestCapabilityFacts,
12
15
  } from '@remogram/core';
13
16
 
14
17
  const PUBLIC_GITHUB_HOST = 'github.com';
@@ -149,6 +152,24 @@ export async function githubFetch(config, parsed, path, options = {}) {
149
152
  });
150
153
  }
151
154
 
155
+ const MAX_CHECK_PAGES = 50;
156
+
157
+ export async function githubFetchPaginated(config, parsed, path, slice) {
158
+ const base = apiBase(config, parsed);
159
+ const { token } = requireToken();
160
+ const all = [];
161
+ let url = `${base}${path}`;
162
+ for (let page = 0; page < MAX_CHECK_PAGES && url; page += 1) {
163
+ const { body, headers } = await fetchJsonWithMeta(url, {
164
+ headers: authHeaders(token),
165
+ });
166
+ all.push(...slice(body));
167
+ const linkHeader = headers?.get?.('link') ?? headers?.get?.('Link') ?? null;
168
+ url = parseLinkHeader(linkHeader).next ?? null;
169
+ }
170
+ return all;
171
+ }
172
+
152
173
  export function graphqlEndpoint(config, parsed = {}) {
153
174
  const remoteHost = (parsed.host || configuredHost(config) || '').toLowerCase();
154
175
  if (remoteHost === PUBLIC_GITHUB_HOST) {
@@ -248,14 +269,14 @@ export function providerCapabilities() {
248
269
  check_sources: ['commit_statuses', 'check_runs'],
249
270
  mergeability_confidence: 'derived',
250
271
  host_binding: 'verified_remote_host',
251
- pagination: 'first_page_only',
272
+ pagination: 'supported',
252
273
  write_support: false,
274
+ ...forgeIngestCapabilityFacts(),
253
275
  };
254
276
  }
255
277
 
256
278
  export async function refsCompare(ctx, baseRef, headRef) {
257
279
  apiBase(ctx.config, ctx.parsed);
258
- requireToken();
259
280
  assertGitRef(baseRef, 'base');
260
281
  assertGitRef(headRef, 'head');
261
282
  const baseSha = gitRevParse(ctx.cwd, baseRef);
@@ -359,16 +380,20 @@ export async function prChecks(ctx, opts) {
359
380
  });
360
381
  }
361
382
 
362
- const [statuses, checkRuns] = await Promise.all([
363
- githubFetch(ctx.config, ctx.parsed, repoApiPath(ctx.config, 'commits', sha, 'statuses')),
364
- githubFetch(ctx.config, ctx.parsed, repoApiPath(ctx.config, 'commits', sha, 'check-runs')),
383
+ const statusPath = repoApiPath(ctx.config, 'commits', sha, 'statuses');
384
+ const checkRunsPath = repoApiPath(ctx.config, 'commits', sha, 'check-runs');
385
+ const [statusRecords, checkRunRecords] = await Promise.all([
386
+ githubFetchPaginated(ctx.config, ctx.parsed, statusPath, (body) =>
387
+ Array.isArray(body) ? body : [],
388
+ ),
389
+ githubFetchPaginated(ctx.config, ctx.parsed, checkRunsPath, (body) => body?.check_runs ?? []),
365
390
  ]);
366
- const mappedStatuses = (statuses || []).map((s) => ({
391
+ const mappedStatuses = statusRecords.map((s) => ({
367
392
  context: sanitizeField(s.context),
368
393
  state: normalizeCommitStatusState(s.state),
369
394
  description: sanitizeField(s.description),
370
395
  }));
371
- const mappedCheckRuns = (checkRuns?.check_runs || []).map((run) => ({
396
+ const mappedCheckRuns = checkRunRecords.map((run) => ({
372
397
  context: sanitizeField(run.name),
373
398
  state: normalizeCheckRunState(run),
374
399
  description: sanitizeField(checkRunDescription(run)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remogram/provider-github-api",
3
- "version": "0.1.0-beta.0",
3
+ "version": "0.1.0-beta.1",
4
4
  "description": "GitHub API provider for remogram",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,6 +22,6 @@
22
22
  "node": ">=20"
23
23
  },
24
24
  "dependencies": {
25
- "@remogram/core": "0.1.0-beta.0"
25
+ "@remogram/core": "0.1.0-beta.1"
26
26
  }
27
27
  }