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

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 +34 -8
  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,8 @@ import {
9
11
  gitAheadBehind,
10
12
  ERROR_CODES,
11
13
  forgeError,
14
+ forgeIngestCapabilityFacts,
15
+ apiProviderCommands,
12
16
  } from '@remogram/core';
13
17
 
14
18
  const PUBLIC_GITHUB_HOST = 'github.com';
@@ -42,7 +46,7 @@ const AUTH_CAPABILITIES = [
42
46
  'sync_plan',
43
47
  ];
44
48
 
45
- const STRUCTURED_COMMANDS = AUTH_CAPABILITIES.map((name) => ({ name, implemented: true }));
49
+ const STRUCTURED_COMMANDS = apiProviderCommands();
46
50
 
47
51
  export function githubToken() {
48
52
  if (process.env.GITHUB_TOKEN) return { token: process.env.GITHUB_TOKEN, env: 'GITHUB_TOKEN' };
@@ -149,6 +153,24 @@ export async function githubFetch(config, parsed, path, options = {}) {
149
153
  });
150
154
  }
151
155
 
156
+ const MAX_CHECK_PAGES = 50;
157
+
158
+ export async function githubFetchPaginated(config, parsed, path, slice) {
159
+ const base = apiBase(config, parsed);
160
+ const { token } = requireToken();
161
+ const all = [];
162
+ let url = `${base}${path}`;
163
+ for (let page = 0; page < MAX_CHECK_PAGES && url; page += 1) {
164
+ const { body, headers } = await fetchJsonWithMeta(url, {
165
+ headers: authHeaders(token),
166
+ });
167
+ all.push(...slice(body));
168
+ const linkHeader = headers?.get?.('link') ?? headers?.get?.('Link') ?? null;
169
+ url = parseLinkHeader(linkHeader).next ?? null;
170
+ }
171
+ return all;
172
+ }
173
+
152
174
  export function graphqlEndpoint(config, parsed = {}) {
153
175
  const remoteHost = (parsed.host || configuredHost(config) || '').toLowerCase();
154
176
  if (remoteHost === PUBLIC_GITHUB_HOST) {
@@ -248,14 +270,14 @@ export function providerCapabilities() {
248
270
  check_sources: ['commit_statuses', 'check_runs'],
249
271
  mergeability_confidence: 'derived',
250
272
  host_binding: 'verified_remote_host',
251
- pagination: 'first_page_only',
273
+ pagination: 'supported',
252
274
  write_support: false,
275
+ ...forgeIngestCapabilityFacts(),
253
276
  };
254
277
  }
255
278
 
256
279
  export async function refsCompare(ctx, baseRef, headRef) {
257
280
  apiBase(ctx.config, ctx.parsed);
258
- requireToken();
259
281
  assertGitRef(baseRef, 'base');
260
282
  assertGitRef(headRef, 'head');
261
283
  const baseSha = gitRevParse(ctx.cwd, baseRef);
@@ -359,16 +381,20 @@ export async function prChecks(ctx, opts) {
359
381
  });
360
382
  }
361
383
 
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')),
384
+ const statusPath = repoApiPath(ctx.config, 'commits', sha, 'statuses');
385
+ const checkRunsPath = repoApiPath(ctx.config, 'commits', sha, 'check-runs');
386
+ const [statusRecords, checkRunRecords] = await Promise.all([
387
+ githubFetchPaginated(ctx.config, ctx.parsed, statusPath, (body) =>
388
+ Array.isArray(body) ? body : [],
389
+ ),
390
+ githubFetchPaginated(ctx.config, ctx.parsed, checkRunsPath, (body) => body?.check_runs ?? []),
365
391
  ]);
366
- const mappedStatuses = (statuses || []).map((s) => ({
392
+ const mappedStatuses = statusRecords.map((s) => ({
367
393
  context: sanitizeField(s.context),
368
394
  state: normalizeCommitStatusState(s.state),
369
395
  description: sanitizeField(s.description),
370
396
  }));
371
- const mappedCheckRuns = (checkRuns?.check_runs || []).map((run) => ({
397
+ const mappedCheckRuns = checkRunRecords.map((run) => ({
372
398
  context: sanitizeField(run.name),
373
399
  state: normalizeCheckRunState(run),
374
400
  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.2",
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.2"
26
26
  }
27
27
  }