@theholocron/cli 5.0.0-alpha.38 → 5.0.0-alpha.381
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 +530 -105
- package/dist/cli.mjs +21768 -6627
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-BVYtgrmR.mjs +578 -0
- package/dist/config-system-BuzBMJRw.d.mts +929 -0
- package/dist/index-BU3l3vpX.d.mts +2884 -0
- package/dist/index.d.mts +375 -594
- package/dist/index.mjs +406 -364
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +53 -4
- package/dist/presets.d.mts +221 -0
- package/dist/presets.mjs +439 -0
- package/package.json +42 -35
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,337 @@
|
|
|
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, i as loadConfig, l as credentialsEnvironment, n as compose, o as HOLOCRON_AREAS, r as defineConfig, s as SHARED_AREAS, t as ConfigFileError, u as resolveConfig } from "./config-system-BVYtgrmR.mjs";
|
|
4
3
|
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
4
|
+
import { AuthError, createFeatureResolver as createFeatureResolver$1, createKeyring, createResolveToken as createResolveToken$1, resolveValue } from "@theholocron/kyber/secrets";
|
|
5
|
+
import { describeError, style } from "@theholocron/kyber/ui";
|
|
6
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
7
|
+
import { createRestClient } from "@theholocron/http-client";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
10
|
+
import { connectionProbe as connectionProbe$1 } from "@theholocron/kyber/checks";
|
|
11
|
+
// src/auth.ts
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* The CLI's credentials: the OS keyring every plugin's bootstrap token lives in, and the two token resolvers built on
|
|
14
|
+
* it. Both are public, so a plugin's `src/auth.ts` is a one-line call.
|
|
15
|
+
*
|
|
16
|
+
* The keyring itself, with its best-effort failure model and its per-process cache, is `createKeyring` in
|
|
17
|
+
* `@theholocron/kyber/secrets`; this file only names the service. Managed via `holocron auth` subcommands and consulted
|
|
18
|
+
* last in every plugin's precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN). See
|
|
19
|
+
* `docs/wiki/specifications/tech-auth-bootstrap.spec.md`.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The holocron keyring: `get` answers `null` for "not stored" and for "keyring unavailable" alike, so callers fall
|
|
23
|
+
* through to env-var precedence, and remembers the answer for the process (`clearCache` forgets it); `set` and `delete`
|
|
24
|
+
* answer whether they did anything; `list` names the stored providers; `isAvailable` tells an outage from an empty keyring.
|
|
25
|
+
*/
|
|
26
|
+
const keyring = createKeyring({
|
|
27
|
+
service: "com.theholocron.cli",
|
|
28
|
+
binding: {
|
|
29
|
+
Entry,
|
|
30
|
+
findCredentials
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Kyber's `createResolveToken` with the keyring, the `HOLOCRON_ORG` variable and the `token` description
|
|
35
|
+
* `holocron doctor tokens` reads filled in, so a plugin stays at a one-liner call site. The chain is the flag, the
|
|
36
|
+
* plugin's variable, the vendor's variable, the `credentials` providers' variables, the keyring.
|
|
15
37
|
*/
|
|
16
|
-
function
|
|
17
|
-
return
|
|
38
|
+
function createResolveToken(config) {
|
|
39
|
+
return Object.assign(createResolveToken$1({
|
|
40
|
+
...config,
|
|
41
|
+
keyring: keyring.get,
|
|
42
|
+
orgEnvName: "HOLOCRON_ORG"
|
|
43
|
+
}), { token: {
|
|
44
|
+
envName: config.envName,
|
|
45
|
+
vendorEnvName: config.vendorEnvName,
|
|
46
|
+
keyringKey: config.keyringService
|
|
47
|
+
} });
|
|
18
48
|
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/auth/keyring.ts
|
|
21
49
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* can talk to its vendor's API) can be stored in the OS keyring under
|
|
26
|
-
* a single reverse-DNS service scope. Managed via `holocron auth`
|
|
27
|
-
* subcommands; consulted at position 4 in every plugin's auth
|
|
28
|
-
* precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN).
|
|
29
|
-
*
|
|
30
|
-
* See `docs/wiki/specifications/tech-auth-bootstrap.spec.md` for the design rationale.
|
|
31
|
-
*
|
|
32
|
-
* Failure model: keyring access is best-effort. Platforms without a
|
|
33
|
-
* supported credential store (some Linux CI images, sandboxed
|
|
34
|
-
* environments) will throw from the underlying library. Every export
|
|
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.
|
|
50
|
+
* Kyber's `createFeatureResolver` for a strict, single-feature token: the flag, the feature's variable, the
|
|
51
|
+
* `credentials` providers' variable of that name, the keyring. No broad-token fallback; if the feature's token is absent
|
|
52
|
+
* the operation fails with a message naming the exact variable to set and `holocron auth set`.
|
|
38
53
|
*/
|
|
39
|
-
|
|
54
|
+
function createFeatureResolver(config) {
|
|
55
|
+
return Object.assign(createFeatureResolver$1({
|
|
56
|
+
...config,
|
|
57
|
+
vendor: config.vendor ?? "GitHub",
|
|
58
|
+
setCommand: (key) => `holocron auth set ${key} <token>`,
|
|
59
|
+
keyring: keyring.get
|
|
60
|
+
}), { token: {
|
|
61
|
+
envName: config.envName,
|
|
62
|
+
keyringKey: config.keyringKey
|
|
63
|
+
} });
|
|
64
|
+
}
|
|
65
|
+
// src/plugin/order-keys/order-keys.ts
|
|
40
66
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
67
|
+
* Puts issue keys in creation order without asking the tracker: issue numbers (`#12`, `ENG-12`) rise with creation inside
|
|
68
|
+
* one repository or team, so the trailing number is the order. `oldest` is ascending, `newest` descending; keys with the
|
|
69
|
+
* same number keep their place. A key with no trailing number is an error, because nothing can be said of its age.
|
|
43
70
|
*/
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
function orderKeys(keys, order) {
|
|
72
|
+
const numbered = keys.map((key, index) => {
|
|
73
|
+
const match = /(\d+)\s*$/.exec(key);
|
|
74
|
+
if (!match) throw new Error(`Cannot order "${key}" by creation: it has no issue number.`);
|
|
75
|
+
return {
|
|
76
|
+
key,
|
|
77
|
+
index,
|
|
78
|
+
n: Number(match[1])
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const sign = order === "newest" ? -1 : 1;
|
|
82
|
+
return numbered.sort((a, b) => sign * (a.n - b.n) || a.index - b.index).map((e) => e.key);
|
|
51
83
|
}
|
|
84
|
+
// src/plugin/pick-by-creation/pick-by-creation.ts
|
|
52
85
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
86
|
+
* Keeps the first or last `limit` of a listing by creation time, returned oldest first. `createdAt` reads an item's
|
|
87
|
+
* ISO timestamp; items created in the same instant keep their listed order. The cut happens on what the listing already
|
|
88
|
+
* holds, so no request is spent on an item that is dropped.
|
|
56
89
|
*/
|
|
57
|
-
function
|
|
90
|
+
function pickByCreation(items, createdAt, order, limit) {
|
|
91
|
+
const ascending = items.map((item, index) => ({
|
|
92
|
+
item,
|
|
93
|
+
index,
|
|
94
|
+
at: Date.parse(createdAt(item))
|
|
95
|
+
})).sort((a, b) => a.at - b.at || a.index - b.index).map((e) => e.item);
|
|
96
|
+
return order === "newest" ? ascending.slice(Math.max(ascending.length - limit, 0)) : ascending.slice(0, limit);
|
|
97
|
+
}
|
|
98
|
+
// src/plugin/read-keys-limited/read-keys-limited.ts
|
|
99
|
+
/**
|
|
100
|
+
* Reads an explicit list of issues in creation order until `limit` of them are kept. The keys are sorted by number first
|
|
101
|
+
* (see {@link orderKeys}), then fetched in small steps of at most `concurrency`, each step no bigger than the places
|
|
102
|
+
* still open, so an issue that is later skipped (a pull request, a closed one) is replaced by the next key and nothing
|
|
103
|
+
* beyond the budget is fetched unless a skip made room. Within a step the fetches run together; the results keep the key
|
|
104
|
+
* order. The kept items come back oldest first, whichever end was chosen.
|
|
105
|
+
*/
|
|
106
|
+
async function readKeysLimited(input) {
|
|
107
|
+
const { keys, order, limit, concurrency, fetch, keep } = input;
|
|
108
|
+
const ordered = orderKeys(keys, order);
|
|
109
|
+
const kept = [];
|
|
110
|
+
let next = 0;
|
|
111
|
+
while (kept.length < limit && next < ordered.length) {
|
|
112
|
+
const step = ordered.slice(next, next + Math.min(concurrency, limit - kept.length));
|
|
113
|
+
next += step.length;
|
|
114
|
+
const fetched = await Promise.all(step.map((key) => fetch(key)));
|
|
115
|
+
for (const item of fetched) if (keep(item)) kept.push(item);
|
|
116
|
+
}
|
|
117
|
+
return order === "newest" ? kept.reverse() : kept;
|
|
118
|
+
}
|
|
119
|
+
// src/commands/notifications-sync-roles/links.ts
|
|
120
|
+
const EMPTY_LINKS = {
|
|
121
|
+
version: 1,
|
|
122
|
+
links: []
|
|
123
|
+
};
|
|
124
|
+
const DIGITS = /^\d{1,20}$/;
|
|
125
|
+
/** 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. */
|
|
126
|
+
function parseLinks(text) {
|
|
127
|
+
let raw;
|
|
58
128
|
try {
|
|
59
|
-
|
|
129
|
+
raw = JSON.parse(text);
|
|
60
130
|
} catch {
|
|
61
|
-
|
|
131
|
+
throw new Error("the links file is not valid JSON");
|
|
132
|
+
}
|
|
133
|
+
const file = raw;
|
|
134
|
+
if (file.version !== 1) throw new Error(`the links file has version ${JSON.stringify(file.version)}; expected 1`);
|
|
135
|
+
if (!Array.isArray(file.links)) throw new Error("the links file has no `links` list");
|
|
136
|
+
const links = file.links.map((entry, i) => {
|
|
137
|
+
const e = entry;
|
|
138
|
+
if (typeof e.github !== "string" || !DIGITS.test(e.github)) throw new Error(`links[${i}]: \`github\` must be a numeric user id string`);
|
|
139
|
+
if (typeof e.member !== "string" || !DIGITS.test(e.member)) throw new Error(`links[${i}]: \`member\` must be a numeric id string`);
|
|
140
|
+
if (typeof e.login !== "string") throw new Error(`links[${i}]: \`login\` must be a string`);
|
|
141
|
+
return {
|
|
142
|
+
github: e.github,
|
|
143
|
+
login: e.login,
|
|
144
|
+
member: e.member
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
for (const key of ["github", "member"]) {
|
|
148
|
+
const seen = /* @__PURE__ */ new Set();
|
|
149
|
+
for (const [i, link] of links.entries()) {
|
|
150
|
+
if (seen.has(link[key])) throw new Error(`links[${i}]: \`${key}\` ${link[key]} appears more than once`);
|
|
151
|
+
seen.add(link[key]);
|
|
152
|
+
}
|
|
62
153
|
}
|
|
154
|
+
return {
|
|
155
|
+
version: 1,
|
|
156
|
+
links
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** Where the links file is: the layout's `links`, else `<org>/.github-private` and `notifications/<provider>-links.json`. */
|
|
160
|
+
function linksLocation(layout, org, provider) {
|
|
161
|
+
const repo = layout.links?.repo ?? (org ? `${org}/.github-private` : void 0);
|
|
162
|
+
if (!repo) throw new Error("no org to find the links file under — set `layout.links.repo` or `org` in holocron.config.ts");
|
|
163
|
+
return {
|
|
164
|
+
repo,
|
|
165
|
+
path: layout.links?.path ?? `notifications/${provider.toLowerCase()}-links.json`
|
|
166
|
+
};
|
|
63
167
|
}
|
|
168
|
+
// src/commands/notifications-sync-roles/plan.ts
|
|
64
169
|
/**
|
|
65
|
-
*
|
|
66
|
-
* when
|
|
67
|
-
*
|
|
68
|
-
*
|
|
170
|
+
* What it takes to make a role's holders equal a team, given who is linked to whom. Pure: it decides, the
|
|
171
|
+
* caller acts. A holder is removed only when a link says they are a person who left the team; a holder
|
|
172
|
+
* nobody has linked is reported, never removed, so an empty or missing links file cannot strip the role from
|
|
173
|
+
* everyone.
|
|
69
174
|
*/
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
175
|
+
function planRoleSync(input) {
|
|
176
|
+
const byGithub = new Map(input.links.map((l) => [l.github, l]));
|
|
177
|
+
const byMember = new Map(input.links.map((l) => [l.member, l]));
|
|
178
|
+
const onTeam = new Set(input.team.map((m) => m.id));
|
|
179
|
+
const holding = new Set(input.holders.map((h) => h.id));
|
|
180
|
+
const plan = {
|
|
181
|
+
add: [],
|
|
182
|
+
remove: [],
|
|
183
|
+
unlinked: [],
|
|
184
|
+
unknownHolders: [],
|
|
185
|
+
inSync: 0
|
|
186
|
+
};
|
|
187
|
+
for (const person of input.team) {
|
|
188
|
+
const link = byGithub.get(person.id);
|
|
189
|
+
if (!link) plan.unlinked.push(person);
|
|
190
|
+
else if (holding.has(link.member)) plan.inSync++;
|
|
191
|
+
else plan.add.push({
|
|
192
|
+
member: link.member,
|
|
193
|
+
login: person.login
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
for (const holder of input.holders) {
|
|
197
|
+
const link = byMember.get(holder.id);
|
|
198
|
+
if (!link) plan.unknownHolders.push({
|
|
199
|
+
member: holder.id,
|
|
200
|
+
...holder.name ? { name: holder.name } : {}
|
|
201
|
+
});
|
|
202
|
+
else if (!onTeam.has(link.github)) plan.remove.push({
|
|
203
|
+
member: holder.id,
|
|
204
|
+
login: link.login
|
|
205
|
+
});
|
|
75
206
|
}
|
|
207
|
+
return plan;
|
|
76
208
|
}
|
|
77
209
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* platforms the underlying credential store supports.
|
|
210
|
+
* The first role the layout declares for two different teams, or undefined. Names compare ignoring case, as
|
|
211
|
+
* the server does; the role would be synced against one team and then the other, so the last would win.
|
|
81
212
|
*/
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
213
|
+
function roleTeamProblem(layout) {
|
|
214
|
+
const seen = /* @__PURE__ */ new Map();
|
|
215
|
+
for (const role of layout.roles ?? []) {
|
|
216
|
+
if (!role.team) continue;
|
|
217
|
+
const key = role.name.toLowerCase();
|
|
218
|
+
const earlier = seen.get(key);
|
|
219
|
+
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`;
|
|
220
|
+
seen.set(key, role.team);
|
|
87
221
|
}
|
|
88
222
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
223
|
+
// src/commands/notifications-sync-roles/sync-roles.ts
|
|
224
|
+
/** Reads the team and the role's holders and works out what has to change. */
|
|
225
|
+
async function planForRole(args) {
|
|
226
|
+
const [team, holders] = await Promise.all([args.source.teamMembers(args.team, args.org), args.notifications.roleMembers(args.role)]);
|
|
227
|
+
return planRoleSync({
|
|
228
|
+
team,
|
|
229
|
+
links: args.links.links,
|
|
230
|
+
holders
|
|
97
231
|
});
|
|
98
232
|
}
|
|
99
233
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
234
|
+
* Makes each role's holders equal its team, one role after another. This is the sync itself, with no setup in
|
|
235
|
+
* front of it: the caller has already picked the providers, read the links and checked the layout. `holocron
|
|
236
|
+
* notifications sync-roles` and Sentinel's role sync are two callers of it. A step that fails is recorded and the
|
|
237
|
+
* run goes on; nothing here throws for a provider error. Idempotent: a role that already matches changes nothing.
|
|
238
|
+
* Lines go to `input.print` when it is given, and nowhere otherwise.
|
|
105
239
|
*/
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
240
|
+
async function syncRoles(input) {
|
|
241
|
+
const print = input.print ?? (() => {});
|
|
242
|
+
const { notifications, source, links, dryRun, keep } = input;
|
|
243
|
+
const result = {
|
|
244
|
+
roles: [],
|
|
245
|
+
failures: [],
|
|
246
|
+
ok: 0,
|
|
247
|
+
skipped: 0
|
|
113
248
|
};
|
|
249
|
+
for (const role of input.roles) {
|
|
250
|
+
print(`\n${style.header(`${role.name} ← team ${role.team}`)}`);
|
|
251
|
+
const step = `role ${role.name}`;
|
|
252
|
+
let plan;
|
|
253
|
+
try {
|
|
254
|
+
plan = await planForRole({
|
|
255
|
+
notifications,
|
|
256
|
+
source,
|
|
257
|
+
role: role.name,
|
|
258
|
+
team: role.team,
|
|
259
|
+
...input.org ? { org: input.org } : {},
|
|
260
|
+
links
|
|
261
|
+
});
|
|
262
|
+
} catch (err) {
|
|
263
|
+
const message = describeError(err);
|
|
264
|
+
print(` ${style.fail(`${step}: ${message}`)}`);
|
|
265
|
+
result.failures.push({
|
|
266
|
+
step,
|
|
267
|
+
message
|
|
268
|
+
});
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const outcome = {
|
|
272
|
+
role: role.name,
|
|
273
|
+
team: role.team,
|
|
274
|
+
plan,
|
|
275
|
+
added: [],
|
|
276
|
+
removed: []
|
|
277
|
+
};
|
|
278
|
+
result.roles.push(outcome);
|
|
279
|
+
result.skipped += plan.inSync;
|
|
280
|
+
if (plan.inSync > 0) print(` ${style.skip(`${plan.inSync} already have it`)}`);
|
|
281
|
+
const act = async (verb, who) => {
|
|
282
|
+
const label = `${verb === "add" ? "gave" : "took"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})`;
|
|
283
|
+
if (dryRun || verb === "remove" && keep) {
|
|
284
|
+
print(` ${style.skip(`would ${verb === "add" ? "give" : "take"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})${keep && verb === "remove" ? " (kept: --keep)" : ""}`)}`);
|
|
285
|
+
result.skipped++;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
if (verb === "add") await notifications.addRoleMember(role.name, who.member);
|
|
290
|
+
else await notifications.removeRoleMember(role.name, who.member);
|
|
291
|
+
(verb === "add" ? outcome.added : outcome.removed).push(who.member);
|
|
292
|
+
print(` ${style.success(label)}`);
|
|
293
|
+
result.ok++;
|
|
294
|
+
} catch (err) {
|
|
295
|
+
const message = describeError(err);
|
|
296
|
+
print(` ${style.fail(`${step}: ${verb} ${who.login}: ${message}`)}`);
|
|
297
|
+
result.failures.push({
|
|
298
|
+
step: `${step} ${verb} ${who.login}`,
|
|
299
|
+
message
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
for (const who of plan.add) await act("add", who);
|
|
304
|
+
for (const who of plan.remove) await act("remove", who);
|
|
305
|
+
for (const person of plan.unlinked) {
|
|
306
|
+
print(` ${style.skip(`${person.login} is on the team but has not linked their account`)}`);
|
|
307
|
+
result.skipped++;
|
|
308
|
+
}
|
|
309
|
+
for (const holder of plan.unknownHolders) {
|
|
310
|
+
print(` ${style.skip(`${holder.name ?? holder.member} holds ${role.name} but is not linked to anyone: left alone`)}`);
|
|
311
|
+
result.skipped++;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return result;
|
|
114
315
|
}
|
|
115
|
-
|
|
116
|
-
|
|
316
|
+
// src/commands/notifications-sync-roles/notifications-sync-roles.ts
|
|
317
|
+
/** What a source provider needs to be able to do to feed a role sync, or the reason it cannot. */
|
|
318
|
+
function sourceProblem(source) {
|
|
319
|
+
if (!source) return "no `source` provider is available to read the team and the links file";
|
|
320
|
+
if (!source.teamMembers) return `the \`${source.providerName}\` provider cannot list team members`;
|
|
321
|
+
if (!source.readFile) return `the \`${source.providerName}\` provider cannot read the links file`;
|
|
322
|
+
}
|
|
323
|
+
/** Reads the links file; a file that does not exist yet is an empty one, a damaged one throws. */
|
|
324
|
+
async function readLinks(source, layout, org, provider) {
|
|
325
|
+
const { repo, path } = linksLocation(layout, org, provider);
|
|
326
|
+
const file = await source.readFile(path, repo);
|
|
327
|
+
if (!file) return EMPTY_LINKS;
|
|
328
|
+
try {
|
|
329
|
+
return parseLinks(file.content);
|
|
330
|
+
} catch (err) {
|
|
331
|
+
throw new Error(`${repo}/${path}: ${errorMessage(err)}`, { cause: err });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
// src/commands/setup/derived-properties/derived-properties.ts
|
|
117
335
|
/**
|
|
118
336
|
* Repo archetype, in priority order:
|
|
119
337
|
* 1. `*-template` repo name → `template` (independent of package shape).
|
|
@@ -184,7 +402,7 @@ function deriveCapabilities(providers) {
|
|
|
184
402
|
return Object.keys(providers ?? {}).sort();
|
|
185
403
|
}
|
|
186
404
|
/**
|
|
187
|
-
* `source` + `ci` are the minimal baseline every repo `holocron setup`
|
|
405
|
+
* `source` + `ci` are the minimal baseline every repo `holocron repo setup`
|
|
188
406
|
* touches wires — every `holocron.config.ts` in this org already satisfies
|
|
189
407
|
* this, so `non-compliant` here means drift (a provider manually removed
|
|
190
408
|
* after setup), not an unmet aspirational policy. Deliberately not a richer
|
|
@@ -192,6 +410,7 @@ function deriveCapabilities(providers) {
|
|
|
192
410
|
* a Phase B (GitHub App) refinement once it can post *why* on a check run.
|
|
193
411
|
*/
|
|
194
412
|
const REQUIRED_BASELINE = ["source", "ci"];
|
|
413
|
+
/** Whether a repo's capabilities include the required baseline (`source` and `ci`); `non-compliant` means drift. */
|
|
195
414
|
function deriveCompliance(capabilities) {
|
|
196
415
|
return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
|
|
197
416
|
}
|
|
@@ -213,287 +432,110 @@ function missingCapabilities(capabilities) {
|
|
|
213
432
|
*/
|
|
214
433
|
async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
215
434
|
const results = [];
|
|
216
|
-
for (const { slug, dir = "packages" } of workspacePackages)
|
|
217
|
-
const
|
|
218
|
-
results.push(
|
|
219
|
-
} catch {}
|
|
220
|
-
return results;
|
|
221
|
-
}
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/config/config.ts
|
|
224
|
-
var ConfigError = class extends Error {
|
|
225
|
-
name = "ConfigError";
|
|
226
|
-
};
|
|
227
|
-
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
228
|
-
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
229
|
-
/**
|
|
230
|
-
* Resolve `"github"` → `"@theholocron/holocron-plugin-github"`.
|
|
231
|
-
* Fully-qualified names (scoped or not) are honored verbatim, which
|
|
232
|
-
* is how third-party plugins published outside the org work.
|
|
233
|
-
*/
|
|
234
|
-
function resolvePluginPackage(provider) {
|
|
235
|
-
if (!provider) throw new ConfigError("provider name is empty");
|
|
236
|
-
if (provider.startsWith("@")) return provider;
|
|
237
|
-
if (provider.startsWith(COMMUNITY_PREFIX)) return provider;
|
|
238
|
-
if (provider.includes("/")) return provider;
|
|
239
|
-
return PLUGIN_PREFIX + provider;
|
|
240
|
-
}
|
|
241
|
-
/** A bare `[provider, options]` tuple, with both elements present? */
|
|
242
|
-
function isOptionsTuple(value) {
|
|
243
|
-
if (!Array.isArray(value)) return false;
|
|
244
|
-
if (value.length !== 2) return false;
|
|
245
|
-
if (typeof value[0] !== "string") return false;
|
|
246
|
-
const opt = value[1];
|
|
247
|
-
return typeof opt === "object" && opt !== null && !Array.isArray(opt);
|
|
248
|
-
}
|
|
249
|
-
function normalizeEntry(entry) {
|
|
250
|
-
if (typeof entry === "string") return {
|
|
251
|
-
provider: entry,
|
|
252
|
-
packageName: resolvePluginPackage(entry),
|
|
253
|
-
options: {}
|
|
254
|
-
};
|
|
255
|
-
const [provider, options] = entry;
|
|
256
|
-
return {
|
|
257
|
-
provider,
|
|
258
|
-
packageName: resolvePluginPackage(provider),
|
|
259
|
-
options
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
function resolveEntry(key, raw) {
|
|
263
|
-
const cardinality = CARDINALITY[key];
|
|
264
|
-
if (typeof raw === "string") {
|
|
265
|
-
if (cardinality === "many") throw new ConfigError(`\`${key}\` accepts multiple providers; wrap a single one in an array: ["${raw}"]`);
|
|
266
|
-
return {
|
|
267
|
-
cardinality: "single",
|
|
268
|
-
tuple: normalizeEntry(raw)
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
if (!Array.isArray(raw)) throw new ConfigError(`\`${key}\` entry must be a string or array, got ${typeof raw}`);
|
|
272
|
-
if (isOptionsTuple(raw)) {
|
|
273
|
-
if (cardinality === "many") return {
|
|
274
|
-
cardinality: "many",
|
|
275
|
-
tuples: [normalizeEntry(raw)]
|
|
276
|
-
};
|
|
277
|
-
return {
|
|
278
|
-
cardinality: "single",
|
|
279
|
-
tuple: normalizeEntry(raw)
|
|
280
|
-
};
|
|
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
|
-
};
|
|
291
|
-
}
|
|
292
|
-
function resolveConfig(raw) {
|
|
293
|
-
if (!raw.name) throw new ConfigError("`name` is required");
|
|
294
|
-
if (!raw.providers || typeof raw.providers !== "object") throw new ConfigError("`providers` block is required");
|
|
295
|
-
const providers = {};
|
|
296
|
-
for (const [key, entry] of Object.entries(raw.providers)) {
|
|
297
|
-
if (entry === void 0) continue;
|
|
298
|
-
providers[key] = resolveEntry(key, entry);
|
|
299
|
-
}
|
|
300
|
-
for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError(`required capability \`${required}\` is missing from providers`);
|
|
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;
|
|
435
|
+
for (const { slug, dir = "packages", path } of workspacePackages) {
|
|
436
|
+
const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
|
|
437
|
+
if (pkg) results.push(pkg);
|
|
305
438
|
}
|
|
306
|
-
|
|
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
|
-
};
|
|
329
|
-
}
|
|
330
|
-
//#endregion
|
|
331
|
-
//#region src/config/compose.ts
|
|
332
|
-
function taskName(e) {
|
|
333
|
-
return typeof e === "string" ? e : e.name;
|
|
439
|
+
return results;
|
|
334
440
|
}
|
|
441
|
+
// src/commands/setup/labels.ts
|
|
335
442
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* - Accepts individual capabilities or nested arrays (for bundle presets).
|
|
340
|
-
* - Deduplicates by `id` — when the same ID appears more than once, the last
|
|
341
|
-
* occurrence wins. This lets callers override bundle defaults by listing an
|
|
342
|
-
* explicit capability after the bundle.
|
|
343
|
-
* - Validates all `requires` at call time and throws `ConfigError` if any are
|
|
344
|
-
* unmet, listing every missing dependency in a single message.
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* // docs-only site — no typecheck
|
|
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());
|
|
443
|
+
* The labels every repository gets from `repo setup`, with their GitHub colours (hex, no `#`) and descriptions. A
|
|
444
|
+
* plugin that makes labels of its own, such as Linear's setup, takes the colour of the one with the same name.
|
|
355
445
|
*/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
446
|
+
const CANONICAL_LABELS = [
|
|
447
|
+
{
|
|
448
|
+
name: "bug",
|
|
449
|
+
color: "d73a4a",
|
|
450
|
+
description: "Something isn't working"
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
name: "chore",
|
|
454
|
+
color: "ededed",
|
|
455
|
+
description: "Maintenance, no user-facing change"
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
name: "ci",
|
|
459
|
+
color: "0075ca",
|
|
460
|
+
description: "CI/CD pipeline changes"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
name: "dependencies",
|
|
464
|
+
color: "0366d6",
|
|
465
|
+
description: "Dependency update"
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: "documentation",
|
|
469
|
+
color: "0075ca",
|
|
470
|
+
description: "Documentation only"
|
|
471
|
+
},
|
|
472
|
+
{
|
|
473
|
+
name: "duplicate",
|
|
474
|
+
color: "cfd3d7",
|
|
475
|
+
description: "Already reported"
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
name: "enhancement",
|
|
479
|
+
color: "a2eeef",
|
|
480
|
+
description: "New feature or request"
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
name: "good first issue",
|
|
484
|
+
color: "7057ff",
|
|
485
|
+
description: "Good for newcomers"
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
name: "help wanted",
|
|
489
|
+
color: "008672",
|
|
490
|
+
description: "Extra attention needed"
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
name: "invalid",
|
|
494
|
+
color: "e4e669",
|
|
495
|
+
description: "Doesn't seem right"
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
name: "performance",
|
|
499
|
+
color: "fbca04",
|
|
500
|
+
description: "Performance improvement"
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
name: "question",
|
|
504
|
+
color: "d876e3",
|
|
505
|
+
description: "Further information requested"
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
name: "refactor",
|
|
509
|
+
color: "cfd3d7",
|
|
510
|
+
description: "Code restructuring"
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: "released",
|
|
514
|
+
color: "ededed",
|
|
515
|
+
description: "Included in a release"
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
name: "test",
|
|
519
|
+
color: "bfd4f2",
|
|
520
|
+
description: "Test-related changes"
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
name: "triage",
|
|
524
|
+
color: "e4e669",
|
|
525
|
+
description: "Needs investigation"
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
name: "wontfix",
|
|
529
|
+
color: "ffffff",
|
|
530
|
+
description: "Won't be addressed"
|
|
407
531
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
providers,
|
|
411
|
-
repo,
|
|
412
|
-
extraRequiredChecks,
|
|
413
|
-
...org !== void 0 ? { org } : {},
|
|
414
|
-
...domain !== void 0 ? { domain } : {},
|
|
415
|
-
...docs !== void 0 ? { docs } : {}
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
//#endregion
|
|
419
|
-
//#region src/config/define-config.ts
|
|
420
|
-
function defineConfig(config) {
|
|
421
|
-
return config;
|
|
422
|
-
}
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/config/load-config.ts
|
|
425
|
-
/**
|
|
426
|
-
* `holocron.config.{ts,js,mjs,cjs,json}` loader.
|
|
427
|
-
*
|
|
428
|
-
* File discovery + module loading (typed configs via `tsx`, no build
|
|
429
|
-
* step) is delegated to `@theholocron/datapad`. This module keeps the
|
|
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.
|
|
435
|
-
*/
|
|
436
|
-
const execFileAsync = promisify(execFile);
|
|
532
|
+
];
|
|
533
|
+
// src/plugin/connection-probe/connection-probe.ts
|
|
437
534
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* be loaded, or `ConfigError` when the config is invalid.
|
|
535
|
+
* The `connection` probe every provider offers, for telling a network problem from a credential problem. The checks are
|
|
536
|
+
* kyber's `connectionProbe`; this types the result as the plugin system's {@link Probe} and `verify` as `VerifyTokenResult`.
|
|
441
537
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
cwd,
|
|
445
|
-
name: "holocron"
|
|
446
|
-
});
|
|
447
|
-
if (!found) throw new ConfigFileError$1(`no holocron.config.{ts,js,mjs,cjs,json} found in ${cwd}. Create one — see the README for the schema.`);
|
|
448
|
-
return {
|
|
449
|
-
resolved: resolveConfig(await deriveDefaults(dirname(found.filepath), found.config)),
|
|
450
|
-
filepath: found.filepath
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
async function deriveDefaults(configDir, raw) {
|
|
454
|
-
const result = { ...raw };
|
|
455
|
-
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
456
|
-
if (result.repo && !result.repo.name) {
|
|
457
|
-
const repoName = await readGitRemote(configDir);
|
|
458
|
-
if (repoName) result.repo = {
|
|
459
|
-
...result.repo,
|
|
460
|
-
name: repoName
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
const manifest = await loadTasksConfig(configDir);
|
|
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;
|
|
470
|
-
}
|
|
471
|
-
async function readPackageJsonName(dir) {
|
|
472
|
-
try {
|
|
473
|
-
const content = await readFile(join(dir, "package.json"), "utf8");
|
|
474
|
-
const pkg = JSON.parse(content);
|
|
475
|
-
return typeof pkg.name === "string" ? pkg.name.replace(/^@[^/]+\//, "") : void 0;
|
|
476
|
-
} catch {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
async function readGitRemote(dir) {
|
|
481
|
-
try {
|
|
482
|
-
const { stdout } = await execFileAsync("git", [
|
|
483
|
-
"remote",
|
|
484
|
-
"get-url",
|
|
485
|
-
"origin"
|
|
486
|
-
], { cwd: dir });
|
|
487
|
-
return parseGitRemoteUrl(stdout.trim());
|
|
488
|
-
} catch {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function parseGitRemoteUrl(url) {
|
|
493
|
-
const httpsMatch = url.match(/github\.com\/([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
494
|
-
if (httpsMatch) return httpsMatch[1];
|
|
495
|
-
const sshMatch = url.match(/github\.com:([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
496
|
-
if (sshMatch) return sshMatch[1];
|
|
538
|
+
function connectionProbe(input) {
|
|
539
|
+
return connectionProbe$1(input);
|
|
497
540
|
}
|
|
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 };
|
|
541
|
+
export { AuthError, CANONICAL_LABELS, CARDINALITY, ConfigError, ConfigFileError, ElevationRequiredError, HOLOCRON_AREAS, MissingTokenError, ProviderApiError, REQUIRED_CAPABILITIES, SHARED_AREAS, WebhookVerificationError, compose, connectionProbe, createFeatureResolver, createResolveToken, createRestClient, credentialsEnvironment, defineConfig, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, isMulti, keyring, loadConfig, missingCapabilities, orderKeys, pickByCreation, placeAreas, readKeysLimited, readLinks, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, resolveValue, roleTeamProblem, sourceProblem, syncRoles };
|