@theholocron/cli 5.0.0-alpha.597 → 5.0.0-alpha.599
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 +1 -1
- package/dist/cli.mjs +111 -41
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +8 -0
- package/dist/index.mjs +13 -1
- package/package.json +6 -6
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
|
|
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: [
|
|
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,9 +4748,29 @@ 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";
|
|
4772
|
+
/** The name of the channel's webhook secret, less the `HOLOCRON_` prefix: `NOTIFY_WEBHOOK_AGENT_LOG`. */
|
|
4773
|
+
const AGENT_LOG_WEBHOOK_NAME = `NOTIFY_WEBHOOK_${AGENT_LOG_CHANNEL.toUpperCase().replaceAll("-", "_")}`;
|
|
4750
4774
|
/** Whether a provider has the three methods a command thread needs. */
|
|
4751
4775
|
function canThread$1(provider) {
|
|
4752
4776
|
return typeof provider.sendWithId === "function" && typeof provider.startThread === "function" && typeof provider.postToThread === "function";
|
|
@@ -4756,8 +4780,8 @@ function canThread$1(provider) {
|
|
|
4756
4780
|
* while the command runs. The config is read at most once, and only when the recorder or the thread asks for a setting
|
|
4757
4781
|
* (a run that is left out for CI, test or the skip list never does); the plugin loader is built only when a post or a
|
|
4758
4782
|
* thread is due, so a human run in the default modes never builds one. The post goes to every configured
|
|
4759
|
-
* `notifications` provider through its `send`,
|
|
4760
|
-
*
|
|
4783
|
+
* `notifications` provider through its `send`, given the channel's webhook (`HOLOCRON_NOTIFY_WEBHOOK_AGENT_LOG`, read through `resolveValue()`); with none, nothing
|
|
4784
|
+
* is sent. A thread is opened on the first provider that has `sendWithId`,
|
|
4761
4785
|
* `startThread` and `postToThread`, and the CLI logger's lines are copied into it through the log tap. Provider tokens
|
|
4762
4786
|
* given with `--token` are not passed on.
|
|
4763
4787
|
*/
|
|
@@ -4768,7 +4792,7 @@ function createCommandRunDeps(input) {
|
|
|
4768
4792
|
const load = () => loaded ??= loadConfig(input.cwd);
|
|
4769
4793
|
const notifications = () => providers ??= (async () => {
|
|
4770
4794
|
const { resolved } = await load();
|
|
4771
|
-
const loader = new PluginLoader(resolved, {
|
|
4795
|
+
const loader = new PluginLoader(notificationsOnlyConfig(resolved), {
|
|
4772
4796
|
repoRoot: input.cwd,
|
|
4773
4797
|
org: resolveOrg({ org: input.org }, resolved)
|
|
4774
4798
|
});
|
|
@@ -4777,6 +4801,7 @@ function createCommandRunDeps(input) {
|
|
|
4777
4801
|
})();
|
|
4778
4802
|
let thread;
|
|
4779
4803
|
if (!disabled && !isCommandLogSkipped(input.command)) {
|
|
4804
|
+
if (input.actor.actor === "agent") notifications().catch(() => void 0);
|
|
4780
4805
|
thread = startCommandThread(input.command, {
|
|
4781
4806
|
actor: input.actor,
|
|
4782
4807
|
now: Date.now,
|
|
@@ -4798,7 +4823,9 @@ function createCommandRunDeps(input) {
|
|
|
4798
4823
|
thread,
|
|
4799
4824
|
mode: async () => (await load()).resolved.notifications?.commandLog ?? "agents",
|
|
4800
4825
|
post: async (line) => {
|
|
4801
|
-
|
|
4826
|
+
const url = resolveValue$2([AGENT_LOG_WEBHOOK_NAME], void 0, { prefix: PREFIX$1 });
|
|
4827
|
+
if (!url) return;
|
|
4828
|
+
await Promise.all((await notifications()).map((provider) => provider.send(url, line)));
|
|
4802
4829
|
}
|
|
4803
4830
|
};
|
|
4804
4831
|
}
|
|
@@ -18129,14 +18156,10 @@ function workflowNameProblems(text) {
|
|
|
18129
18156
|
});
|
|
18130
18157
|
}
|
|
18131
18158
|
// src/commands/notifications-workflow-checks/notifications-workflow-checks.ts
|
|
18132
|
-
/** Where the workflow that posts failed runs and
|
|
18159
|
+
/** Where the workflow that posts failed runs and deploys lives, on the default branch. */
|
|
18133
18160
|
const NOTIFICATIONS_WORKFLOW_PATH = ".github/workflows/platform.notifications.yml";
|
|
18134
|
-
/** The webhook secrets the workflow posts through: failed runs
|
|
18135
|
-
const WEBHOOK_SECRETS = [
|
|
18136
|
-
"HOLOCRON_NOTIFY_WEBHOOK_ALERTS",
|
|
18137
|
-
"HOLOCRON_NOTIFY_WEBHOOK_DEPLOYS",
|
|
18138
|
-
"HOLOCRON_NOTIFY_WEBHOOK_RELEASES"
|
|
18139
|
-
];
|
|
18161
|
+
/** The webhook secrets the workflow posts through: failed runs and deploys. A release is announced by the release job. */
|
|
18162
|
+
const WEBHOOK_SECRETS = ["HOLOCRON_NOTIFY_WEBHOOK_ALERTS", "HOLOCRON_NOTIFY_WEBHOOK_DEPLOYS"];
|
|
18140
18163
|
const PRESENT_ID = "notifications-workflow";
|
|
18141
18164
|
const PRESENT_TITLE = "Notifications workflow is on the default branch";
|
|
18142
18165
|
const WIRED_ID = "notifications-workflow-wiring";
|
|
@@ -18146,10 +18169,10 @@ const NAMES_TITLE = "Notifications workflow lists only task ids";
|
|
|
18146
18169
|
const shown$3 = (s) => sanitizeDetail(s);
|
|
18147
18170
|
const upper = (names) => new Set(names.map((n) => n.toUpperCase()));
|
|
18148
18171
|
/**
|
|
18149
|
-
* The steps of `doctor notifications` that check the workflow which posts failed runs and
|
|
18172
|
+
* The steps of `doctor notifications` that check the workflow which posts failed runs and deploys: the file is on
|
|
18150
18173
|
* the default branch, and the `HOLOCRON_NOTIFY_*` secrets it reads are the ones the layout fills (so every channel it
|
|
18151
18174
|
* writes to is in the layout, and a channel the layout wires for it is one it posts to). Read-only. No rows when the
|
|
18152
|
-
* layout fills
|
|
18175
|
+
* layout fills neither the alerts nor the deploys webhook, because then nothing is meant to reach those channels.
|
|
18153
18176
|
*/
|
|
18154
18177
|
async function notificationsWorkflowChecks(input) {
|
|
18155
18178
|
const filled = upper(layoutSecretNames(input.layout));
|
|
@@ -18182,7 +18205,7 @@ async function notificationsWorkflowChecks(input) {
|
|
|
18182
18205
|
];
|
|
18183
18206
|
}
|
|
18184
18207
|
if (text === void 0) return [
|
|
18185
|
-
resultRow(PRESENT_ID, PRESENT_TITLE, [`${NOTIFICATIONS_WORKFLOW_PATH} is missing: without it a failed run or a
|
|
18208
|
+
resultRow(PRESENT_ID, PRESENT_TITLE, [`${NOTIFICATIONS_WORKFLOW_PATH} is missing: without it a failed run or a deploy posts nothing to Discord`], ""),
|
|
18186
18209
|
skipRow$1(WIRED_ID, WIRED_TITLE, "not checked: the workflow is missing"),
|
|
18187
18210
|
skipRow$1(NAMES_ID, NAMES_TITLE, "not checked: the workflow is missing")
|
|
18188
18211
|
];
|
|
@@ -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
|
|
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
|
|
42493
|
-
if (!
|
|
42494
|
-
|
|
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
|
-
|
|
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
|
|
42517
|
-
const
|
|
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
|
|
42520
|
-
if (
|
|
42521
|
-
|
|
42522
|
-
|
|
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
|
|
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
|
}
|