@theholocron/cli 5.0.0-alpha.51 → 5.0.0-alpha.511
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 +626 -107
- package/dist/cli.mjs +35032 -8114
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-CHEJvjlB.mjs +901 -0
- package/dist/index-D_e9vKTW.d.mts +5285 -0
- package/dist/index.d.mts +756 -641
- package/dist/index.mjs +1131 -340
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +59 -4
- package/dist/presets.d.mts +224 -0
- package/dist/presets.mjs +441 -0
- package/package.json +49 -36
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,810 @@
|
|
|
1
|
-
import { CARDINALITY, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { createEnvLookup } from "@theholocron/env-utils";
|
|
1
|
+
import { CARDINALITY, ElevationRequiredError, MissingTokenError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
2
|
+
import { a as placeAreas, c as ConfigError, d as resolveEntry, f as resolvePluginPackage, g as layerEnvironment, h as isEnvironmentLayer, i as loadConfig, l as credentialsEnvironment, m as ENVIRONMENT_LAYERS, n as compose, o as HOLOCRON_AREAS, p as repoSlug, r as defineConfig, s as SHARED_AREAS, t as ConfigFileError, u as resolveConfig } from "./config-system-CHEJvjlB.mjs";
|
|
4
3
|
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
4
|
+
import { AuthError, createFeatureResolver as createFeatureResolver$1, createKeyring, createResolveToken as createResolveToken$1, resolveValue } from "@theholocron/kyber/secrets";
|
|
5
|
+
import { DOCUMENTATION_FLAG, codecovFlagNames, readWorkspacePackages } from "@theholocron/astromech";
|
|
6
|
+
import { dirname, join, posix, resolve } from "node:path";
|
|
5
7
|
import { readFile } from "node:fs/promises";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
8
|
+
import { describeError, style } from "@theholocron/kyber/ui";
|
|
9
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
10
|
+
import { createRestClient } from "@theholocron/http-client";
|
|
11
|
+
import { connectionProbe as connectionProbe$1 } from "@theholocron/kyber/checks";
|
|
12
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
13
|
+
import { fstatSync, mkdirSync } from "node:fs";
|
|
14
|
+
// src/auth/auth.ts
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
16
|
+
* The CLI's credentials: the OS keyring every plugin's bootstrap token lives in, and the two token resolvers built on
|
|
17
|
+
* it. Both are public, so a plugin's `src/auth.ts` is a one-line call.
|
|
18
|
+
*
|
|
19
|
+
* The keyring itself, with its best-effort failure model and its per-process cache, is `createKeyring` in
|
|
20
|
+
* `@theholocron/kyber/secrets`; this file only names the service. Managed via `holocron check token` subcommands and consulted
|
|
21
|
+
* last in every plugin's precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN). See
|
|
22
|
+
* `docs/wiki/specifications/tech-auth-bootstrap.spec.md`.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The holocron keyring: `get` answers `null` for "not stored" and for "keyring unavailable" alike, so callers fall
|
|
26
|
+
* through to env-var precedence, and remembers the answer for the process (`clearCache` forgets it); `set` and `delete`
|
|
27
|
+
* answer whether they did anything; `list` names the stored providers; `isAvailable` tells an outage from an empty keyring.
|
|
15
28
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
const keyring = createKeyring({
|
|
30
|
+
service: "com.theholocron.cli",
|
|
31
|
+
binding: {
|
|
32
|
+
Entry,
|
|
33
|
+
findCredentials
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Kyber's `createResolveToken` with the keyring, the `HOLOCRON_ORG` variable and the `token` description
|
|
38
|
+
* `holocron doctor secrets --verify` reads filled in, so a plugin stays at a one-liner call site. The chain is the flag, the
|
|
39
|
+
* plugin's variable, the vendor's variable, the `credentials` providers' variables, the keyring.
|
|
40
|
+
*/
|
|
41
|
+
function createResolveToken(config) {
|
|
42
|
+
return Object.assign(createResolveToken$1({
|
|
43
|
+
...config,
|
|
44
|
+
keyring: keyring.get,
|
|
45
|
+
orgEnvName: "HOLOCRON_ORG"
|
|
46
|
+
}), { token: {
|
|
47
|
+
envName: config.envName,
|
|
48
|
+
vendorEnvName: config.vendorEnvName,
|
|
49
|
+
keyringKey: config.keyringService
|
|
50
|
+
} });
|
|
18
51
|
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/auth/keyring.ts
|
|
21
52
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
* Kyber's `createFeatureResolver` for a strict, single-feature token: the flag, the feature's variable, the
|
|
54
|
+
* `credentials` providers' variable of that name, the keyring. No broad-token fallback; if the feature's token is absent
|
|
55
|
+
* the operation fails with a message naming the exact variable to set and `holocron new token`.
|
|
56
|
+
*/
|
|
57
|
+
function createFeatureResolver(config) {
|
|
58
|
+
return Object.assign(createFeatureResolver$1({
|
|
59
|
+
...config,
|
|
60
|
+
vendor: config.vendor ?? "GitHub",
|
|
61
|
+
setCommand: (key) => `holocron new token ${key} <token>`,
|
|
62
|
+
keyring: keyring.get
|
|
63
|
+
}), { token: {
|
|
64
|
+
envName: config.envName,
|
|
65
|
+
keyringKey: config.keyringKey
|
|
66
|
+
} });
|
|
67
|
+
}
|
|
68
|
+
// src/commands/coverage-expectations/coverage-expectations.ts
|
|
69
|
+
/**
|
|
70
|
+
* The flags and components `holocron sync` writes to `codecov.yml` for the workspace at `repoRoot`: the same
|
|
71
|
+
* functions the generator uses, so a coverage provider's `checkRepo()` compares with exactly what is written. A flag per
|
|
72
|
+
* package (none for `docs`), plus `documentation` when `docsCoverage` is `warn` or `required`; a component per package.
|
|
73
|
+
* Both lists are sorted. Plugins call this instead of importing the task runner.
|
|
74
|
+
*/
|
|
75
|
+
function coverageExpectations(repoRoot, docsCoverage = "off") {
|
|
76
|
+
const packages = readWorkspacePackages(repoRoot);
|
|
77
|
+
const flags = codecovFlagNames(packages);
|
|
78
|
+
if (docsCoverage !== "off") flags.push(DOCUMENTATION_FLAG);
|
|
79
|
+
return {
|
|
80
|
+
flags: [...new Set(flags)].sort(),
|
|
81
|
+
components: packages.map((pkg) => pkg.slug).sort()
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// src/commands/notifications-reaction/layout-reactions/layout-reactions.ts
|
|
85
|
+
/**
|
|
86
|
+
* Every reaction a layout writes that can name a server emoji: each forum's default and starter reactions and its tags'
|
|
87
|
+
* `emoji` (a tag's is a string, Unicode or `:name:`), then the layout's own `emojis` (server emoji made with no reaction
|
|
88
|
+
* naming them), in that order.
|
|
89
|
+
*/
|
|
90
|
+
function layoutReactions(layout) {
|
|
91
|
+
const reactions = [];
|
|
92
|
+
for (const channel of (layout?.categories ?? []).flatMap((c) => c.channels ?? [])) {
|
|
93
|
+
if (channel.defaultReaction !== void 0) reactions.push(channel.defaultReaction);
|
|
94
|
+
reactions.push(...channel.starterReactions ?? []);
|
|
95
|
+
for (const tag of channel.tags ?? []) if (tag.emoji) reactions.push(tag.emoji);
|
|
96
|
+
}
|
|
97
|
+
reactions.push(...layout?.emojis ?? []);
|
|
98
|
+
return reactions;
|
|
99
|
+
}
|
|
100
|
+
// src/commands/notifications-reaction/parse-reaction/parse-reaction.ts
|
|
101
|
+
/** A server emoji written as Discord shows it: `:name:`, the name 2 to 32 letters, digits and underscores. */
|
|
102
|
+
const CUSTOM_EMOJI = /^:([A-Za-z0-9_]{2,32}):$/;
|
|
103
|
+
/**
|
|
104
|
+
* Reads a layout reaction. `":git_merge:"` (or `{ emoji: ":git_merge:", image }`) is a server emoji named `git_merge`;
|
|
105
|
+
* any other string is a Unicode emoji and kept as written. It does not judge a value: `reactionProblem()` does, before
|
|
106
|
+
* anything is applied, so an invalid `emoji` here is kept as the name it was given.
|
|
107
|
+
*/
|
|
108
|
+
function parseReaction(reaction) {
|
|
109
|
+
if (typeof reaction === "string") {
|
|
110
|
+
const name = CUSTOM_EMOJI.exec(reaction)?.[1];
|
|
111
|
+
return name === void 0 ? {
|
|
112
|
+
kind: "unicode",
|
|
113
|
+
value: reaction
|
|
114
|
+
} : {
|
|
115
|
+
kind: "custom",
|
|
116
|
+
name
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
kind: "custom",
|
|
121
|
+
name: CUSTOM_EMOJI.exec(reaction.emoji)?.[1] ?? reaction.emoji,
|
|
122
|
+
...reaction.image ? { image: reaction.image } : {}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// src/commands/notifications-reaction/emoji-conflict-problem/emoji-conflict-problem.ts
|
|
126
|
+
/**
|
|
127
|
+
* The first server emoji a layout gives two different pictures, or undefined. One name is one emoji, so it can be made
|
|
128
|
+
* from one file only; the same file written twice is fine.
|
|
129
|
+
*/
|
|
130
|
+
function emojiConflictProblem(layout) {
|
|
131
|
+
const images = /* @__PURE__ */ new Map();
|
|
132
|
+
for (const reaction of layoutReactions(layout)) {
|
|
133
|
+
const parsed = parseReaction(reaction);
|
|
134
|
+
if (parsed.kind !== "custom" || !parsed.image) continue;
|
|
135
|
+
const image = posix.normalize(parsed.image);
|
|
136
|
+
const have = images.get(parsed.name);
|
|
137
|
+
if (have !== void 0 && have !== image) return `emoji \`:${parsed.name}:\` is given two different images, \`${have}\` and \`${image}\``;
|
|
138
|
+
images.set(parsed.name, image);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// src/commands/notifications-reaction/layout-emojis/layout-emojis.ts
|
|
142
|
+
/**
|
|
143
|
+
* The server emoji a layout's forum reactions name (default and starter) and its `emojis` list, once each, in the order the layout first
|
|
144
|
+
* names them. A name that is given an `image` anywhere keeps it, so the picture can sit on any one of its uses.
|
|
145
|
+
*/
|
|
146
|
+
function layoutEmojis(layout) {
|
|
147
|
+
const found = /* @__PURE__ */ new Map();
|
|
148
|
+
for (const reaction of layoutReactions(layout)) {
|
|
149
|
+
const parsed = parseReaction(reaction);
|
|
150
|
+
if (parsed.kind !== "custom") continue;
|
|
151
|
+
const have = found.get(parsed.name);
|
|
152
|
+
if (!have) found.set(parsed.name, {
|
|
153
|
+
name: parsed.name,
|
|
154
|
+
...parsed.image ? { image: parsed.image } : {}
|
|
155
|
+
});
|
|
156
|
+
else if (!have.image && parsed.image) have.image = parsed.image;
|
|
157
|
+
}
|
|
158
|
+
return [...found.values()];
|
|
159
|
+
}
|
|
160
|
+
// src/commands/notifications-reaction/load-emoji-image/load-emoji-image.ts
|
|
161
|
+
/** Discord's limit for an emoji file ("256 KiB", its Emoji resource docs). */
|
|
162
|
+
const MAX_EMOJI_BYTES = 262144;
|
|
163
|
+
const ascii = (bytes, from, to) => Buffer.from(bytes.subarray(from, to)).toString("latin1");
|
|
164
|
+
/** The image type the first bytes show, among the ones Discord takes for an emoji (JPEG, PNG, GIF, WebP, AVIF). */
|
|
165
|
+
function typeOf(bytes) {
|
|
166
|
+
if (bytes.length >= 8 && [
|
|
167
|
+
137,
|
|
168
|
+
80,
|
|
169
|
+
78,
|
|
170
|
+
71,
|
|
171
|
+
13,
|
|
172
|
+
10,
|
|
173
|
+
26,
|
|
174
|
+
10
|
|
175
|
+
].every((b, i) => bytes[i] === b)) return "image/png";
|
|
176
|
+
if (bytes.length >= 3 && bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255) return "image/jpeg";
|
|
177
|
+
if (ascii(bytes, 0, 4) === "GIF8") return "image/gif";
|
|
178
|
+
if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 12) === "WEBP") return "image/webp";
|
|
179
|
+
if (ascii(bytes, 4, 8) === "ftyp" && ["avif", "avis"].includes(ascii(bytes, 8, 12))) return "image/avif";
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Reads the picture an emoji is made from, a file in the repo, and returns it as a `data:` URI. The type comes from the
|
|
183
|
+
* first bytes, not the name, and a file Discord would refuse (larger than 256 KiB, or not a JPEG, PNG, GIF, WebP or
|
|
184
|
+
* AVIF image) is refused here, before anything is written. `read` is injected by tests.
|
|
185
|
+
*/
|
|
186
|
+
async function loadEmojiImage(source, baseDir = process.cwd(), read = readFile) {
|
|
187
|
+
const bytes = await read(resolve(baseDir, source));
|
|
188
|
+
if (bytes.length > 262144) throw new Error(`it is ${Math.ceil(bytes.length / 1024)} KiB, and Discord takes an emoji up to 256 KiB`);
|
|
189
|
+
const type = typeOf(bytes);
|
|
190
|
+
if (!type) throw new Error("it is not a JPEG, PNG, GIF, WebP or AVIF image, which are the formats Discord takes");
|
|
191
|
+
return `data:${type};base64,${Buffer.from(bytes).toString("base64")}`;
|
|
192
|
+
}
|
|
193
|
+
// src/commands/notifications-reaction/reaction-problem/reaction-problem.ts
|
|
194
|
+
/** The folder a layout's emoji pictures live in, as the webhook avatar's files do. */
|
|
195
|
+
const EMOJI_MEDIA_DIR = ".holocron/media/";
|
|
196
|
+
/**
|
|
197
|
+
* The first reason a reaction cannot work, or undefined; `noun` names it in the message (`` `defaultReaction` ``, "a
|
|
198
|
+
* starter reaction"). A Unicode emoji must be a character, not a word (`git_merge` without colons would be sent to
|
|
199
|
+
* Discord as text), a server emoji `:name:` with a name Discord allows, and an `image` a file under `.holocron/media/`
|
|
200
|
+
* (a path, not a URL, with no `..` out of it). A `null` a config wrote is refused, not read as absent.
|
|
201
|
+
*/
|
|
202
|
+
function reactionProblem(noun, reaction) {
|
|
203
|
+
if (reaction === null || typeof reaction !== "string" && typeof reaction !== "object") return `${noun} must be an emoji, \`:name:\` for a server emoji, or \`{ emoji, image }\``;
|
|
204
|
+
const text = typeof reaction === "string" ? reaction : reaction.emoji;
|
|
205
|
+
if (typeof text !== "string" || text.trim() === "") return `${noun} is empty`;
|
|
206
|
+
const isCustom = CUSTOM_EMOJI.test(text);
|
|
207
|
+
if (typeof reaction === "object" && !isCustom) return `${noun}: \`emoji\` must be a server emoji written \`:name:\` (2 to 32 letters, digits and underscores), not \`${text}\``;
|
|
208
|
+
if (!isCustom && /^:|:$|^[A-Za-z0-9_ ]+$/.test(text)) return `${noun}: \`${text}\` is not an emoji; write a server emoji as \`:name:\` (2 to 32 letters, digits and underscores)`;
|
|
209
|
+
if (typeof reaction === "object" && reaction.image !== void 0) {
|
|
210
|
+
const image = reaction.image;
|
|
211
|
+
if (typeof image !== "string" || image.trim() === "") return `${noun}: \`image\` is empty`;
|
|
212
|
+
if (/^[a-z][a-z0-9+.-]+:/i.test(image)) return `${noun}: \`image\` must be a file under \`${EMOJI_MEDIA_DIR}\`, not a URL`;
|
|
213
|
+
const path = posix.normalize(image);
|
|
214
|
+
if (!path.startsWith(".holocron/media/") || path === ".holocron/media/") return `${noun}: \`image\` must be a file under \`${EMOJI_MEDIA_DIR}\`, not \`${image}\``;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// src/commands/notifications-reaction/reaction-spelling/reaction-spelling.ts
|
|
218
|
+
/** How a reaction is written in a layout and shown in a row: `:name:` for a server emoji, the character otherwise. */
|
|
219
|
+
function reactionSpelling(reaction) {
|
|
220
|
+
const parsed = parseReaction(reaction);
|
|
221
|
+
return parsed.kind === "custom" ? `:${parsed.name}:` : parsed.value;
|
|
222
|
+
}
|
|
223
|
+
// src/commands/notifications-reaction/tag-emoji-problem/tag-emoji-problem.ts
|
|
224
|
+
/**
|
|
225
|
+
* The first reason a forum tag's `emoji` cannot work, or undefined. A string with no colon at either end is a Unicode
|
|
226
|
+
* emoji and kept as written (it is not judged). One that starts or ends with a colon is meant as a server emoji, so it
|
|
227
|
+
* must be `:name:` (2 to 32 letters, digits and underscores), and the layout must give that emoji a picture somewhere
|
|
228
|
+
* (`pictured`: the names an `image` is declared for, from `layoutEmojis()`), because a tag's `emoji` is only a name and
|
|
229
|
+
* `setup` makes the emoji before any channel.
|
|
230
|
+
*/
|
|
231
|
+
function tagEmojiProblem(tagName, emoji, pictured) {
|
|
232
|
+
if (emoji === void 0 || !/^:|:$/.test(emoji)) return void 0;
|
|
233
|
+
const noun = `tag \`${tagName}\` emoji`;
|
|
234
|
+
const problem = reactionProblem(noun, emoji);
|
|
235
|
+
if (problem) return problem;
|
|
236
|
+
if (pictured.has(emoji.slice(1, -1))) return void 0;
|
|
237
|
+
return `${noun} \`${emoji}\` has no picture: give the emoji an \`image\` in \`emojis\` or a reaction so \`setup\` can make it`;
|
|
238
|
+
}
|
|
239
|
+
// src/plugin/issues-provider/order-keys/order-keys.ts
|
|
240
|
+
/**
|
|
241
|
+
* Puts issue keys in creation order without asking the tracker: issue numbers (`#12`, `ENG-12`) rise with creation inside
|
|
242
|
+
* one repository or team, so the trailing number is the order. `oldest` is ascending, `newest` descending; keys with the
|
|
243
|
+
* same number keep their place. A key with no trailing number is an error, because nothing can be said of its age.
|
|
244
|
+
*/
|
|
245
|
+
function orderKeys(keys, order) {
|
|
246
|
+
const numbered = keys.map((key, index) => {
|
|
247
|
+
const match = /(\d+)\s*$/.exec(key);
|
|
248
|
+
if (!match) throw new Error(`Cannot order "${key}" by creation: it has no issue number.`);
|
|
249
|
+
return {
|
|
250
|
+
key,
|
|
251
|
+
index,
|
|
252
|
+
n: Number(match[1])
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
const sign = order === "newest" ? -1 : 1;
|
|
256
|
+
return numbered.sort((a, b) => sign * (a.n - b.n) || a.index - b.index).map((e) => e.key);
|
|
257
|
+
}
|
|
258
|
+
// src/plugin/issues-provider/pick-by-creation/pick-by-creation.ts
|
|
259
|
+
/**
|
|
260
|
+
* Keeps the first or last `limit` of a listing by creation time, returned oldest first. `createdAt` reads an item's
|
|
261
|
+
* ISO timestamp; items created in the same instant keep their listed order. The cut happens on what the listing already
|
|
262
|
+
* holds, so no request is spent on an item that is dropped.
|
|
263
|
+
*/
|
|
264
|
+
function pickByCreation(items, createdAt, order, limit) {
|
|
265
|
+
const ascending = items.map((item, index) => ({
|
|
266
|
+
item,
|
|
267
|
+
index,
|
|
268
|
+
at: Date.parse(createdAt(item))
|
|
269
|
+
})).sort((a, b) => a.at - b.at || a.index - b.index).map((e) => e.item);
|
|
270
|
+
return order === "newest" ? ascending.slice(Math.max(ascending.length - limit, 0)) : ascending.slice(0, limit);
|
|
271
|
+
}
|
|
272
|
+
// src/plugin/issues-provider/read-keys-limited/read-keys-limited.ts
|
|
273
|
+
/**
|
|
274
|
+
* Reads an explicit list of issues in creation order until `limit` of them are kept. The keys are sorted by number first
|
|
275
|
+
* (see {@link orderKeys}), then fetched in small steps of at most `concurrency`, each step no bigger than the places
|
|
276
|
+
* still open, so an issue that is later skipped (a pull request, a closed one) is replaced by the next key and nothing
|
|
277
|
+
* beyond the budget is fetched unless a skip made room. Within a step the fetches run together; the results keep the key
|
|
278
|
+
* order. The kept items come back oldest first, whichever end was chosen.
|
|
279
|
+
*/
|
|
280
|
+
async function readKeysLimited(input) {
|
|
281
|
+
const { keys, order, limit, concurrency, fetch, keep } = input;
|
|
282
|
+
const ordered = orderKeys(keys, order);
|
|
283
|
+
const kept = [];
|
|
284
|
+
let next = 0;
|
|
285
|
+
while (kept.length < limit && next < ordered.length) {
|
|
286
|
+
const step = ordered.slice(next, next + Math.min(concurrency, limit - kept.length));
|
|
287
|
+
next += step.length;
|
|
288
|
+
const fetched = await Promise.all(step.map((key) => fetch(key)));
|
|
289
|
+
for (const item of fetched) if (keep(item)) kept.push(item);
|
|
290
|
+
}
|
|
291
|
+
return order === "newest" ? kept.reverse() : kept;
|
|
292
|
+
}
|
|
293
|
+
// src/plugin/issues-provider/report-progress/report-progress.ts
|
|
294
|
+
/**
|
|
295
|
+
* Calls a provider's optional `onProgress` hook with how many items are done of how many. A hook that throws is
|
|
296
|
+
* ignored, because a progress counter must never change or stop the read or write it reports on.
|
|
31
297
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* here catches and returns a null/empty result rather than propagating
|
|
36
|
-
* — the plugin's precedence chain then falls through to
|
|
37
|
-
* env-var-only paths, which is exactly how CI is meant to work.
|
|
298
|
+
* @param onProgress - The hook from `ExportInfo` or `ImportOptions`; nothing happens when it is not given.
|
|
299
|
+
* @param done - How many items are finished.
|
|
300
|
+
* @param total - How many items there are.
|
|
38
301
|
*/
|
|
39
|
-
|
|
302
|
+
function reportProgress(onProgress, done, total) {
|
|
303
|
+
try {
|
|
304
|
+
onProgress?.(done, total);
|
|
305
|
+
} catch {}
|
|
306
|
+
}
|
|
307
|
+
// src/plugin/probes/connection-probe/connection-probe.ts
|
|
40
308
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
309
|
+
* The `connection` probe every provider offers, for telling a network problem from a credential problem. The checks are
|
|
310
|
+
* kyber's `connectionProbe`; this types the result as the plugin system's {@link Probe} and `verify` as `VerifyTokenResult`.
|
|
43
311
|
*/
|
|
44
|
-
function
|
|
312
|
+
function connectionProbe(input) {
|
|
313
|
+
return connectionProbe$1(input);
|
|
314
|
+
}
|
|
315
|
+
// src/commands/notifications-sync-roles/links.ts
|
|
316
|
+
const EMPTY_LINKS = {
|
|
317
|
+
version: 1,
|
|
318
|
+
links: []
|
|
319
|
+
};
|
|
320
|
+
const DIGITS = /^\d{1,20}$/;
|
|
321
|
+
/** Reads the file's text. Throws with a plain reason on anything that is not a links file, so a damaged one is never treated as empty. */
|
|
322
|
+
function parseLinks(text) {
|
|
323
|
+
let raw;
|
|
45
324
|
try {
|
|
46
|
-
|
|
47
|
-
return true;
|
|
325
|
+
raw = JSON.parse(text);
|
|
48
326
|
} catch {
|
|
49
|
-
|
|
327
|
+
throw new Error("the links file is not valid JSON");
|
|
328
|
+
}
|
|
329
|
+
const file = raw;
|
|
330
|
+
if (file.version !== 1) throw new Error(`the links file has version ${JSON.stringify(file.version)}; expected 1`);
|
|
331
|
+
if (!Array.isArray(file.links)) throw new Error("the links file has no `links` list");
|
|
332
|
+
const links = file.links.map((entry, i) => {
|
|
333
|
+
const e = entry;
|
|
334
|
+
if (typeof e.github !== "string" || !DIGITS.test(e.github)) throw new Error(`links[${i}]: \`github\` must be a numeric user id string`);
|
|
335
|
+
if (typeof e.member !== "string" || !DIGITS.test(e.member)) throw new Error(`links[${i}]: \`member\` must be a numeric id string`);
|
|
336
|
+
if (typeof e.login !== "string") throw new Error(`links[${i}]: \`login\` must be a string`);
|
|
337
|
+
return {
|
|
338
|
+
github: e.github,
|
|
339
|
+
login: e.login,
|
|
340
|
+
member: e.member
|
|
341
|
+
};
|
|
342
|
+
});
|
|
343
|
+
for (const key of ["github", "member"]) {
|
|
344
|
+
const seen = /* @__PURE__ */ new Set();
|
|
345
|
+
for (const [i, link] of links.entries()) {
|
|
346
|
+
if (seen.has(link[key])) throw new Error(`links[${i}]: \`${key}\` ${link[key]} appears more than once`);
|
|
347
|
+
seen.add(link[key]);
|
|
348
|
+
}
|
|
50
349
|
}
|
|
350
|
+
return {
|
|
351
|
+
version: 1,
|
|
352
|
+
links
|
|
353
|
+
};
|
|
51
354
|
}
|
|
355
|
+
/** Where the links file is: the layout's `links`, else `<org>/.github-private` and `notifications/<provider>-links.json`. */
|
|
356
|
+
function linksLocation(layout, org, provider) {
|
|
357
|
+
const repo = layout.links?.repo ?? (org ? `${org}/.github-private` : void 0);
|
|
358
|
+
if (!repo) throw new Error("no org to find the links file under — set `layout.links.repo` or `org` in holocron.config.ts");
|
|
359
|
+
return {
|
|
360
|
+
repo,
|
|
361
|
+
path: layout.links?.path ?? `notifications/${provider.toLowerCase()}-links.json`
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
// src/commands/notifications-sync-roles/plan.ts
|
|
52
365
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
366
|
+
* What it takes to make a role's holders equal a team, given who is linked to whom. Pure: it decides, the
|
|
367
|
+
* caller acts. A holder is removed only when a link says they are a person who left the team; a holder
|
|
368
|
+
* nobody has linked is reported, never removed, so an empty or missing links file cannot strip the role from
|
|
369
|
+
* everyone.
|
|
56
370
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
371
|
+
function planRoleSync(input) {
|
|
372
|
+
const byGithub = new Map(input.links.map((l) => [l.github, l]));
|
|
373
|
+
const byMember = new Map(input.links.map((l) => [l.member, l]));
|
|
374
|
+
const onTeam = new Set(input.team.map((m) => m.id));
|
|
375
|
+
const holding = new Set(input.holders.map((h) => h.id));
|
|
376
|
+
const plan = {
|
|
377
|
+
add: [],
|
|
378
|
+
remove: [],
|
|
379
|
+
unlinked: [],
|
|
380
|
+
unknownHolders: [],
|
|
381
|
+
inSync: 0
|
|
382
|
+
};
|
|
383
|
+
for (const person of input.team) {
|
|
384
|
+
const link = byGithub.get(person.id);
|
|
385
|
+
if (!link) plan.unlinked.push(person);
|
|
386
|
+
else if (holding.has(link.member)) plan.inSync++;
|
|
387
|
+
else plan.add.push({
|
|
388
|
+
member: link.member,
|
|
389
|
+
login: person.login
|
|
390
|
+
});
|
|
62
391
|
}
|
|
392
|
+
for (const holder of input.holders) {
|
|
393
|
+
const link = byMember.get(holder.id);
|
|
394
|
+
if (!link) plan.unknownHolders.push({
|
|
395
|
+
member: holder.id,
|
|
396
|
+
...holder.name ? { name: holder.name } : {}
|
|
397
|
+
});
|
|
398
|
+
else if (!onTeam.has(link.github)) plan.remove.push({
|
|
399
|
+
member: holder.id,
|
|
400
|
+
login: link.login
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
return plan;
|
|
63
404
|
}
|
|
64
405
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* Distinguishing the two cases isn't worth the surface area — the
|
|
68
|
-
* command output makes the situation clear either way.
|
|
406
|
+
* The first role the layout declares for two different teams, or undefined. Names compare ignoring case, as
|
|
407
|
+
* the server does; the role would be synced against one team and then the other, so the last would win.
|
|
69
408
|
*/
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
409
|
+
function roleTeamProblem(layout) {
|
|
410
|
+
const seen = /* @__PURE__ */ new Map();
|
|
411
|
+
for (const role of layout.roles ?? []) {
|
|
412
|
+
if (!role.team) continue;
|
|
413
|
+
const key = role.name.toLowerCase();
|
|
414
|
+
const earlier = seen.get(key);
|
|
415
|
+
if (earlier !== void 0 && earlier.toLowerCase() !== role.team.toLowerCase()) return `role \`${role.name}\` is declared for two teams (\`${earlier}\` and \`${role.team}\`); a role follows one team`;
|
|
416
|
+
seen.set(key, role.team);
|
|
75
417
|
}
|
|
76
418
|
}
|
|
419
|
+
// src/commands/notifications-sync-roles/sync-roles.ts
|
|
420
|
+
/** Reads the team and the role's holders and works out what has to change. */
|
|
421
|
+
async function planForRole(args) {
|
|
422
|
+
const [team, holders] = await Promise.all([args.source.teamMembers(args.team, args.org), args.notifications.roleMembers(args.role)]);
|
|
423
|
+
return planRoleSync({
|
|
424
|
+
team,
|
|
425
|
+
links: args.links.links,
|
|
426
|
+
holders
|
|
427
|
+
});
|
|
428
|
+
}
|
|
77
429
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
430
|
+
* Makes each role's holders equal its team, one role after another. This is the sync itself, with no setup in
|
|
431
|
+
* front of it: the caller has already picked the providers, read the links and checked the layout. `holocron
|
|
432
|
+
* sync roles` and Sentinel's role sync are two callers of it. A step that fails is recorded and the
|
|
433
|
+
* run goes on; nothing here throws for a provider error. Idempotent: a role that already matches changes nothing.
|
|
434
|
+
* Lines go to `input.print` when it is given, and nowhere otherwise.
|
|
81
435
|
*/
|
|
82
|
-
function
|
|
436
|
+
async function syncRoles(input) {
|
|
437
|
+
const print = input.print ?? (() => {});
|
|
438
|
+
const { notifications, source, links, dryRun, keep } = input;
|
|
439
|
+
const result = {
|
|
440
|
+
roles: [],
|
|
441
|
+
failures: [],
|
|
442
|
+
ok: 0,
|
|
443
|
+
skipped: 0
|
|
444
|
+
};
|
|
445
|
+
for (const role of input.roles) {
|
|
446
|
+
print(`\n${style.header(`${role.name} ← team ${role.team}`)}`);
|
|
447
|
+
const step = `role ${role.name}`;
|
|
448
|
+
let plan;
|
|
449
|
+
try {
|
|
450
|
+
plan = await planForRole({
|
|
451
|
+
notifications,
|
|
452
|
+
source,
|
|
453
|
+
role: role.name,
|
|
454
|
+
team: role.team,
|
|
455
|
+
...input.org ? { org: input.org } : {},
|
|
456
|
+
links
|
|
457
|
+
});
|
|
458
|
+
} catch (err) {
|
|
459
|
+
const message = describeError(err);
|
|
460
|
+
print(` ${style.fail(`${step}: ${message}`)}`);
|
|
461
|
+
result.failures.push({
|
|
462
|
+
step,
|
|
463
|
+
message
|
|
464
|
+
});
|
|
465
|
+
continue;
|
|
466
|
+
}
|
|
467
|
+
const outcome = {
|
|
468
|
+
role: role.name,
|
|
469
|
+
team: role.team,
|
|
470
|
+
plan,
|
|
471
|
+
added: [],
|
|
472
|
+
removed: []
|
|
473
|
+
};
|
|
474
|
+
result.roles.push(outcome);
|
|
475
|
+
result.skipped += plan.inSync;
|
|
476
|
+
if (plan.inSync > 0) print(` ${style.skip(`${plan.inSync} already have it`)}`);
|
|
477
|
+
const act = async (verb, who) => {
|
|
478
|
+
const label = `${verb === "add" ? "gave" : "took"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})`;
|
|
479
|
+
if (dryRun || verb === "remove" && keep) {
|
|
480
|
+
print(` ${style.skip(`would ${verb === "add" ? "give" : "take"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})${keep && verb === "remove" ? " (kept: --keep)" : ""}`)}`);
|
|
481
|
+
result.skipped++;
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
if (verb === "add") await notifications.addRoleMember(role.name, who.member);
|
|
486
|
+
else await notifications.removeRoleMember(role.name, who.member);
|
|
487
|
+
(verb === "add" ? outcome.added : outcome.removed).push(who.member);
|
|
488
|
+
print(` ${style.success(label)}`);
|
|
489
|
+
result.ok++;
|
|
490
|
+
} catch (err) {
|
|
491
|
+
const message = describeError(err);
|
|
492
|
+
print(` ${style.fail(`${step}: ${verb} ${who.login}: ${message}`)}`);
|
|
493
|
+
result.failures.push({
|
|
494
|
+
step: `${step} ${verb} ${who.login}`,
|
|
495
|
+
message
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
for (const who of plan.add) await act("add", who);
|
|
500
|
+
for (const who of plan.remove) await act("remove", who);
|
|
501
|
+
for (const person of plan.unlinked) {
|
|
502
|
+
print(` ${style.skip(`${person.login} is on the team but has not linked their account`)}`);
|
|
503
|
+
result.skipped++;
|
|
504
|
+
}
|
|
505
|
+
for (const holder of plan.unknownHolders) {
|
|
506
|
+
print(` ${style.skip(`${holder.name ?? holder.member} holds ${role.name} but is not linked to anyone: left alone`)}`);
|
|
507
|
+
result.skipped++;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
// src/commands/notifications-sync-roles/notifications-sync-roles.ts
|
|
513
|
+
/** What a source provider needs to be able to do to feed a role sync, or the reason it cannot. */
|
|
514
|
+
function sourceProblem(source) {
|
|
515
|
+
if (!source) return "no `source` provider is available to read the team and the links file";
|
|
516
|
+
if (!source.teamMembers) return `the \`${source.providerName}\` provider cannot list team members`;
|
|
517
|
+
if (!source.readFile) return `the \`${source.providerName}\` provider cannot read the links file`;
|
|
518
|
+
}
|
|
519
|
+
/** Reads the links file; a file that does not exist yet is an empty one, a damaged one throws. */
|
|
520
|
+
async function readLinks(source, layout, org, provider) {
|
|
521
|
+
const { repo, path } = linksLocation(layout, org, provider);
|
|
522
|
+
const file = await source.readFile(path, repo);
|
|
523
|
+
if (!file) return EMPTY_LINKS;
|
|
83
524
|
try {
|
|
84
|
-
return
|
|
85
|
-
} catch {
|
|
86
|
-
|
|
525
|
+
return parseLinks(file.content);
|
|
526
|
+
} catch (err) {
|
|
527
|
+
throw new Error(`${repo}/${path}: ${errorMessage(err)}`, { cause: err });
|
|
87
528
|
}
|
|
88
529
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
530
|
+
// src/commands/project/plan-pull-request-status/plan-pull-request-status.ts
|
|
531
|
+
/**
|
|
532
|
+
* Decide the status an item's linked pull requests ask for (spec `tech-board-status-automation`, #2388). Pure: it reads
|
|
533
|
+
* one item and the template and touches nothing; status only, never priority or any other field.
|
|
534
|
+
*
|
|
535
|
+
* - an open linked pull request (a draft counts) puts the item in `active`;
|
|
536
|
+
* - an open one whose aggregate check is `success` puts it in `review`;
|
|
537
|
+
* - when the item is in `review` and no open pull request is green, a `failure` moves it back to `active`, while
|
|
538
|
+
* `pending` and `none` leave it, so a re-run after a push does not flicker the board;
|
|
539
|
+
* - no open pull request: no change (closed and merged ones are `planReconcile()`'s, through the closed issue).
|
|
540
|
+
*
|
|
541
|
+
* Left to `planReconcile()`, which runs first: a closed item, an item with an open blocker or in `blocked`, and an
|
|
542
|
+
* item with no status (reported there, not set). An item in `done` is left alone. Where the template has no status of
|
|
543
|
+
* the wanted category the rule comes back as `unresolved` and nothing is guessed; where a category has several statuses
|
|
544
|
+
* the first in template order is used. Applying the change and planning again gives no change.
|
|
545
|
+
*/
|
|
546
|
+
function planPullRequestStatus(item, template) {
|
|
547
|
+
if (!item.open || item.status === void 0 || item.blockedBy.length > 0) return void 0;
|
|
548
|
+
const category = template.statuses.find((s) => s.name === item.status)?.category ?? item.category;
|
|
549
|
+
if (category === "blocked" || category === "done") return void 0;
|
|
550
|
+
const open = (item.pullRequests ?? []).filter((pr) => pr.state === "open");
|
|
551
|
+
if (open.length === 0) return void 0;
|
|
552
|
+
let want;
|
|
553
|
+
let reason;
|
|
554
|
+
if (open.some((pr) => pr.checks === "success")) {
|
|
555
|
+
if (category !== "review") [want, reason] = ["review", "checks-green"];
|
|
556
|
+
} else if (category === "review") {
|
|
557
|
+
if (open.some((pr) => pr.checks === "failure")) [want, reason] = ["active", "checks-failed"];
|
|
558
|
+
} else if (category !== "active") [want, reason] = ["active", "pull-request-open"];
|
|
559
|
+
if (want === void 0 || reason === void 0) return void 0;
|
|
560
|
+
const to = template.statuses.find((s) => s.category === want)?.name;
|
|
561
|
+
if (to === void 0) return {
|
|
562
|
+
kind: "unresolved",
|
|
563
|
+
unresolved: {
|
|
564
|
+
key: item.key,
|
|
565
|
+
title: item.title,
|
|
566
|
+
category: want,
|
|
567
|
+
reason
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
return {
|
|
571
|
+
kind: "change",
|
|
572
|
+
change: {
|
|
573
|
+
key: item.key,
|
|
574
|
+
title: item.title,
|
|
575
|
+
from: item.status,
|
|
576
|
+
to,
|
|
577
|
+
category: want,
|
|
578
|
+
reason
|
|
579
|
+
}
|
|
580
|
+
};
|
|
98
581
|
}
|
|
582
|
+
// src/commands/project/plan-reconcile/plan-reconcile.ts
|
|
99
583
|
/**
|
|
100
|
-
*
|
|
584
|
+
* Decide the status changes that keep a board true (spec `command-project`, "Keeping a board true"). Pure: it reads
|
|
585
|
+
* the items and the template and touches nothing. Status only, never priority or any other field.
|
|
101
586
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
587
|
+
* - closed or merged, not in a `done` status: set to `done` (whatever the blockers say);
|
|
588
|
+
* - open with no status: not changed, listed in `unset` (it needs a decision, not a rule; this holds even when it has a
|
|
589
|
+
* blocker);
|
|
590
|
+
* - open with an open blocker, not in a `blocked` status: set to `blocked`;
|
|
591
|
+
* - open, in a `blocked` status, with no open blocker: set to `planned` (the status it held before is unknown).
|
|
592
|
+
*
|
|
593
|
+
* Where a category has several statuses the first in template order is used; where it has none the item is listed in
|
|
594
|
+
* `unresolved` and nothing is guessed. An item's category is read from the template by its status name, falling back
|
|
595
|
+
* to the one the provider reports. Applying the changes and planning again gives no change.
|
|
105
596
|
*/
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
597
|
+
function planReconcile(items, template) {
|
|
598
|
+
const target = (category) => template.statuses.find((s) => s.category === category)?.name;
|
|
599
|
+
const plan = {
|
|
600
|
+
changes: [],
|
|
601
|
+
unset: [],
|
|
602
|
+
unresolved: []
|
|
603
|
+
};
|
|
604
|
+
for (const item of items) {
|
|
605
|
+
const category = item.status === void 0 ? void 0 : template.statuses.find((s) => s.name === item.status)?.category ?? item.category;
|
|
606
|
+
let want;
|
|
607
|
+
let reason;
|
|
608
|
+
if (!item.open) {
|
|
609
|
+
if (category !== "done") [want, reason] = ["done", "closed"];
|
|
610
|
+
} else if (item.status === void 0) {
|
|
611
|
+
plan.unset.push(item);
|
|
612
|
+
continue;
|
|
613
|
+
} else if (item.blockedBy.length > 0) {
|
|
614
|
+
if (category !== "blocked") [want, reason] = ["blocked", "blocked"];
|
|
615
|
+
} else if (category === "blocked") [want, reason] = ["planned", "unblocked"];
|
|
616
|
+
if (want === void 0 || reason === void 0) continue;
|
|
617
|
+
const to = target(want);
|
|
618
|
+
if (to === void 0) {
|
|
619
|
+
plan.unresolved.push({
|
|
620
|
+
key: item.key,
|
|
621
|
+
title: item.title,
|
|
622
|
+
category: want,
|
|
623
|
+
reason
|
|
624
|
+
});
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
plan.changes.push({
|
|
628
|
+
key: item.key,
|
|
629
|
+
title: item.title,
|
|
630
|
+
...item.status !== void 0 ? { from: item.status } : {},
|
|
631
|
+
to,
|
|
632
|
+
category: want,
|
|
633
|
+
reason
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
return plan;
|
|
637
|
+
}
|
|
638
|
+
// src/commands/project/project-options/project-options.ts
|
|
639
|
+
/** Where a repo's own template files live unless the `templates` option says otherwise. */
|
|
640
|
+
const DEFAULT_TEMPLATES_DIR = ".holocron/projects";
|
|
641
|
+
/**
|
|
642
|
+
* Read the options of `providers.projects`: `org` (the owner, defaulting to `fallbackOwner`, the config's org), `boards`
|
|
643
|
+
* (a list of `{ template, name }`, nothing else about a board is written in the config) and `templates` (the directory
|
|
644
|
+
* of template files). Every problem is listed at once, and two boards with the same name are one.
|
|
645
|
+
*/
|
|
646
|
+
function resolveProjectOptions(options, fallbackOwner) {
|
|
647
|
+
const problems = [];
|
|
648
|
+
const org = options.org;
|
|
649
|
+
if (org !== void 0 && (typeof org !== "string" || org.trim() === "")) problems.push("org must be text");
|
|
650
|
+
const owner = typeof org === "string" && org.trim() !== "" ? org : fallbackOwner;
|
|
651
|
+
const dir = options.templates;
|
|
652
|
+
if (dir !== void 0 && (typeof dir !== "string" || dir.trim() === "")) problems.push("templates must be the path of a directory");
|
|
653
|
+
const boards = [];
|
|
654
|
+
if (options.boards !== void 0) {
|
|
655
|
+
if (!Array.isArray(options.boards)) problems.push("boards must be a list of { template, name }");
|
|
656
|
+
else {
|
|
657
|
+
const seen = /* @__PURE__ */ new Set();
|
|
658
|
+
options.boards.forEach((entry, i) => {
|
|
659
|
+
const where = `boards[${i}]`;
|
|
660
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
661
|
+
problems.push(`${where} must be { template, name }`);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
const { template, name } = entry;
|
|
665
|
+
if (typeof template !== "string" || template.trim() === "") problems.push(`${where} needs a template`);
|
|
666
|
+
if (typeof name !== "string" || name.trim() === "") problems.push(`${where} needs a name`);
|
|
667
|
+
if (typeof template !== "string" || typeof name !== "string" || !template.trim() || !name.trim()) return;
|
|
668
|
+
if (seen.has(name)) problems.push(`${where}: the board name "${name}" is used twice`);
|
|
669
|
+
seen.add(name);
|
|
670
|
+
boards.push({
|
|
671
|
+
template,
|
|
672
|
+
name
|
|
673
|
+
});
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (problems.length > 0) return {
|
|
678
|
+
ok: false,
|
|
679
|
+
problems
|
|
680
|
+
};
|
|
681
|
+
return {
|
|
682
|
+
ok: true,
|
|
683
|
+
options: {
|
|
684
|
+
owner,
|
|
685
|
+
boards,
|
|
686
|
+
templatesDir: typeof dir === "string" ? dir : DEFAULT_TEMPLATES_DIR
|
|
687
|
+
}
|
|
113
688
|
};
|
|
114
689
|
}
|
|
115
|
-
|
|
116
|
-
|
|
690
|
+
// src/commands/project/templates/builtin-templates/builtin-templates.ts
|
|
691
|
+
/** The templates that ship in `@theholocron/cli`, by name. A repo's own template with the same name replaces one. */
|
|
692
|
+
const BUILTIN_TEMPLATES = {
|
|
693
|
+
roadmap: {
|
|
694
|
+
name: "roadmap",
|
|
695
|
+
statuses: [
|
|
696
|
+
{
|
|
697
|
+
name: "Someday",
|
|
698
|
+
category: "backlog",
|
|
699
|
+
color: "GRAY",
|
|
700
|
+
description: "Idea or future consideration, not yet planned"
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
name: "Todo",
|
|
704
|
+
category: "planned",
|
|
705
|
+
color: "BLUE",
|
|
706
|
+
description: "Planned and ready to be worked on"
|
|
707
|
+
},
|
|
708
|
+
{
|
|
709
|
+
name: "In Progress",
|
|
710
|
+
category: "active",
|
|
711
|
+
color: "YELLOW",
|
|
712
|
+
description: "Currently being worked on"
|
|
713
|
+
},
|
|
714
|
+
{
|
|
715
|
+
name: "In Review",
|
|
716
|
+
category: "review",
|
|
717
|
+
color: "ORANGE",
|
|
718
|
+
description: "Pull request is green and waiting on review"
|
|
719
|
+
},
|
|
720
|
+
{
|
|
721
|
+
name: "Blocked",
|
|
722
|
+
category: "blocked",
|
|
723
|
+
color: "RED",
|
|
724
|
+
description: "Waiting on another issue or an outside change"
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
name: "Done",
|
|
728
|
+
category: "done",
|
|
729
|
+
color: "GREEN",
|
|
730
|
+
description: "Completed"
|
|
731
|
+
}
|
|
732
|
+
],
|
|
733
|
+
fields: [{
|
|
734
|
+
name: "Priority",
|
|
735
|
+
type: "single_select",
|
|
736
|
+
options: [
|
|
737
|
+
"1 · Now",
|
|
738
|
+
"2 · Next",
|
|
739
|
+
"3 · Process"
|
|
740
|
+
]
|
|
741
|
+
}],
|
|
742
|
+
views: [
|
|
743
|
+
{
|
|
744
|
+
name: "Active",
|
|
745
|
+
layout: "board",
|
|
746
|
+
filter: "-status:Someday -status:Done",
|
|
747
|
+
default: true
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
name: "Backlog",
|
|
751
|
+
layout: "board",
|
|
752
|
+
filter: "status:Someday"
|
|
753
|
+
},
|
|
754
|
+
{
|
|
755
|
+
name: "Done",
|
|
756
|
+
layout: "table",
|
|
757
|
+
filter: "status:Done"
|
|
758
|
+
}
|
|
759
|
+
],
|
|
760
|
+
rules: ["Auto-add sub-issues to project"]
|
|
761
|
+
},
|
|
762
|
+
sprint: {
|
|
763
|
+
name: "sprint",
|
|
764
|
+
statuses: [
|
|
765
|
+
{
|
|
766
|
+
name: "Todo",
|
|
767
|
+
category: "planned",
|
|
768
|
+
color: "BLUE"
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
name: "In Progress",
|
|
772
|
+
category: "active",
|
|
773
|
+
color: "YELLOW"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
name: "In Review",
|
|
777
|
+
category: "review",
|
|
778
|
+
color: "ORANGE"
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
name: "Blocked",
|
|
782
|
+
category: "blocked",
|
|
783
|
+
color: "RED"
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
name: "Done",
|
|
787
|
+
category: "done",
|
|
788
|
+
color: "GREEN"
|
|
789
|
+
}
|
|
790
|
+
],
|
|
791
|
+
fields: [{
|
|
792
|
+
name: "Sprint",
|
|
793
|
+
type: "text"
|
|
794
|
+
}],
|
|
795
|
+
views: [{
|
|
796
|
+
name: "Active",
|
|
797
|
+
layout: "table",
|
|
798
|
+
filter: "-status:Done",
|
|
799
|
+
default: true
|
|
800
|
+
}, {
|
|
801
|
+
name: "Done",
|
|
802
|
+
layout: "table",
|
|
803
|
+
filter: "status:Done"
|
|
804
|
+
}]
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
// src/commands/setup/derived-properties/derived-properties.ts
|
|
117
808
|
/**
|
|
118
809
|
* Repo archetype, in priority order:
|
|
119
810
|
* 1. `*-template` repo name → `template` (independent of package shape).
|
|
@@ -153,6 +844,7 @@ function deriveProfile(input) {
|
|
|
153
844
|
if (pkg?.private) return "app";
|
|
154
845
|
return "library";
|
|
155
846
|
}
|
|
847
|
+
/** The framework and build-tool names `deriveStack()` can detect, in the order it lists them; `StackName` is derived from it. */
|
|
156
848
|
const KNOWN_STACK_DEPS = [
|
|
157
849
|
"next",
|
|
158
850
|
"vite",
|
|
@@ -192,6 +884,7 @@ function deriveCapabilities(providers) {
|
|
|
192
884
|
* a Phase B (GitHub App) refinement once it can post *why* on a check run.
|
|
193
885
|
*/
|
|
194
886
|
const REQUIRED_BASELINE = ["source", "ci"];
|
|
887
|
+
/** Whether a repo's capabilities include the required baseline (`source` and `ci`); `non-compliant` means drift. */
|
|
195
888
|
function deriveCompliance(capabilities) {
|
|
196
889
|
return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
|
|
197
890
|
}
|
|
@@ -213,287 +906,385 @@ function missingCapabilities(capabilities) {
|
|
|
213
906
|
*/
|
|
214
907
|
async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
215
908
|
const results = [];
|
|
216
|
-
for (const { slug, dir = "packages" } of workspacePackages)
|
|
217
|
-
const
|
|
218
|
-
results.push(
|
|
219
|
-
}
|
|
909
|
+
for (const { slug, dir = "packages", path } of workspacePackages) {
|
|
910
|
+
const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
|
|
911
|
+
if (pkg) results.push(pkg);
|
|
912
|
+
}
|
|
220
913
|
return results;
|
|
221
914
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
915
|
+
// src/commands/setup/labels.ts
|
|
916
|
+
/**
|
|
917
|
+
* The labels every repository gets from `setup`, with their GitHub colours (hex, no `#`) and descriptions. A
|
|
918
|
+
* plugin that makes labels of its own, such as Linear's setup, takes the colour of the one with the same name.
|
|
919
|
+
*/
|
|
920
|
+
const CANONICAL_LABELS = [
|
|
921
|
+
{
|
|
922
|
+
name: "bug",
|
|
923
|
+
color: "d73a4a",
|
|
924
|
+
description: "Something isn't working"
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
name: "chore",
|
|
928
|
+
color: "ededed",
|
|
929
|
+
description: "Maintenance, no user-facing change"
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
name: "ci",
|
|
933
|
+
color: "0075ca",
|
|
934
|
+
description: "CI/CD pipeline changes"
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
name: "dependencies",
|
|
938
|
+
color: "0366d6",
|
|
939
|
+
description: "Dependency update"
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
name: "documentation",
|
|
943
|
+
color: "0075ca",
|
|
944
|
+
description: "Documentation only"
|
|
945
|
+
},
|
|
946
|
+
{
|
|
947
|
+
name: "duplicate",
|
|
948
|
+
color: "cfd3d7",
|
|
949
|
+
description: "Already reported"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
name: "enhancement",
|
|
953
|
+
color: "a2eeef",
|
|
954
|
+
description: "New feature or request"
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
name: "epic",
|
|
958
|
+
color: "5319e7",
|
|
959
|
+
description: "A body of work made of several issues"
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
name: "good first issue",
|
|
963
|
+
color: "7057ff",
|
|
964
|
+
description: "Good for newcomers"
|
|
965
|
+
},
|
|
966
|
+
{
|
|
967
|
+
name: "help wanted",
|
|
968
|
+
color: "008672",
|
|
969
|
+
description: "Extra attention needed"
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
name: "invalid",
|
|
973
|
+
color: "e4e669",
|
|
974
|
+
description: "Doesn't seem right"
|
|
975
|
+
},
|
|
976
|
+
{
|
|
977
|
+
name: "performance",
|
|
978
|
+
color: "fbca04",
|
|
979
|
+
description: "Performance improvement"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
name: "question",
|
|
983
|
+
color: "d876e3",
|
|
984
|
+
description: "Further information requested"
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
name: "refactor",
|
|
988
|
+
color: "cfd3d7",
|
|
989
|
+
description: "Code restructuring"
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
name: "released",
|
|
993
|
+
color: "ededed",
|
|
994
|
+
description: "Included in a release"
|
|
995
|
+
},
|
|
996
|
+
{
|
|
997
|
+
name: "test",
|
|
998
|
+
color: "bfd4f2",
|
|
999
|
+
description: "Test-related changes"
|
|
1000
|
+
},
|
|
1001
|
+
{
|
|
1002
|
+
name: "triage",
|
|
1003
|
+
color: "e4e669",
|
|
1004
|
+
description: "Needs investigation"
|
|
1005
|
+
},
|
|
1006
|
+
{
|
|
1007
|
+
name: "wontfix",
|
|
1008
|
+
color: "ffffff",
|
|
1009
|
+
description: "Won't be addressed"
|
|
270
1010
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
1011
|
+
];
|
|
1012
|
+
// src/area-labels/area-for-scope/area-for-scope.ts
|
|
1013
|
+
/**
|
|
1014
|
+
* The area a title scope means, by `repo.labels.scopes` (spec `tech-github-area-labels`): `sentinel` gives the area it is
|
|
1015
|
+
* mapped to. The scope is matched without regard to case; a scope the map does not name, or a repo with no map, gives
|
|
1016
|
+
* `undefined`. It is the area's name, not its label: `areaLabelsForTitle()` adds the prefix.
|
|
1017
|
+
*/
|
|
1018
|
+
function areaForScope(scope, scopes) {
|
|
1019
|
+
const wanted = scope.trim().toLowerCase();
|
|
1020
|
+
for (const [name, area] of Object.entries(scopes ?? {})) if (name.toLowerCase() === wanted) return area;
|
|
1021
|
+
}
|
|
1022
|
+
// src/area-labels/area-prefix/area-prefix.ts
|
|
1023
|
+
/** The prefix of an area label (spec `tech-github-area-labels`): `area:cli`. */
|
|
1024
|
+
const AREA_PREFIX = "area:";
|
|
1025
|
+
// src/area-labels/area-label-defs/area-label-defs.ts
|
|
1026
|
+
/** The colour of every area label: one family, one colour (spec `tech-github-area-labels`). */
|
|
1027
|
+
const AREA_LABEL_COLOR = "c5def5";
|
|
1028
|
+
/** GitHub refuses a label description longer than this. */
|
|
1029
|
+
const MAX_DESCRIPTION = 100;
|
|
1030
|
+
/**
|
|
1031
|
+
* The labels `holocron setup` makes for the areas a repo declares: `area:<name>`, the one family colour and the
|
|
1032
|
+
* description `Changes under <paths>` from the area's own (not excluded) patterns, cut to GitHub's 100 characters. They
|
|
1033
|
+
* are never part of `CANONICAL_LABELS`: an area names this repo's folders, so another repo has none of them.
|
|
1034
|
+
*/
|
|
1035
|
+
function areaLabelDefs(areas) {
|
|
1036
|
+
return Object.entries(areas ?? {}).map(([name, patterns]) => {
|
|
1037
|
+
const text = `Changes under ${patterns.filter((p) => !p.startsWith("!")).join(", ")}`;
|
|
1038
|
+
const description = text.length > MAX_DESCRIPTION ? `${text.slice(0, 99)}…` : text;
|
|
277
1039
|
return {
|
|
278
|
-
|
|
279
|
-
|
|
1040
|
+
name: `${AREA_PREFIX}${name}`,
|
|
1041
|
+
color: AREA_LABEL_COLOR,
|
|
1042
|
+
description
|
|
280
1043
|
};
|
|
281
|
-
}
|
|
282
|
-
if (cardinality === "single") throw new ConfigError(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
|
|
283
|
-
return {
|
|
284
|
-
cardinality: "many",
|
|
285
|
-
tuples: raw.map((entry, idx) => {
|
|
286
|
-
if (typeof entry === "string") return normalizeEntry(entry);
|
|
287
|
-
if (isOptionsTuple(entry)) return normalizeEntry(entry);
|
|
288
|
-
throw new ConfigError(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
|
|
289
|
-
})
|
|
290
|
-
};
|
|
1044
|
+
});
|
|
291
1045
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
for (
|
|
297
|
-
|
|
298
|
-
|
|
1046
|
+
// src/area-labels/path-matches/path-matches.ts
|
|
1047
|
+
/** Turns one glob into the expression a whole path must match: `**` crosses folders, `*` and `?` stay in one. */
|
|
1048
|
+
function globToRegExp(glob) {
|
|
1049
|
+
let out = "";
|
|
1050
|
+
for (let i = 0; i < glob.length; i++) {
|
|
1051
|
+
const c = glob.charAt(i);
|
|
1052
|
+
if (c === "*") {
|
|
1053
|
+
if (glob.charAt(i + 1) === "*") {
|
|
1054
|
+
const slash = glob.charAt(i + 2) === "/";
|
|
1055
|
+
out += slash ? "(?:.*/)?" : ".*";
|
|
1056
|
+
i += slash ? 2 : 1;
|
|
1057
|
+
} else out += "[^/]*";
|
|
1058
|
+
} else if (c === "?") out += "[^/]";
|
|
1059
|
+
else out += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
299
1060
|
}
|
|
300
|
-
|
|
301
|
-
let docs;
|
|
302
|
-
if (raw.docs !== void 0) {
|
|
303
|
-
if (!raw.docs.build) throw new ConfigError("`docs.build` is required when `docs` is set");
|
|
304
|
-
docs = raw.docs;
|
|
305
|
-
}
|
|
306
|
-
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
307
|
-
return {
|
|
308
|
-
name: raw.name,
|
|
309
|
-
description: raw.description,
|
|
310
|
-
homepage,
|
|
311
|
-
org: raw.org,
|
|
312
|
-
domain: raw.domain,
|
|
313
|
-
repo: raw.repo,
|
|
314
|
-
tasks: raw.tasks,
|
|
315
|
-
syncScripts: raw.syncScripts,
|
|
316
|
-
holocronScript: raw.holocronScript,
|
|
317
|
-
extraRequiredChecks: raw.extraRequiredChecks,
|
|
318
|
-
hooks: raw.hooks,
|
|
319
|
-
providers,
|
|
320
|
-
apps: raw.apps ?? [],
|
|
321
|
-
doctor: raw.doctor ?? {},
|
|
322
|
-
agent: raw.agent,
|
|
323
|
-
skills: raw.skills,
|
|
324
|
-
docs,
|
|
325
|
-
env: raw.env,
|
|
326
|
-
log: raw.log,
|
|
327
|
-
telemetry: raw.telemetry
|
|
328
|
-
};
|
|
1061
|
+
return new RegExp(`^${out}$`);
|
|
329
1062
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
1063
|
+
/**
|
|
1064
|
+
* Whether a repository path (forward slashes, from the root) matches one pattern of `repo.labels.areas`. A pattern with
|
|
1065
|
+
* a `*` or `?` is a glob (`cli/**`, `docs/**` then `/*.md`); one without is a file (`turbo.json`) or a folder and
|
|
1066
|
+
* everything under it (`.holocron`, `.holocron/`).
|
|
1067
|
+
*/
|
|
1068
|
+
function pathMatches(path, pattern) {
|
|
1069
|
+
const clean = path.replace(/^\.?\//, "");
|
|
1070
|
+
if (/[*?]/.test(pattern)) return globToRegExp(pattern.replace(/^\.?\//, "")).test(clean);
|
|
1071
|
+
const plain = pattern.replace(/^\.?\//, "").replace(/\/+$/, "");
|
|
1072
|
+
return clean === plain || clean.startsWith(`${plain}/`);
|
|
334
1073
|
}
|
|
1074
|
+
// src/area-labels/area-labels-for-files/area-labels-for-files.ts
|
|
335
1075
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
* const preset = compose(node(), docs());
|
|
349
|
-
*
|
|
350
|
-
* // library with docs
|
|
351
|
-
* const preset = compose(node(), typecheck(), docs());
|
|
352
|
-
*
|
|
353
|
-
* // nextjs() is a bundle that returns Capability[]
|
|
354
|
-
* const preset = compose(node(), nextjs());
|
|
355
|
-
*/
|
|
356
|
-
function compose(...args) {
|
|
357
|
-
const flat = args.flat();
|
|
358
|
-
const byId = /* @__PURE__ */ new Map();
|
|
359
|
-
for (const cap of flat) byId.set(cap.id, cap);
|
|
360
|
-
const caps = [...byId.values()];
|
|
361
|
-
const available = new Set(caps.map((c) => c.id));
|
|
362
|
-
const errors = [];
|
|
363
|
-
for (const cap of caps) for (const req of cap.requires ?? []) if (!available.has(req)) errors.push(`"${cap.id}" requires "${req}"`);
|
|
364
|
-
if (errors.length > 0) throw new ConfigError(`compose(): unmet dependencies — ${errors.join(", ")}`);
|
|
365
|
-
const taskMap = /* @__PURE__ */ new Map();
|
|
366
|
-
for (const cap of caps) for (const entry of cap.tasks ?? []) taskMap.set(taskName(entry), entry);
|
|
367
|
-
let providers = {};
|
|
368
|
-
for (const cap of caps) if (cap.providers) providers = {
|
|
369
|
-
...providers,
|
|
370
|
-
...cap.providers
|
|
371
|
-
};
|
|
372
|
-
const checksSeen = /* @__PURE__ */ new Set();
|
|
373
|
-
const extraRequiredChecks = [];
|
|
374
|
-
for (const cap of caps) for (const check of cap.extraRequiredChecks ?? []) if (!checksSeen.has(check)) {
|
|
375
|
-
checksSeen.add(check);
|
|
376
|
-
extraRequiredChecks.push(check);
|
|
377
|
-
}
|
|
378
|
-
let repo = {};
|
|
379
|
-
for (const cap of caps) {
|
|
380
|
-
if (!cap.repo) continue;
|
|
381
|
-
const { properties, topics, teams, ...scalars } = cap.repo;
|
|
382
|
-
repo = {
|
|
383
|
-
...repo,
|
|
384
|
-
...scalars
|
|
385
|
-
};
|
|
386
|
-
if (properties) repo.properties = {
|
|
387
|
-
...repo.properties,
|
|
388
|
-
...properties
|
|
389
|
-
};
|
|
390
|
-
if (topics) {
|
|
391
|
-
const merged = /* @__PURE__ */ new Set([...repo.topics ?? [], ...topics]);
|
|
392
|
-
repo.topics = [...merged];
|
|
393
|
-
}
|
|
394
|
-
if (teams) {
|
|
395
|
-
const teamMap = new Map((repo.teams ?? []).map((t) => [typeof t === "string" ? t : t.slug, t]));
|
|
396
|
-
for (const t of teams) teamMap.set(typeof t === "string" ? t : t.slug, t);
|
|
397
|
-
repo.teams = [...teamMap.values()];
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
let org;
|
|
401
|
-
let domain;
|
|
402
|
-
let docs;
|
|
403
|
-
for (const cap of caps) {
|
|
404
|
-
if (cap.org !== void 0) org = cap.org;
|
|
405
|
-
if (cap.domain !== void 0) domain = cap.domain;
|
|
406
|
-
if (cap.docs !== void 0) docs = cap.docs;
|
|
1076
|
+
* The `area:<name>` labels a set of changed paths earns, in the order the areas are declared (spec
|
|
1077
|
+
* `tech-github-area-labels`). An area's patterns are the ones in `repo.labels.areas`; one starting with `!` takes a path
|
|
1078
|
+
* out of the area (`docs/**` with `!docs/wiki/**`), so a path is in an area when some pattern includes it and none
|
|
1079
|
+
* excludes it. A path in no area earns nothing, which is right, not a failure. This is the one mapping from changed
|
|
1080
|
+
* folders to labels in the CLI; Sentinel's `planAreaLabels()` is meant to agree with it.
|
|
1081
|
+
*/
|
|
1082
|
+
function areaLabelsForFiles(files, areas) {
|
|
1083
|
+
const labels = [];
|
|
1084
|
+
for (const [name, patterns] of Object.entries(areas ?? {})) {
|
|
1085
|
+
const include = patterns.filter((p) => !p.startsWith("!"));
|
|
1086
|
+
const exclude = patterns.filter((p) => p.startsWith("!")).map((p) => p.slice(1));
|
|
1087
|
+
if (files.some((file) => include.some((p) => pathMatches(file, p)) && !exclude.some((p) => pathMatches(file, p)))) labels.push(`${AREA_PREFIX}${name}`);
|
|
407
1088
|
}
|
|
408
|
-
return
|
|
409
|
-
tasks: [...taskMap.values()],
|
|
410
|
-
providers,
|
|
411
|
-
repo,
|
|
412
|
-
extraRequiredChecks,
|
|
413
|
-
...org !== void 0 ? { org } : {},
|
|
414
|
-
...domain !== void 0 ? { domain } : {},
|
|
415
|
-
...docs !== void 0 ? { docs } : {}
|
|
416
|
-
};
|
|
1089
|
+
return labels;
|
|
417
1090
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
1091
|
+
// src/area-labels/title-scopes/title-scopes.ts
|
|
1092
|
+
const TITLE = /^\s*[A-Za-z]+(?:\(([^)]*)\))?!?:/;
|
|
1093
|
+
/**
|
|
1094
|
+
* The scopes of a Conventional Commit title: `feat(sentinel): ...` gives `["sentinel"]`, `fix(cli, docs)!: ...` gives
|
|
1095
|
+
* `["cli", "docs"]`. A title with no scope, or that is not in the `type(scope): subject` form, gives none.
|
|
1096
|
+
*/
|
|
1097
|
+
function titleScopes(title) {
|
|
1098
|
+
const scope = TITLE.exec(title)?.[1];
|
|
1099
|
+
if (scope === void 0) return [];
|
|
1100
|
+
return scope.split(",").map((s) => s.trim()).filter((s) => s !== "");
|
|
422
1101
|
}
|
|
423
|
-
|
|
424
|
-
//#region src/config/load-config.ts
|
|
1102
|
+
// src/area-labels/area-labels-for-title/area-labels-for-title.ts
|
|
425
1103
|
/**
|
|
426
|
-
* `
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* holocron-specific parts: filling `name` / `repo.name` defaults and
|
|
431
|
-
* running the config through `resolveConfig`.
|
|
432
|
-
*
|
|
433
|
-
* Probe order is TS-first (`.ts` → `.js` → `.mjs` → `.cjs` → `.json`) —
|
|
434
|
-
* see ADR-0010 / issue #75 / #81.
|
|
1104
|
+
* The `area:<name>` labels the scopes of an issue's title earn, through `repo.labels.scopes` (spec
|
|
1105
|
+
* `tech-github-area-labels`): `feat(sentinel): ...` gives `["area:sentinel"]`. An issue has no changed files, so this is
|
|
1106
|
+
* its only source of an area. A title with no scope, or a scope the map does not name, earns nothing; the same area
|
|
1107
|
+
* from two scopes is given once, in the order of the title.
|
|
435
1108
|
*/
|
|
436
|
-
|
|
1109
|
+
function areaLabelsForTitle(title, scopes) {
|
|
1110
|
+
const labels = [];
|
|
1111
|
+
for (const scope of titleScopes(title)) {
|
|
1112
|
+
const area = areaForScope(scope, scopes);
|
|
1113
|
+
if (area === void 0) continue;
|
|
1114
|
+
const label = `${AREA_PREFIX}${area}`;
|
|
1115
|
+
if (!labels.includes(label)) labels.push(label);
|
|
1116
|
+
}
|
|
1117
|
+
return labels;
|
|
1118
|
+
}
|
|
1119
|
+
// src/commands/token-rotation/token-rotation.ts
|
|
1120
|
+
/** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
|
|
1121
|
+
const DEFAULT_TOKEN_ROTATION = {
|
|
1122
|
+
maxAgeDays: 90,
|
|
1123
|
+
warnDays: 14
|
|
1124
|
+
};
|
|
1125
|
+
const DAY_MS = 864e5;
|
|
1126
|
+
/** The whole days from `from` to `to`, rounded down (negative once `to` is past). */
|
|
1127
|
+
function daysBetween(from, to) {
|
|
1128
|
+
return Math.floor((to.getTime() - from.getTime()) / DAY_MS);
|
|
1129
|
+
}
|
|
1130
|
+
/** `2026-11-13` of a valid date. */
|
|
1131
|
+
const day = (d) => d.toISOString().slice(0, 10);
|
|
1132
|
+
/** A valid `Date` of an ISO string, or `undefined` when there is none or it does not parse. */
|
|
1133
|
+
function parse(value) {
|
|
1134
|
+
if (value === void 0) return void 0;
|
|
1135
|
+
const date = new Date(value);
|
|
1136
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
1137
|
+
}
|
|
437
1138
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
1139
|
+
* Rows saying whether a token is due for rotation, from what its provider exposes. Provider-neutral: a token probe reads
|
|
1140
|
+
* the lifetime however its provider offers it and hands it here, with the layer's `rotation` from `tokenExpectations()`.
|
|
1141
|
+
* `lifetime` is `undefined` when the provider exposes nothing (the row says so rather than passing), and a date the
|
|
1142
|
+
* provider gave that does not parse is an `info` row, never a pass. An expired or near-expiry token fails, and so does
|
|
1143
|
+
* one older than `maxAgeDays`. Only dates are printed, never the token.
|
|
441
1144
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
1145
|
+
function tokenRotationRows(lifetime, rotation, now) {
|
|
1146
|
+
if (!lifetime) return [{
|
|
1147
|
+
status: "info",
|
|
1148
|
+
label: "rotation",
|
|
1149
|
+
detail: `the provider does not expose this token's age or expiry; rotate it by hand every ${rotation.maxAgeDays} days`
|
|
1150
|
+
}];
|
|
1151
|
+
const rows = [];
|
|
1152
|
+
const expires = parse(lifetime.expiresAt);
|
|
1153
|
+
if (lifetime.expiresAt !== void 0 && !expires) rows.push({
|
|
1154
|
+
status: "info",
|
|
1155
|
+
label: "expiry",
|
|
1156
|
+
detail: "the provider's expiry date could not be read"
|
|
446
1157
|
});
|
|
447
|
-
if (
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
1158
|
+
else if (expires) {
|
|
1159
|
+
const left = daysBetween(now, expires);
|
|
1160
|
+
if (expires.getTime() <= now.getTime()) rows.push({
|
|
1161
|
+
status: "fail",
|
|
1162
|
+
label: "expiry",
|
|
1163
|
+
detail: `expired on ${day(expires)}`
|
|
1164
|
+
});
|
|
1165
|
+
else if (left < rotation.warnDays) rows.push({
|
|
1166
|
+
status: "fail",
|
|
1167
|
+
label: "expiry",
|
|
1168
|
+
detail: `expires on ${day(expires)} (${left} days left, warns under ${rotation.warnDays}); rotate it`
|
|
1169
|
+
});
|
|
1170
|
+
else rows.push({
|
|
1171
|
+
status: "ok",
|
|
1172
|
+
label: "expiry",
|
|
1173
|
+
detail: `expires on ${day(expires)} (${left} days left)`
|
|
1174
|
+
});
|
|
1175
|
+
} else rows.push({
|
|
1176
|
+
status: "info",
|
|
1177
|
+
label: "expiry",
|
|
1178
|
+
detail: "the token has no expiry"
|
|
1179
|
+
});
|
|
1180
|
+
const created = parse(lifetime.createdAt);
|
|
1181
|
+
if (lifetime.createdAt !== void 0 && !created) rows.push({
|
|
1182
|
+
status: "info",
|
|
1183
|
+
label: "age",
|
|
1184
|
+
detail: "the provider's creation date could not be read"
|
|
1185
|
+
});
|
|
1186
|
+
else if (created) {
|
|
1187
|
+
const age = daysBetween(created, now);
|
|
1188
|
+
const due = age > rotation.maxAgeDays;
|
|
1189
|
+
rows.push({
|
|
1190
|
+
status: due ? "fail" : "ok",
|
|
1191
|
+
label: "age",
|
|
1192
|
+
detail: due ? `${age} days old since ${day(created)}, over the ${rotation.maxAgeDays} days allowed; rotate it` : `${age} days old since ${day(created)} (rotate after ${rotation.maxAgeDays})`
|
|
1193
|
+
});
|
|
1194
|
+
} else rows.push({
|
|
1195
|
+
status: "info",
|
|
1196
|
+
label: "age",
|
|
1197
|
+
detail: "the provider does not say when the token was made"
|
|
1198
|
+
});
|
|
1199
|
+
return rows;
|
|
452
1200
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
1201
|
+
// src/commands/token-expectations/token-expectations.ts
|
|
1202
|
+
/**
|
|
1203
|
+
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
1204
|
+
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
1205
|
+
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
1206
|
+
*/
|
|
1207
|
+
function tokenExpectations(tokens, filter = {}) {
|
|
1208
|
+
const found = [];
|
|
1209
|
+
for (const token of tokens) {
|
|
1210
|
+
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
1211
|
+
const { layers = [], permissions = {} } = token.expect;
|
|
1212
|
+
for (const layer of ENVIRONMENT_LAYERS) {
|
|
1213
|
+
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
1214
|
+
const rules = permissions[layer];
|
|
1215
|
+
if (!rules && !layers.includes(layer)) continue;
|
|
1216
|
+
const entries = Object.entries(rules ?? {});
|
|
1217
|
+
found.push({
|
|
1218
|
+
envName: token.envName,
|
|
1219
|
+
layer,
|
|
1220
|
+
rules: rules ?? {},
|
|
1221
|
+
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
1222
|
+
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name),
|
|
1223
|
+
rotation: {
|
|
1224
|
+
...DEFAULT_TOKEN_ROTATION,
|
|
1225
|
+
...token.expect.rotation
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
462
1229
|
}
|
|
463
|
-
|
|
464
|
-
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
465
|
-
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
466
|
-
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
467
|
-
if (manifest.hooks !== void 0) result.hooks = manifest.hooks;
|
|
468
|
-
if (manifest.extraRequiredChecks) result.extraRequiredChecks = [...result.extraRequiredChecks ?? [], ...manifest.extraRequiredChecks];
|
|
469
|
-
return result;
|
|
1230
|
+
return found;
|
|
470
1231
|
}
|
|
471
|
-
|
|
1232
|
+
// src/commands/auth-export/stdout-kind/stdout-kind.ts
|
|
1233
|
+
/**
|
|
1234
|
+
* What file descriptor `fd` (stdout) is, for deciding where tokens may go: a `terminal`, a `pipe` (a FIFO, or the
|
|
1235
|
+
* socket some shells and runners use for one), or `other` (a regular file, a device, or anything that cannot be
|
|
1236
|
+
* inspected). Only a pipe is safe to write the lines to, so anything unknown is `other`.
|
|
1237
|
+
*/
|
|
1238
|
+
function stdoutKind(isTerminal, fd = 1, stat = fstatSync) {
|
|
1239
|
+
if (isTerminal) return "terminal";
|
|
472
1240
|
try {
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
return typeof pkg.name === "string" ? pkg.name.replace(/^@[^/]+\//, "") : void 0;
|
|
1241
|
+
const s = stat(fd);
|
|
1242
|
+
return s.isFIFO() || s.isSocket() ? "pipe" : "other";
|
|
476
1243
|
} catch {
|
|
477
|
-
return;
|
|
1244
|
+
return "other";
|
|
478
1245
|
}
|
|
479
1246
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
1247
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
1248
|
+
/**
|
|
1249
|
+
* The vault Environment `holocron sync secrets --env <environment>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
1250
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
1251
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
1252
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
1253
|
+
*
|
|
1254
|
+
* @param id - The `--env` value the user gave.
|
|
1255
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
1256
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
1257
|
+
*/
|
|
1258
|
+
async function resolveEnvironmentId(id, input) {
|
|
1259
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
1260
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
491
1261
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
1262
|
+
// src/private-dir/ignore-advice/ignore-advice.ts
|
|
1263
|
+
/** The line that says how to fix a credentials path the version control ignore rules do not cover. */
|
|
1264
|
+
function ignoreAdvice(isDefault, choose) {
|
|
1265
|
+
return isDefault ? "the private directory's ignore rule is missing: run `holocron sync` to add it" : `add it to .gitignore, or ${choose}`;
|
|
1266
|
+
}
|
|
1267
|
+
/** The file `export tokens` and `new github-app` write by default, relative to the repository root. */
|
|
1268
|
+
const PRIVATE_CREDENTIALS_FILE = `.holocron/.private/.credentials`;
|
|
1269
|
+
// src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
|
|
1270
|
+
/**
|
|
1271
|
+
* The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
|
|
1272
|
+
* under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
|
|
1273
|
+
* about a path whose directory exists and the file cannot be written without it.
|
|
1274
|
+
*/
|
|
1275
|
+
function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
|
|
1276
|
+
recursive: true,
|
|
1277
|
+
mode: 448
|
|
1278
|
+
})) {
|
|
1279
|
+
if (file) return {
|
|
1280
|
+
path: resolve(base, file),
|
|
1281
|
+
isDefault: false
|
|
1282
|
+
};
|
|
1283
|
+
const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
|
|
1284
|
+
makeDir(dirname(path));
|
|
1285
|
+
return {
|
|
1286
|
+
path,
|
|
1287
|
+
isDefault: true
|
|
1288
|
+
};
|
|
497
1289
|
}
|
|
498
|
-
|
|
499
|
-
export { AuthError, CARDINALITY, ConfigError, ConfigFileError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, compose, createFeatureResolver, createResolveToken, createRestClient, defineConfig, deleteToken, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, getToken, isMulti, listStoredProviders, loadConfig, missingCapabilities, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, setToken };
|
|
1290
|
+
export { AREA_LABEL_COLOR, AREA_PREFIX, AuthError, BUILTIN_TEMPLATES, CANONICAL_LABELS, CARDINALITY, CUSTOM_EMOJI, ConfigError, ConfigFileError, DEFAULT_TEMPLATES_DIR, DEFAULT_TOKEN_ROTATION, EMOJI_MEDIA_DIR, ElevationRequiredError, HOLOCRON_AREAS, KNOWN_STACK_DEPS, MAX_EMOJI_BYTES, MissingTokenError, PRIVATE_CREDENTIALS_FILE, ProviderApiError, REQUIRED_CAPABILITIES, SHARED_AREAS, WebhookVerificationError, areaForScope, areaLabelDefs, areaLabelsForFiles, areaLabelsForTitle, compose, connectionProbe, coverageExpectations, createFeatureResolver, createResolveToken, createRestClient, credentialsEnvironment, defineConfig, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, emojiConflictProblem, ignoreAdvice, isMulti, keyring, layoutEmojis, layoutReactions, loadConfig, loadEmojiImage, missingCapabilities, orderKeys, parseReaction, pathMatches, pickByCreation, placeAreas, planPullRequestStatus, planReconcile, reactionProblem, reactionSpelling, readKeysLimited, readLinks, readWorkspacePackageJsons, reportProgress, resolveConfig, resolveCredentialsFile, resolveEntry, resolveEnvironmentId, resolvePluginPackage, resolveProjectOptions, resolveValue, roleTeamProblem, sourceProblem, stdoutKind, syncRoles, tagEmojiProblem, titleScopes, tokenExpectations, tokenRotationRows };
|