@remogram/cli 0.1.0-beta.1 → 0.1.0-beta.3

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 +60 -3
  2. package/package.json +7 -7
package/index.js CHANGED
@@ -18,6 +18,9 @@ import {
18
18
  assertGitRemote,
19
19
  getEffectiveIngestMaxBytes,
20
20
  FORGE_INGEST_MAX_BYTES_ENV,
21
+ throwIfStaleHeadByNumber,
22
+ FACT_INVENTORY_PACKET_TYPES,
23
+ forgeFactInventoryPacket,
21
24
  } from '@remogram/core';
22
25
  import { provider as giteaApi } from '@remogram/provider-gitea-api';
23
26
  import { provider as githubApi } from '@remogram/provider-github-api';
@@ -59,6 +62,11 @@ function handleError(err, ctx, asJson) {
59
62
  remoteName: 'origin',
60
63
  repoId: 'unknown/unknown',
61
64
  };
65
+ if (err.staleHeadPacket) {
66
+ output(forgePacket(err.staleHeadPacket.type, baseCtx, err.staleHeadPacket.body, fe), asJson);
67
+ process.exitCode = 1;
68
+ return;
69
+ }
62
70
  output(forgeErrorPacket(baseCtx, fe), asJson);
63
71
  process.exitCode = 1;
64
72
  }
@@ -145,7 +153,7 @@ async function buildDoctorPacket(cwd, providers) {
145
153
  'provider',
146
154
  stubProvider ? 'warn' : 'pass',
147
155
  stubProvider
148
- ? `${config.provider} is not implemented in v1; use an *-api provider`
156
+ ? `${config.provider} is not fully supported in v1; use an *-api provider`
149
157
  : `${config.provider} is registered`,
150
158
  ),
151
159
  );
@@ -330,6 +338,37 @@ export async function runCli(argv, options = {}) {
330
338
  ctx,
331
339
  await provider.refsCompare(ctx, flags.base, flags.head),
332
340
  );
341
+ } else if (group === 'refs' && sub === 'inventory') {
342
+ if (typeof provider.refsInventory !== 'function') {
343
+ throw Object.assign(new Error('refs inventory not implemented for provider'), {
344
+ forgeError: forgeError(
345
+ ERROR_CODES.PROVIDER_UNSUPPORTED,
346
+ 'refs inventory not implemented for provider',
347
+ ),
348
+ });
349
+ }
350
+ packet = forgeFactInventoryPacket(
351
+ FACT_INVENTORY_PACKET_TYPES.REF_INVENTORY,
352
+ ctx,
353
+ await provider.refsInventory(ctx),
354
+ );
355
+ } else if (group === 'cr' && sub === 'inventory') {
356
+ if (typeof provider.crInventory !== 'function') {
357
+ throw Object.assign(new Error('cr inventory not implemented for provider'), {
358
+ forgeError: forgeError(
359
+ ERROR_CODES.PROVIDER_UNSUPPORTED,
360
+ 'cr inventory not implemented for provider',
361
+ ),
362
+ });
363
+ }
364
+ packet = forgeFactInventoryPacket(
365
+ FACT_INVENTORY_PACKET_TYPES.CR_INVENTORY_SLICE,
366
+ ctx,
367
+ await provider.crInventory(ctx, {
368
+ slice_ref: flags.slice_ref,
369
+ limit: parsePositiveInt(flags.limit, '--limit'),
370
+ }),
371
+ );
333
372
  } else if (group === 'pr' && sub === 'view') {
334
373
  const number = parsePositiveInt(flags.number, '--number');
335
374
  if (number == null) {
@@ -337,7 +376,15 @@ export async function runCli(argv, options = {}) {
337
376
  forgeError: forgeError(ERROR_CODES.INVALID_ARGS, '--number required for pr view'),
338
377
  });
339
378
  }
340
- packet = forgePacket(PACKET_TYPES.PR_STATUS, ctx, await provider.prView(ctx, { number }));
379
+ const body = await provider.prView(ctx, { number });
380
+ throwIfStaleHeadByNumber(
381
+ ctx,
382
+ PACKET_TYPES.PR_STATUS,
383
+ body,
384
+ body.head_ref,
385
+ body.head_sha,
386
+ );
387
+ packet = forgePacket(PACKET_TYPES.PR_STATUS, ctx, body);
341
388
  } else if (group === 'pr' && sub === 'checks') {
342
389
  const number = parsePositiveInt(flags.number, '--number');
343
390
  if (number == null && !flags.ref) {
@@ -346,6 +393,16 @@ export async function runCli(argv, options = {}) {
346
393
  });
347
394
  }
348
395
  if (flags.ref) assertGitRef(flags.ref, '--ref');
396
+ if (number != null && !flags.ref) {
397
+ const view = await provider.prView(ctx, { number });
398
+ throwIfStaleHeadByNumber(
399
+ ctx,
400
+ PACKET_TYPES.PR_CHECKS,
401
+ { head_sha: view.head_sha },
402
+ view.head_ref,
403
+ view.head_sha,
404
+ );
405
+ }
349
406
  packet = forgePacket(
350
407
  PACKET_TYPES.PR_CHECKS,
351
408
  ctx,
@@ -371,7 +428,7 @@ export async function runCli(argv, options = {}) {
371
428
  throw Object.assign(new Error(`Unknown command: ${positional.join(' ')}`), {
372
429
  forgeError: forgeError(
373
430
  ERROR_CODES.INVALID_ARGS,
374
- 'Unknown command. Try: provider capabilities, repo status, refs compare, pr view, pr checks, merge plan, sync plan',
431
+ 'Unknown command. Try: provider capabilities, repo status, refs compare, refs inventory, cr inventory, pr view, pr checks, merge plan, sync plan',
375
432
  ),
376
433
  });
377
434
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remogram/cli",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.3",
4
4
  "description": "Remogram forge boundary CLI",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,11 +27,11 @@
27
27
  "node": ">=20"
28
28
  },
29
29
  "dependencies": {
30
- "@remogram/core": "0.1.0-beta.1",
31
- "@remogram/provider-gitea-api": "0.1.0-beta.1",
32
- "@remogram/provider-github-api": "0.1.0-beta.1",
33
- "@remogram/provider-gitlab-api": "0.1.0-beta.1",
34
- "@remogram/provider-gitea-tea": "0.1.0-beta.1",
35
- "@remogram/provider-github-gh": "0.1.0-beta.1"
30
+ "@remogram/core": "0.1.0-beta.3",
31
+ "@remogram/provider-gitea-api": "0.1.0-beta.3",
32
+ "@remogram/provider-github-api": "0.1.0-beta.3",
33
+ "@remogram/provider-gitlab-api": "0.1.0-beta.3",
34
+ "@remogram/provider-gitea-tea": "0.1.0-beta.3",
35
+ "@remogram/provider-github-gh": "0.1.0-beta.3"
36
36
  }
37
37
  }