@theholocron/cli 5.0.0-alpha.596 → 5.0.0-alpha.598

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.
package/README.md CHANGED
@@ -847,7 +847,7 @@ See the [command pages](https://theholocron.dev/holocron/commands/setup-notifica
847
847
 
848
848
  ## Keeping pull request posts in step
849
849
 
850
- - **`holocron sync prs [--provider <name>] [--yes]`** — reads the repository's open pull requests (`source`
850
+ - **`holocron sync prs [--repo <owner/name>]... [--provider <name>] [--yes]`** — reads the open pull requests of every repository that has posts in the forum (`--repo` restricts it; the token must read them all, and a repository it cannot read is one skipped row) (`source`
851
851
  `readPullRequestState`) and the forum with `feeds.prs`, and puts each post's tag, title and first message right with the
852
852
  same `renderPullRequest()` Sentinel's feed uses, archiving the posts of closed or merged pull requests. A tag changed by
853
853
  hand is set back (Discord does not set a pull request's state). Reports a post whose pull request is gone and a key with
package/dist/cli.mjs CHANGED
@@ -2237,7 +2237,11 @@ const syncPrsEntry = {
2237
2237
  description: "Keep the pull request forum's posts in step with GitHub",
2238
2238
  positionals: [],
2239
2239
  options: [],
2240
- skipOptions: ["provider", "yes"],
2240
+ skipOptions: [
2241
+ "provider",
2242
+ "yes",
2243
+ "repo"
2244
+ ],
2241
2245
  supportsDryRun: true
2242
2246
  };
2243
2247
  // src/commands/sync-readme/sync-readme.entry.ts
@@ -4744,6 +4748,24 @@ function startCommandThread(command, deps) {
4744
4748
  }
4745
4749
  };
4746
4750
  }
4751
+ // src/observability/notifications-only-config/notifications-only-config.ts
4752
+ /** The providers a command record needs: the one that posts, and the ones that read this machine's tokens for it. */
4753
+ const KEPT = ["notifications", "credentials"];
4754
+ /**
4755
+ * The config with every provider but the notifications and credentials ones left out, so a plugin loader built from it
4756
+ * imports only the plugins a command record uses. Loading all of them took about five seconds on a cold start, which is
4757
+ * longer than the record may wait; the two it needs take under two. Nothing else of the config changes.
4758
+ *
4759
+ * @param resolved - The resolved config.
4760
+ */
4761
+ function notificationsOnlyConfig(resolved) {
4762
+ const providers = {};
4763
+ for (const key of KEPT) if (resolved.providers[key] !== void 0) providers[key] = resolved.providers[key];
4764
+ return {
4765
+ ...resolved,
4766
+ providers
4767
+ };
4768
+ }
4747
4769
  // src/observability/command-run-deps/command-run-deps.ts
4748
4770
  /** The channel a command run is posted to; the layout declares it (`.holocron/notifications.ts`). */
4749
4771
  const AGENT_LOG_CHANNEL = "agent-log";
@@ -4768,7 +4790,7 @@ function createCommandRunDeps(input) {
4768
4790
  const load = () => loaded ??= loadConfig(input.cwd);
4769
4791
  const notifications = () => providers ??= (async () => {
4770
4792
  const { resolved } = await load();
4771
- const loader = new PluginLoader(resolved, {
4793
+ const loader = new PluginLoader(notificationsOnlyConfig(resolved), {
4772
4794
  repoRoot: input.cwd,
4773
4795
  org: resolveOrg({ org: input.org }, resolved)
4774
4796
  });
@@ -4777,6 +4799,7 @@ function createCommandRunDeps(input) {
4777
4799
  })();
4778
4800
  let thread;
4779
4801
  if (!disabled && !isCommandLogSkipped(input.command)) {
4802
+ if (input.actor.actor === "agent") notifications().catch(() => void 0);
4780
4803
  thread = startCommandThread(input.command, {
4781
4804
  actor: input.actor,
4782
4805
  now: Date.now,
@@ -42240,6 +42263,18 @@ const syncIssuesCommand = {
42240
42263
  })).status === "fail") process.exitCode = 1;
42241
42264
  }
42242
42265
  };
42266
+ // src/pull-request-post/parse-pr-key/parse-pr-key.ts
42267
+ /**
42268
+ * The repository and number a post's key names, the inverse of `prKey()`: `owner/repo#123` gives
42269
+ * `{ repo: "owner/repo", number: 123 }`; any other text gives `undefined`.
42270
+ */
42271
+ function parsePrKey(key) {
42272
+ const match = /^([^/#\s]+\/[^/#\s]+)#(\d+)$/.exec(key ?? "");
42273
+ return match ? {
42274
+ repo: match[1],
42275
+ number: Number(match[2])
42276
+ } : void 0;
42277
+ }
42243
42278
  // src/pull-request-post/pr-key/pr-key.ts
42244
42279
  /** The key a pull request's post is found by: `owner/repo#123`. */
42245
42280
  function prKey(repo, number) {
@@ -42431,8 +42466,9 @@ async function mapInBatches(items, size, fn) {
42431
42466
  }
42432
42467
  // src/commands/sync-prs/run-sync-prs/run-sync-prs.ts
42433
42468
  /**
42434
- * `holocron sync prs` -- keep the pull request forum's posts in step with GitHub (spec `tech-discord-notifications-v2`,
42435
- * step 3, #2853).
42469
+ * `holocron sync prs` -- keep the pull request forum's posts in step with GitHub, for every repository that has posts
42470
+ * in it (spec `tech-discord-notifications-v2`, step 3, #2853). The repositories are this one and every one a post's
42471
+ * key names (`--repo` narrows them); a repository whose pull requests cannot be read is one skipped row.
42436
42472
  *
42437
42473
  * Sentinel's feed writes a post on each webhook delivery; a missed delivery, an outage or a hand-changed tag leaves a
42438
42474
  * post wrong until the next event. This reads the repository's open pull requests, each as `Source.readPullRequestState`
@@ -42489,9 +42525,9 @@ async function runSyncPrs(input) {
42489
42525
  const source = loader.has("source") ? loader.get("source") : void 0;
42490
42526
  if (!source) return stop("skip", "no `source` provider to read pull requests from");
42491
42527
  if (!source.listPullRequests || !source.readPullRequestState) return stop("fail", `the \`${source.providerName}\` provider cannot read a pull request's state`);
42492
- const repo = input.context.repo ?? (input.context.org && input.loaded.resolved.name ? `${input.context.org}/${input.loaded.resolved.name}` : void 0);
42493
- if (!repo) return stop("fail", "cannot tell which repository this is; run it from a checkout with a name and an org");
42494
- if (exclude?.repos?.includes(repo)) return stop("skip", `\`feeds.prs.exclude\` leaves ${repo} out`);
42528
+ const own = input.context.repo ?? (input.context.org && input.loaded.resolved.name ? `${input.context.org}/${input.loaded.resolved.name}` : void 0);
42529
+ if (!own) return stop("fail", "cannot tell which repository this is; run it from a checkout with a name and an org");
42530
+ const excludedRepos = new Set(exclude?.repos ?? []);
42495
42531
  const excludedAuthors = new Set((exclude?.authors ?? []).map((a) => a.toLowerCase()));
42496
42532
  const counts = {
42497
42533
  updated: 0,
@@ -42499,51 +42535,80 @@ async function runSyncPrs(input) {
42499
42535
  unchanged: 0,
42500
42536
  reported: 0,
42501
42537
  failed: 0,
42502
- left: 0
42538
+ left: 0,
42539
+ skipped: 0
42503
42540
  };
42504
42541
  let posts;
42505
- let open;
42506
42542
  let required;
42507
42543
  try {
42508
42544
  if (aggregatePoster({ ci: input.loaded.resolved.ci }) === "none") required = (await resolveRequiredChecks({
42509
42545
  source,
42510
42546
  config: input.loaded.resolved
42511
42547
  })).required;
42512
- [posts, open] = await Promise.all([notifications.listDiscussions(channel), source.listPullRequests("open", repo)]);
42548
+ posts = await notifications.listDiscussions(channel);
42513
42549
  } catch (err) {
42514
42550
  return stop("fail", `reading the pull requests and #${channel}: ${describeError(err)}`);
42515
42551
  }
42516
- const prefix = prKey(repo, 0).slice(0, -1);
42517
- const mine = /* @__PURE__ */ new Map();
42552
+ const named = input.repos && input.repos.length > 0 ? new Set(input.repos) : void 0;
42553
+ const byRepo = /* @__PURE__ */ new Map();
42554
+ for (const repo of named ?? [own]) byRepo.set(repo, /* @__PURE__ */ new Map());
42518
42555
  for (const post of posts) {
42519
- const rest = post.key?.startsWith(prefix) ? post.key.slice(prefix.length) : "";
42520
- if (/^\d+$/.test(rest)) mine.set(Number(rest), post);
42521
- }
42522
- for (const post of mine.values()) if (post.duplicates) {
42556
+ const parsed = parsePrKey(post.key);
42557
+ if (!parsed || named && !named.has(parsed.repo)) continue;
42558
+ const numbers = byRepo.get(parsed.repo) ?? /* @__PURE__ */ new Map();
42559
+ numbers.set(parsed.number, post);
42560
+ byRepo.set(parsed.repo, numbers);
42561
+ }
42562
+ for (const repo of excludedRepos) byRepo.delete(repo);
42563
+ if (byRepo.size === 0) return stop("skip", "`feeds.prs.exclude` leaves every repository out");
42564
+ const repos = [...byRepo.keys()].sort();
42565
+ for (const mine of byRepo.values()) for (const post of mine.values()) if (post.duplicates) {
42523
42566
  counts.reported++;
42524
42567
  row("skip", post.key, `${post.duplicates} more post(s) carry this key; \`holocron cleanup posts\` removes them`);
42525
42568
  }
42526
42569
  const finished = (post) => post.closed && (post.state === "merged" || post.state === "closed");
42527
- const numbers = [.../* @__PURE__ */ new Set([...open.map((p) => p.number), ...mine.keys()])].filter((n) => {
42528
- if (open.some((p) => p.number === n) || retainDays !== void 0) return true;
42529
- if (finished(mine.get(n))) {
42530
- counts.unchanged++;
42531
- return false;
42532
- }
42533
- return true;
42534
- });
42535
42570
  let limited = false;
42536
- const looked = await mapInBatches(numbers, BATCH, async (number) => {
42571
+ const targets = [];
42572
+ for (const repo of repos) {
42573
+ const mine = byRepo.get(repo);
42574
+ if (limited) {
42575
+ counts.left += mine.size;
42576
+ continue;
42577
+ }
42578
+ let open;
42579
+ try {
42580
+ open = await source.listPullRequests("open", repo);
42581
+ } catch (err) {
42582
+ if (rateLimitedFor(err) !== void 0) {
42583
+ limited = true;
42584
+ counts.left += mine.size;
42585
+ continue;
42586
+ }
42587
+ const unreadable = err instanceof ProviderApiError && (err.status === 404 || err.status === 403);
42588
+ counts.skipped += unreadable ? 1 : 0;
42589
+ counts.failed += unreadable ? 0 : 1;
42590
+ row(unreadable ? "skip" : "fail", repo, unreadable ? `its pull requests cannot be read with this token (${describeError(err)}); its posts are left alone` : `reading its pull requests: ${describeError(err)}`);
42591
+ continue;
42592
+ }
42593
+ if (repo !== own && (open.length > 0 || mine.size > 0)) row("skip", repo, "its required checks are not read; each pull request's CI is the aggregate check's");
42594
+ const openNumbers = new Set(open.map((p) => p.number));
42595
+ for (const number of /* @__PURE__ */ new Set([...openNumbers, ...mine.keys()])) if (!openNumbers.has(number) && retainDays === void 0 && finished(mine.get(number))) counts.unchanged++;
42596
+ else targets.push({
42597
+ repo,
42598
+ number,
42599
+ post: mine.get(number)
42600
+ });
42601
+ }
42602
+ const looked = await mapInBatches(targets, BATCH, async ({ repo, number, post }) => {
42537
42603
  const key = prKey(repo, number);
42538
42604
  if (limited) return { kind: "left" };
42539
42605
  try {
42540
- const state = await source.readPullRequestState(number, repo, required);
42606
+ const state = await source.readPullRequestState(number, repo, repo === own ? required : void 0);
42541
42607
  if (!state) return {
42542
42608
  kind: "gone",
42543
42609
  key
42544
42610
  };
42545
42611
  if (excludedAuthors.has(state.author.toLowerCase())) return { kind: "excluded" };
42546
- const post = mine.get(number);
42547
42612
  if (!post) return {
42548
42613
  kind: "no-post",
42549
42614
  key
@@ -42642,7 +42707,7 @@ async function runSyncPrs(input) {
42642
42707
  row("fail", w.key, describeError(err));
42643
42708
  }
42644
42709
  if (counts.left > 0) row("skip", `stopped: a service is rate limiting; ${counts.left} post(s) are left for the next run`);
42645
- row(counts.failed > 0 ? "fail" : "ok", `#${channel}: updated ${counts.updated}, deleted ${counts.deleted}, unchanged ${counts.unchanged}, reported ${counts.reported}, failed ${counts.failed}, left ${counts.left}`);
42710
+ row(counts.failed > 0 ? "fail" : "ok", `#${channel}: updated ${counts.updated}, deleted ${counts.deleted}, unchanged ${counts.unchanged}, reported ${counts.reported}, failed ${counts.failed}, left ${counts.left}${counts.skipped > 0 ? `, repositories skipped ${counts.skipped}` : ""}`);
42646
42711
  return {
42647
42712
  status: counts.failed > 0 ? "fail" : "ok",
42648
42713
  counts
@@ -42655,6 +42720,10 @@ const syncPrsCommand = {
42655
42720
  builder: (y) => y.option("provider", {
42656
42721
  type: "string",
42657
42722
  describe: "The `notifications` provider to write through, when several are configured"
42723
+ }).option("repo", {
42724
+ type: "string",
42725
+ array: true,
42726
+ describe: "Only this repository (owner/name); repeat for more. Default: every repository that has posts"
42658
42727
  }).option("yes", {
42659
42728
  type: "boolean",
42660
42729
  describe: "Change the posts without asking (a scheduled run needs it)"
@@ -42673,6 +42742,7 @@ const syncPrsCommand = {
42673
42742
  org: resolveOrg(argv, loaded.resolved)
42674
42743
  },
42675
42744
  ...argv.provider ? { provider: argv.provider } : {},
42745
+ ...argv.repo && argv.repo.length > 0 ? { repos: argv.repo } : {},
42676
42746
  ...argv.yes ? { yes: true } : {}
42677
42747
  })).status === "fail") process.exitCode = 1;
42678
42748
  }