@theholocron/cli 5.0.0-alpha.405 → 5.0.0-alpha.407
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 +168 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/{index-C0aDee00.d.mts → index-Dp4VbR6j.d.mts} +14 -1
- package/dist/index.d.mts +2 -2
- package/dist/plugin/capabilities.d.mts +2 -2
- package/dist/presets.d.mts +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -659,7 +659,7 @@ Channels fed by the error tracker add `feeds: { errors: true }` and a layout `re
|
|
|
659
659
|
|
|
660
660
|
A channel with `kind: "forum"` is a forum, with `tags` (each a `name`, an `emoji` and whether it is `moderated`); `setup` adds and corrects the tags but never removes one, and a text channel of the same name must be deleted first, since neither kind can become the other. A forum takes no `webhook` and none of the webhook feeds (`monitoring`, `errors`); its one feed is `feeds: { prs: true }`, the pull-request feed, where Sentinel keeps one post per pull request tagged with its state. The object form `feeds: { prs: { exclude: { repos?: ["owner/name"], authors?: ["login"] } } }` leaves some pull requests out. `feeds.prs` belongs to a forum (a text channel with it is refused) and the forum's `tags` must hold all eight states, `draft`, `conflicts`, `failing`, `changes requested`, `ready`, `waiting`, `merged` and `closed`, or `setup` refuses the layout. `setup` does nothing more for it; `doctor notifications` checks that the forum exists, has those tags and that the bot can start posts and manage threads in it (`ServerInspection` `botThreads`, filled in by the Discord provider after the forum's own permission overwrites). `defaultReaction` is the emoji Discord offers on every post (its Get Started step "Set a default reaction for posts"); Discord allows only one, so `starterReactions` lists more (`["👍", "👎", "❓"]` for approve, disapprove, question) that the bot adds to the first message of each post `specs sync` makes. Existing posts are left alone, a reaction the bot cannot add is skipped, and `doctor notifications` checks `defaultReaction`. Unicode emoji only.
|
|
661
661
|
|
|
662
|
-
`holocron specs sync [--channel <forum>] [--files <paths...>] [--pr <number>] [--refresh] [--refresh-origin] [--refresh-titles] [--withdraw] [--notify]` keeps one forum post per ADR and spec in step with the files: it makes the post (titled with the document's own title, tagged with the file's status), writes its address into the file as `discussion.url`, and turns a gatekeeper's retag into an edit of the file's `status:` line in the working tree for a pull request. `--files` syncs only those files and `--pr` names a pull request on their posts, for a pull request that is still open. `--refresh-origin` is a one-off repair: it rewrites the `PR:` line of existing posts to the one the current rule names (the optional `prLine` of `DiscussionPatch`, and of `DiscussionPost`), and nothing else in them. `--refresh-titles` is the same kind of one-off repair for the title: it renames each existing post whose title differs from the current rule's (the optional `title` of `DiscussionPatch`, and of `DiscussionPost`) and changes nothing else; a rate limit stops it cleanly, reports how many documents are left, and the next run continues. The id that opens a post is a link to the file on the default branch (`repo.defaultBranch`, else `HEAD`) once the file is there, and plain text while `--pr` names an open pull request; the normal sync rewrites a post's id line (and only that line) whenever it is not the one the rule gives and no `--pr` is given, which covers a file that moved and a post made while its pull request was open, so it needs no extra request when every post is right and `--refresh` is no longer needed for it. `--refresh` runs the `PR:`, title and id-link repairs in one pass (the id link is the optional `idLine` of `DiscussionPatch`, and of `DiscussionPost`, which changes only the message's first line); `--refresh-origin` and `--refresh-titles` still do only their own. `--withdraw` (with `--files`, on the base branch) tags the posts of a pull request closed unmerged `withdrawn` and closes them; `withdrawn` is a tag only, never a file `status:`, and the next sync puts the file's own status back. It cannot be combined with `--refresh`, `--refresh-origin` or `--refresh-titles`. `--dry-run` previews it. The posts behind it are also usable for other keys, such as a pull request (`owner/repo#123`, the state a tag name): `DiscussionPatch.body` replaces the first message's text (the provider keeps its footer), and the optional `Notifications` methods `postDiscussionMessage(channel, key, content, { quiet })` (a closed post is unarchived, written to and closed again), `readDiscussionMessages(channel, key, limit)` (text, newest first, 50 by default) and `dedupeDiscussion(channel, key)` (keeps the oldest post of the key, deletes the rest, returns how many) append to, read and repair a post. See the [`specs sync` page](https://docs.theholocron.dev/holocron/commands/specs-sync/).
|
|
662
|
+
`holocron specs sync [--channel <forum>] [--files <paths...>] [--pr <number>] [--refresh] [--refresh-origin] [--refresh-titles] [--withdraw] [--notify]` keeps one forum post per ADR and spec in step with the files: it makes the post (titled with the document's own title, tagged with the file's status), writes its address into the file as `discussion.url`, and turns a gatekeeper's retag into an edit of the file's `status:` line in the working tree for a pull request. `--files` syncs only those files and `--pr` names a pull request on their posts, for a pull request that is still open. `--refresh-origin` is a one-off repair: it rewrites the `PR:` line of existing posts to the one the current rule names (the optional `prLine` of `DiscussionPatch`, and of `DiscussionPost`), and nothing else in them. `--refresh-titles` is the same kind of one-off repair for the title: it renames each existing post whose title differs from the current rule's (the optional `title` of `DiscussionPatch`, and of `DiscussionPost`) and changes nothing else; a rate limit stops it cleanly, reports how many documents are left, and the next run continues. The id that opens a post is a link to the file on the default branch (`repo.defaultBranch`, else `HEAD`) once the file is there, and plain text while `--pr` names an open pull request; the normal sync rewrites a post's id line (and only that line) whenever it is not the one the rule gives and no `--pr` is given, which covers a file that moved and a post made while its pull request was open, so it needs no extra request when every post is right and `--refresh` is no longer needed for it. `--refresh` runs the `PR:`, title and id-link repairs in one pass (the id link is the optional `idLine` of `DiscussionPatch`, and of `DiscussionPost`, which changes only the message's first line); `--refresh-origin` and `--refresh-titles` still do only their own. `--withdraw` (with `--files`, on the base branch) tags the posts of a pull request closed unmerged `withdrawn` and closes them; `withdrawn` is a tag only, never a file `status:`, and the next sync puts the file's own status back. It cannot be combined with `--refresh`, `--refresh-origin` or `--refresh-titles`. `--dry-run` previews it. The posts behind it are also usable for other keys, such as a pull request (`owner/repo#123`, the state a tag name): `DiscussionPatch.body` replaces the first message's text (the provider keeps its footer), and the optional `Notifications` methods `postDiscussionMessage(channel, key, content, { quiet })` (a closed post is unarchived, written to and closed again), `readDiscussionMessages(channel, key, limit)` (text, newest first, 50 by default) and `dedupeDiscussion(channel, key)` (keeps the oldest post of the key, deletes the rest, returns how many) append to, read and repair a post, and `duplicateDiscussions(channel)` lists the keys with more than one post without deleting: `holocron notifications dedupe [channel] [--provider <name>] [--yes]` uses the two to clear duplicates that are already there (the forum with `feeds.prs` by default; `--dry-run` previews it). See the [`specs sync` page](https://docs.theholocron.dev/holocron/commands/specs-sync/).
|
|
663
663
|
|
|
664
664
|
Pinned messages are declared under the provider's `layout` as `pinned: [{ channel, content }]` or `pinned: [{ channel, file }]` (`channel` is a channel in the layout, `content` up to 2000 characters, `file` a text file in the repository, such as `.holocron/pinned/rules.md`, whose contents are the message and win over a hand edit; `doctor notifications` reports the drift); the layout is the whole set of messages the bot has pinned in those channels.
|
|
665
665
|
|
package/dist/cli.mjs
CHANGED
|
@@ -767,6 +767,7 @@ const COMMAND_CONTEXTS = {
|
|
|
767
767
|
"notifications link": "workspace",
|
|
768
768
|
"notifications create-server": "workspace",
|
|
769
769
|
"notifications sync-roles": "workspace",
|
|
770
|
+
"notifications dedupe": "workspace",
|
|
770
771
|
"specs sync": "workspace",
|
|
771
772
|
"project reconcile": "workspace",
|
|
772
773
|
"doctor all": "workspace",
|
|
@@ -2388,6 +2389,14 @@ const notificationsCreateServerEntry = {
|
|
|
2388
2389
|
],
|
|
2389
2390
|
supportsDryRun: true
|
|
2390
2391
|
};
|
|
2392
|
+
// src/commands/notifications-dedupe/notifications-dedupe.entry.ts
|
|
2393
|
+
const notificationsDedupeEntry = {
|
|
2394
|
+
name: "notifications dedupe",
|
|
2395
|
+
description: "Delete the extra posts of a forum that has more than one post for the same key",
|
|
2396
|
+
positionals: [],
|
|
2397
|
+
skipOptions: ["yes", "provider"],
|
|
2398
|
+
supportsDryRun: true
|
|
2399
|
+
};
|
|
2391
2400
|
// src/commands/notifications-link/notifications-link.entry.ts
|
|
2392
2401
|
const notificationsLinkEntry = {
|
|
2393
2402
|
name: "notifications link",
|
|
@@ -2631,6 +2640,7 @@ const registry = createCommandRegistry([
|
|
|
2631
2640
|
notificationsCreateServerEntry,
|
|
2632
2641
|
notificationsLinkEntry,
|
|
2633
2642
|
notificationsSyncRolesEntry,
|
|
2643
|
+
notificationsDedupeEntry,
|
|
2634
2644
|
{
|
|
2635
2645
|
name: "specs sync",
|
|
2636
2646
|
description: "Keep each ADR and spec in step with a post in a forum channel",
|
|
@@ -15068,6 +15078,163 @@ const notificationsCreateServerCommand = {
|
|
|
15068
15078
|
})).status === "fail") process.exitCode = 1;
|
|
15069
15079
|
}
|
|
15070
15080
|
};
|
|
15081
|
+
// src/commands/notifications-dedupe/notifications-dedupe.ts
|
|
15082
|
+
/**
|
|
15083
|
+
* `holocron notifications dedupe` — delete the extra posts of a forum that has more than one post for the same key.
|
|
15084
|
+
*
|
|
15085
|
+
* Two deliveries that race (Sentinel's pull-request feed on serverless instances, #2032) can each make the post for one
|
|
15086
|
+
* pull request. This reads the forum afresh, lists every key with more than one post, and for each keeps the oldest
|
|
15087
|
+
* post and deletes the rest. It deletes threads, so it asks first unless `--dry-run` or `--yes` (without a terminal it
|
|
15088
|
+
* refuses instead). Idempotent: a second run finds nothing. A key that fails is reported and the run goes on.
|
|
15089
|
+
*/
|
|
15090
|
+
/** The provider that can list the keys with more than one post and delete the extras. */
|
|
15091
|
+
function pickDeduper(providers, wanted) {
|
|
15092
|
+
return pickProvider(providers, wanted, (p) => typeof p.duplicateDiscussions === "function" && typeof p.dedupeDiscussion === "function", {
|
|
15093
|
+
infinitive: "de-duplicate forum posts",
|
|
15094
|
+
gerund: "de-duplicating forum posts"
|
|
15095
|
+
});
|
|
15096
|
+
}
|
|
15097
|
+
/** The forum to repair when none is named: the layout's one forum with `feeds.prs`, or why there is not one. */
|
|
15098
|
+
function defaultForum(layout) {
|
|
15099
|
+
const fed = (layout?.categories ?? []).flatMap((cat) => cat.channels ?? []).filter((channel) => channel.feeds?.prs).map((channel) => channel.name);
|
|
15100
|
+
if (fed.length === 1) return { name: fed[0] };
|
|
15101
|
+
return { problem: fed.length === 0 ? "no forum in the layout has `feeds.prs`; name the forum to repair" : `several forums have \`feeds.prs\` (${fed.join(", ")}); name the forum to repair` };
|
|
15102
|
+
}
|
|
15103
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
15104
|
+
async function runNotificationsDedupe(input) {
|
|
15105
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
15106
|
+
const logger = input.logger ?? getLogger();
|
|
15107
|
+
/* v8 ignore next -- the real loader is only built outside tests, which always inject one */
|
|
15108
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
15109
|
+
await loader.load();
|
|
15110
|
+
assertPluginsResolvable$1(loader, "notifications dedupe");
|
|
15111
|
+
const dryRun = input.context.dryRun ?? false;
|
|
15112
|
+
const report = {
|
|
15113
|
+
status: "ok",
|
|
15114
|
+
duplicates: [],
|
|
15115
|
+
deleted: 0,
|
|
15116
|
+
failures: []
|
|
15117
|
+
};
|
|
15118
|
+
const refuse = (message) => {
|
|
15119
|
+
print(` ${style.fail(message)}`);
|
|
15120
|
+
print("");
|
|
15121
|
+
print(style.header("0 ok, 1 fail, 0 skipped"));
|
|
15122
|
+
logger.warn({ reason: message }, "notifications dedupe");
|
|
15123
|
+
return {
|
|
15124
|
+
...report,
|
|
15125
|
+
status: "fail",
|
|
15126
|
+
message
|
|
15127
|
+
};
|
|
15128
|
+
};
|
|
15129
|
+
let notifications;
|
|
15130
|
+
try {
|
|
15131
|
+
notifications = pickDeduper(notificationProviders(loader), input.provider);
|
|
15132
|
+
} catch (err) {
|
|
15133
|
+
return refuse(errorMessage(err));
|
|
15134
|
+
}
|
|
15135
|
+
let channel = input.channel;
|
|
15136
|
+
if (!channel) {
|
|
15137
|
+
const forum = defaultForum(notifications.layout);
|
|
15138
|
+
if ("problem" in forum) return refuse(forum.problem);
|
|
15139
|
+
channel = forum.name;
|
|
15140
|
+
}
|
|
15141
|
+
report.channel = channel;
|
|
15142
|
+
try {
|
|
15143
|
+
report.duplicates = await notifications.duplicateDiscussions(channel);
|
|
15144
|
+
} catch (err) {
|
|
15145
|
+
return refuse(`could not read #${channel}: ${errorMessage(err)}`);
|
|
15146
|
+
}
|
|
15147
|
+
const extra = report.duplicates.reduce((sum, d) => sum + d.extra, 0);
|
|
15148
|
+
if (report.duplicates.length === 0) {
|
|
15149
|
+
print(` ${style.success(`#${channel}: no key has more than one post`)}`);
|
|
15150
|
+
print("");
|
|
15151
|
+
print(style.header("1 ok, 0 fail, 0 skipped"));
|
|
15152
|
+
return report;
|
|
15153
|
+
}
|
|
15154
|
+
for (const { key, extra: n } of report.duplicates) print(` ${style.skip(`${key}: ${plural(n, "extra post")}`)}`);
|
|
15155
|
+
if (dryRun) {
|
|
15156
|
+
print("");
|
|
15157
|
+
print(style.header(`0 ok, 0 fail, ${report.duplicates.length} skipped (would delete ${plural(extra, "post")} from #${channel})`));
|
|
15158
|
+
return {
|
|
15159
|
+
...report,
|
|
15160
|
+
status: "dry-run"
|
|
15161
|
+
};
|
|
15162
|
+
}
|
|
15163
|
+
if (!input.yes) {
|
|
15164
|
+
if (!(input.interactive ?? Boolean(process.stdin.isTTY))) throw new NonInteractiveError(`\`notifications dedupe\` deletes ${plural(extra, "post")} from #${channel}; pass --yes to run it without asking, or --dry-run to preview`);
|
|
15165
|
+
if (!await (input.confirm ?? ((message) => confirm({
|
|
15166
|
+
message,
|
|
15167
|
+
default: false
|
|
15168
|
+
})))(`Delete ${plural(extra, "post")} from #${channel}, keeping the oldest post of each key?`)) {
|
|
15169
|
+
print(` ${style.skip("cancelled; nothing was deleted")}`);
|
|
15170
|
+
return {
|
|
15171
|
+
...report,
|
|
15172
|
+
status: "cancelled"
|
|
15173
|
+
};
|
|
15174
|
+
}
|
|
15175
|
+
}
|
|
15176
|
+
let ok = 0;
|
|
15177
|
+
for (const { key } of report.duplicates) try {
|
|
15178
|
+
const deleted = await notifications.dedupeDiscussion(channel, key);
|
|
15179
|
+
report.deleted += deleted;
|
|
15180
|
+
ok++;
|
|
15181
|
+
print(` ${style.success(`${key}: deleted ${plural(deleted, "post")}`)}`);
|
|
15182
|
+
} catch (err) {
|
|
15183
|
+
const message = errorMessage(err);
|
|
15184
|
+
report.failures.push({
|
|
15185
|
+
key,
|
|
15186
|
+
message
|
|
15187
|
+
});
|
|
15188
|
+
print(` ${style.fail(`${key}: ${message}`)}`);
|
|
15189
|
+
}
|
|
15190
|
+
if (report.failures.length > 0) report.status = "fail";
|
|
15191
|
+
print("");
|
|
15192
|
+
print(style.header(`${ok} ok, ${report.failures.length} fail, 0 skipped`));
|
|
15193
|
+
logger.info({
|
|
15194
|
+
provider: notifications.providerName,
|
|
15195
|
+
channel,
|
|
15196
|
+
keys: report.duplicates.length,
|
|
15197
|
+
deleted: report.deleted,
|
|
15198
|
+
failures: report.failures.length,
|
|
15199
|
+
status: report.status
|
|
15200
|
+
}, "notifications dedupe");
|
|
15201
|
+
return report;
|
|
15202
|
+
}
|
|
15203
|
+
// src/commands/notifications-dedupe/notifications-dedupe.args.ts
|
|
15204
|
+
const notificationsDedupeArgs = (y) => y.positional("channel", {
|
|
15205
|
+
type: "string",
|
|
15206
|
+
describe: "The forum to repair (default: the forum with `feeds.prs`)"
|
|
15207
|
+
}).option("provider", {
|
|
15208
|
+
type: "string",
|
|
15209
|
+
describe: "Which notifications provider, when several can de-duplicate posts"
|
|
15210
|
+
}).option("yes", {
|
|
15211
|
+
type: "boolean",
|
|
15212
|
+
describe: "Delete without asking (required without a terminal)"
|
|
15213
|
+
});
|
|
15214
|
+
// src/commands/notifications-dedupe/notifications-dedupe.command.ts
|
|
15215
|
+
const notificationsDedupeCommand = {
|
|
15216
|
+
command: "dedupe [channel]",
|
|
15217
|
+
describe: "Delete the extra posts of a forum that has more than one post for the same key",
|
|
15218
|
+
builder: notificationsDedupeArgs,
|
|
15219
|
+
handler: async (argv) => {
|
|
15220
|
+
const tokens = tokenContext$1(argv.token);
|
|
15221
|
+
if (!tokens) return;
|
|
15222
|
+
const loaded = await loadConfig(argv.cwd);
|
|
15223
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
15224
|
+
if ((await runNotificationsDedupe({
|
|
15225
|
+
loaded,
|
|
15226
|
+
context: {
|
|
15227
|
+
repoRoot: argv.cwd,
|
|
15228
|
+
dryRun: argv.dryRun,
|
|
15229
|
+
...tokens,
|
|
15230
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
15231
|
+
},
|
|
15232
|
+
...argv.channel ? { channel: argv.channel } : {},
|
|
15233
|
+
...argv.provider ? { provider: argv.provider } : {},
|
|
15234
|
+
...argv.yes ? { yes: true } : {}
|
|
15235
|
+
})).status === "fail") process.exitCode = 1;
|
|
15236
|
+
}
|
|
15237
|
+
};
|
|
15071
15238
|
// src/commands/notifications-link/notifications-link.args.ts
|
|
15072
15239
|
const notificationsLinkArgs = (y) => y.option("provider", {
|
|
15073
15240
|
type: "string",
|
|
@@ -15226,7 +15393,7 @@ const notificationsChannelCommand = {
|
|
|
15226
15393
|
const notificationsCommand = {
|
|
15227
15394
|
command: "notifications",
|
|
15228
15395
|
describe: "Provision notification channels, webhooks and roles",
|
|
15229
|
-
builder: (y) => y.command(notificationsChannelCommand).command(notificationsSetupCommand).command(notificationsCreateServerCommand).command(notificationsLinkCommand).command(notificationsSyncRolesCommand).command(groupMenu$1("notifications")),
|
|
15396
|
+
builder: (y) => y.command(notificationsChannelCommand).command(notificationsSetupCommand).command(notificationsCreateServerCommand).command(notificationsLinkCommand).command(notificationsSyncRolesCommand).command(notificationsDedupeCommand).command(groupMenu$1("notifications")),
|
|
15230
15397
|
handler: () => {}
|
|
15231
15398
|
};
|
|
15232
15399
|
// src/commands/move-tag/move-tag.ts
|