@theholocron/cli 5.0.0-alpha.45 → 5.0.0-alpha.451
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 +566 -106
- package/dist/cli.mjs +27687 -8357
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-CAYb1d4M.mjs +814 -0
- package/dist/index-DMoGsKv2.d.mts +4263 -0
- package/dist/index.d.mts +479 -632
- package/dist/index.mjs +577 -348
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +59 -4
- package/dist/presets.d.mts +221 -0
- package/dist/presets.mjs +439 -0
- package/package.json +49 -36
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,360 @@
|
|
|
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-CAYb1d4M.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 { connectionProbe as connectionProbe$1 } from "@theholocron/kyber/checks";
|
|
9
|
+
import { dirname, join, resolve } from "node:path";
|
|
10
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
11
|
+
import { fstatSync, mkdirSync } from "node:fs";
|
|
12
|
+
// src/auth/auth.ts
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* The CLI's credentials: the OS keyring every plugin's bootstrap token lives in, and the two token resolvers built on
|
|
15
|
+
* it. Both are public, so a plugin's `src/auth.ts` is a one-line call.
|
|
16
|
+
*
|
|
17
|
+
* The keyring itself, with its best-effort failure model and its per-process cache, is `createKeyring` in
|
|
18
|
+
* `@theholocron/kyber/secrets`; this file only names the service. Managed via `holocron check token` subcommands and consulted
|
|
19
|
+
* last in every plugin's precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN). See
|
|
20
|
+
* `docs/wiki/specifications/tech-auth-bootstrap.spec.md`.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* The holocron keyring: `get` answers `null` for "not stored" and for "keyring unavailable" alike, so callers fall
|
|
24
|
+
* through to env-var precedence, and remembers the answer for the process (`clearCache` forgets it); `set` and `delete`
|
|
25
|
+
* answer whether they did anything; `list` names the stored providers; `isAvailable` tells an outage from an empty keyring.
|
|
15
26
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
const keyring = createKeyring({
|
|
28
|
+
service: "com.theholocron.cli",
|
|
29
|
+
binding: {
|
|
30
|
+
Entry,
|
|
31
|
+
findCredentials
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Kyber's `createResolveToken` with the keyring, the `HOLOCRON_ORG` variable and the `token` description
|
|
36
|
+
* `holocron doctor secrets --verify` reads filled in, so a plugin stays at a one-liner call site. The chain is the flag, the
|
|
37
|
+
* plugin's variable, the vendor's variable, the `credentials` providers' variables, the keyring.
|
|
38
|
+
*/
|
|
39
|
+
function createResolveToken(config) {
|
|
40
|
+
return Object.assign(createResolveToken$1({
|
|
41
|
+
...config,
|
|
42
|
+
keyring: keyring.get,
|
|
43
|
+
orgEnvName: "HOLOCRON_ORG"
|
|
44
|
+
}), { token: {
|
|
45
|
+
envName: config.envName,
|
|
46
|
+
vendorEnvName: config.vendorEnvName,
|
|
47
|
+
keyringKey: config.keyringService
|
|
48
|
+
} });
|
|
18
49
|
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/auth/keyring.ts
|
|
21
50
|
/**
|
|
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.
|
|
51
|
+
* Kyber's `createFeatureResolver` for a strict, single-feature token: the flag, the feature's variable, the
|
|
52
|
+
* `credentials` providers' variable of that name, the keyring. No broad-token fallback; if the feature's token is absent
|
|
53
|
+
* the operation fails with a message naming the exact variable to set and `holocron new token`.
|
|
38
54
|
*/
|
|
39
|
-
|
|
55
|
+
function createFeatureResolver(config) {
|
|
56
|
+
return Object.assign(createFeatureResolver$1({
|
|
57
|
+
...config,
|
|
58
|
+
vendor: config.vendor ?? "GitHub",
|
|
59
|
+
setCommand: (key) => `holocron new token ${key} <token>`,
|
|
60
|
+
keyring: keyring.get
|
|
61
|
+
}), { token: {
|
|
62
|
+
envName: config.envName,
|
|
63
|
+
keyringKey: config.keyringKey
|
|
64
|
+
} });
|
|
65
|
+
}
|
|
66
|
+
// src/plugin/issues-provider/order-keys/order-keys.ts
|
|
40
67
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
68
|
+
* Puts issue keys in creation order without asking the tracker: issue numbers (`#12`, `ENG-12`) rise with creation inside
|
|
69
|
+
* one repository or team, so the trailing number is the order. `oldest` is ascending, `newest` descending; keys with the
|
|
70
|
+
* same number keep their place. A key with no trailing number is an error, because nothing can be said of its age.
|
|
43
71
|
*/
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
72
|
+
function orderKeys(keys, order) {
|
|
73
|
+
const numbered = keys.map((key, index) => {
|
|
74
|
+
const match = /(\d+)\s*$/.exec(key);
|
|
75
|
+
if (!match) throw new Error(`Cannot order "${key}" by creation: it has no issue number.`);
|
|
76
|
+
return {
|
|
77
|
+
key,
|
|
78
|
+
index,
|
|
79
|
+
n: Number(match[1])
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
const sign = order === "newest" ? -1 : 1;
|
|
83
|
+
return numbered.sort((a, b) => sign * (a.n - b.n) || a.index - b.index).map((e) => e.key);
|
|
84
|
+
}
|
|
85
|
+
// src/plugin/issues-provider/pick-by-creation/pick-by-creation.ts
|
|
86
|
+
/**
|
|
87
|
+
* Keeps the first or last `limit` of a listing by creation time, returned oldest first. `createdAt` reads an item's
|
|
88
|
+
* ISO timestamp; items created in the same instant keep their listed order. The cut happens on what the listing already
|
|
89
|
+
* holds, so no request is spent on an item that is dropped.
|
|
90
|
+
*/
|
|
91
|
+
function pickByCreation(items, createdAt, order, limit) {
|
|
92
|
+
const ascending = items.map((item, index) => ({
|
|
93
|
+
item,
|
|
94
|
+
index,
|
|
95
|
+
at: Date.parse(createdAt(item))
|
|
96
|
+
})).sort((a, b) => a.at - b.at || a.index - b.index).map((e) => e.item);
|
|
97
|
+
return order === "newest" ? ascending.slice(Math.max(ascending.length - limit, 0)) : ascending.slice(0, limit);
|
|
98
|
+
}
|
|
99
|
+
// src/plugin/issues-provider/read-keys-limited/read-keys-limited.ts
|
|
100
|
+
/**
|
|
101
|
+
* Reads an explicit list of issues in creation order until `limit` of them are kept. The keys are sorted by number first
|
|
102
|
+
* (see {@link orderKeys}), then fetched in small steps of at most `concurrency`, each step no bigger than the places
|
|
103
|
+
* still open, so an issue that is later skipped (a pull request, a closed one) is replaced by the next key and nothing
|
|
104
|
+
* beyond the budget is fetched unless a skip made room. Within a step the fetches run together; the results keep the key
|
|
105
|
+
* order. The kept items come back oldest first, whichever end was chosen.
|
|
106
|
+
*/
|
|
107
|
+
async function readKeysLimited(input) {
|
|
108
|
+
const { keys, order, limit, concurrency, fetch, keep } = input;
|
|
109
|
+
const ordered = orderKeys(keys, order);
|
|
110
|
+
const kept = [];
|
|
111
|
+
let next = 0;
|
|
112
|
+
while (kept.length < limit && next < ordered.length) {
|
|
113
|
+
const step = ordered.slice(next, next + Math.min(concurrency, limit - kept.length));
|
|
114
|
+
next += step.length;
|
|
115
|
+
const fetched = await Promise.all(step.map((key) => fetch(key)));
|
|
116
|
+
for (const item of fetched) if (keep(item)) kept.push(item);
|
|
50
117
|
}
|
|
118
|
+
return order === "newest" ? kept.reverse() : kept;
|
|
51
119
|
}
|
|
120
|
+
// src/plugin/issues-provider/report-progress/report-progress.ts
|
|
52
121
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
122
|
+
* Calls a provider's optional `onProgress` hook with how many items are done of how many. A hook that throws is
|
|
123
|
+
* ignored, because a progress counter must never change or stop the read or write it reports on.
|
|
124
|
+
*
|
|
125
|
+
* @param onProgress - The hook from `ExportInfo` or `ImportOptions`; nothing happens when it is not given.
|
|
126
|
+
* @param done - How many items are finished.
|
|
127
|
+
* @param total - How many items there are.
|
|
56
128
|
*/
|
|
57
|
-
function
|
|
129
|
+
function reportProgress(onProgress, done, total) {
|
|
58
130
|
try {
|
|
59
|
-
|
|
60
|
-
} catch {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
131
|
+
onProgress?.(done, total);
|
|
132
|
+
} catch {}
|
|
63
133
|
}
|
|
134
|
+
// src/plugin/probes/connection-probe/connection-probe.ts
|
|
64
135
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* Distinguishing the two cases isn't worth the surface area — the
|
|
68
|
-
* command output makes the situation clear either way.
|
|
136
|
+
* The `connection` probe every provider offers, for telling a network problem from a credential problem. The checks are
|
|
137
|
+
* kyber's `connectionProbe`; this types the result as the plugin system's {@link Probe} and `verify` as `VerifyTokenResult`.
|
|
69
138
|
*/
|
|
70
|
-
function
|
|
139
|
+
function connectionProbe(input) {
|
|
140
|
+
return connectionProbe$1(input);
|
|
141
|
+
}
|
|
142
|
+
// src/commands/notifications-sync-roles/links.ts
|
|
143
|
+
const EMPTY_LINKS = {
|
|
144
|
+
version: 1,
|
|
145
|
+
links: []
|
|
146
|
+
};
|
|
147
|
+
const DIGITS = /^\d{1,20}$/;
|
|
148
|
+
/** 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. */
|
|
149
|
+
function parseLinks(text) {
|
|
150
|
+
let raw;
|
|
71
151
|
try {
|
|
72
|
-
|
|
152
|
+
raw = JSON.parse(text);
|
|
73
153
|
} catch {
|
|
74
|
-
|
|
154
|
+
throw new Error("the links file is not valid JSON");
|
|
75
155
|
}
|
|
156
|
+
const file = raw;
|
|
157
|
+
if (file.version !== 1) throw new Error(`the links file has version ${JSON.stringify(file.version)}; expected 1`);
|
|
158
|
+
if (!Array.isArray(file.links)) throw new Error("the links file has no `links` list");
|
|
159
|
+
const links = file.links.map((entry, i) => {
|
|
160
|
+
const e = entry;
|
|
161
|
+
if (typeof e.github !== "string" || !DIGITS.test(e.github)) throw new Error(`links[${i}]: \`github\` must be a numeric user id string`);
|
|
162
|
+
if (typeof e.member !== "string" || !DIGITS.test(e.member)) throw new Error(`links[${i}]: \`member\` must be a numeric id string`);
|
|
163
|
+
if (typeof e.login !== "string") throw new Error(`links[${i}]: \`login\` must be a string`);
|
|
164
|
+
return {
|
|
165
|
+
github: e.github,
|
|
166
|
+
login: e.login,
|
|
167
|
+
member: e.member
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
for (const key of ["github", "member"]) {
|
|
171
|
+
const seen = /* @__PURE__ */ new Set();
|
|
172
|
+
for (const [i, link] of links.entries()) {
|
|
173
|
+
if (seen.has(link[key])) throw new Error(`links[${i}]: \`${key}\` ${link[key]} appears more than once`);
|
|
174
|
+
seen.add(link[key]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
version: 1,
|
|
179
|
+
links
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** Where the links file is: the layout's `links`, else `<org>/.github-private` and `notifications/<provider>-links.json`. */
|
|
183
|
+
function linksLocation(layout, org, provider) {
|
|
184
|
+
const repo = layout.links?.repo ?? (org ? `${org}/.github-private` : void 0);
|
|
185
|
+
if (!repo) throw new Error("no org to find the links file under — set `layout.links.repo` or `org` in holocron.config.ts");
|
|
186
|
+
return {
|
|
187
|
+
repo,
|
|
188
|
+
path: layout.links?.path ?? `notifications/${provider.toLowerCase()}-links.json`
|
|
189
|
+
};
|
|
76
190
|
}
|
|
191
|
+
// src/commands/notifications-sync-roles/plan.ts
|
|
77
192
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
193
|
+
* What it takes to make a role's holders equal a team, given who is linked to whom. Pure: it decides, the
|
|
194
|
+
* caller acts. A holder is removed only when a link says they are a person who left the team; a holder
|
|
195
|
+
* nobody has linked is reported, never removed, so an empty or missing links file cannot strip the role from
|
|
196
|
+
* everyone.
|
|
81
197
|
*/
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
198
|
+
function planRoleSync(input) {
|
|
199
|
+
const byGithub = new Map(input.links.map((l) => [l.github, l]));
|
|
200
|
+
const byMember = new Map(input.links.map((l) => [l.member, l]));
|
|
201
|
+
const onTeam = new Set(input.team.map((m) => m.id));
|
|
202
|
+
const holding = new Set(input.holders.map((h) => h.id));
|
|
203
|
+
const plan = {
|
|
204
|
+
add: [],
|
|
205
|
+
remove: [],
|
|
206
|
+
unlinked: [],
|
|
207
|
+
unknownHolders: [],
|
|
208
|
+
inSync: 0
|
|
209
|
+
};
|
|
210
|
+
for (const person of input.team) {
|
|
211
|
+
const link = byGithub.get(person.id);
|
|
212
|
+
if (!link) plan.unlinked.push(person);
|
|
213
|
+
else if (holding.has(link.member)) plan.inSync++;
|
|
214
|
+
else plan.add.push({
|
|
215
|
+
member: link.member,
|
|
216
|
+
login: person.login
|
|
217
|
+
});
|
|
87
218
|
}
|
|
219
|
+
for (const holder of input.holders) {
|
|
220
|
+
const link = byMember.get(holder.id);
|
|
221
|
+
if (!link) plan.unknownHolders.push({
|
|
222
|
+
member: holder.id,
|
|
223
|
+
...holder.name ? { name: holder.name } : {}
|
|
224
|
+
});
|
|
225
|
+
else if (!onTeam.has(link.github)) plan.remove.push({
|
|
226
|
+
member: holder.id,
|
|
227
|
+
login: link.login
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return plan;
|
|
88
231
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
232
|
+
/**
|
|
233
|
+
* The first role the layout declares for two different teams, or undefined. Names compare ignoring case, as
|
|
234
|
+
* the server does; the role would be synced against one team and then the other, so the last would win.
|
|
235
|
+
*/
|
|
236
|
+
function roleTeamProblem(layout) {
|
|
237
|
+
const seen = /* @__PURE__ */ new Map();
|
|
238
|
+
for (const role of layout.roles ?? []) {
|
|
239
|
+
if (!role.team) continue;
|
|
240
|
+
const key = role.name.toLowerCase();
|
|
241
|
+
const earlier = seen.get(key);
|
|
242
|
+
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`;
|
|
243
|
+
seen.set(key, role.team);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
// src/commands/notifications-sync-roles/sync-roles.ts
|
|
247
|
+
/** Reads the team and the role's holders and works out what has to change. */
|
|
248
|
+
async function planForRole(args) {
|
|
249
|
+
const [team, holders] = await Promise.all([args.source.teamMembers(args.team, args.org), args.notifications.roleMembers(args.role)]);
|
|
250
|
+
return planRoleSync({
|
|
251
|
+
team,
|
|
252
|
+
links: args.links.links,
|
|
253
|
+
holders
|
|
97
254
|
});
|
|
98
255
|
}
|
|
99
256
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
257
|
+
* Makes each role's holders equal its team, one role after another. This is the sync itself, with no setup in
|
|
258
|
+
* front of it: the caller has already picked the providers, read the links and checked the layout. `holocron
|
|
259
|
+
* sync roles` and Sentinel's role sync are two callers of it. A step that fails is recorded and the
|
|
260
|
+
* run goes on; nothing here throws for a provider error. Idempotent: a role that already matches changes nothing.
|
|
261
|
+
* Lines go to `input.print` when it is given, and nowhere otherwise.
|
|
105
262
|
*/
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
263
|
+
async function syncRoles(input) {
|
|
264
|
+
const print = input.print ?? (() => {});
|
|
265
|
+
const { notifications, source, links, dryRun, keep } = input;
|
|
266
|
+
const result = {
|
|
267
|
+
roles: [],
|
|
268
|
+
failures: [],
|
|
269
|
+
ok: 0,
|
|
270
|
+
skipped: 0
|
|
113
271
|
};
|
|
272
|
+
for (const role of input.roles) {
|
|
273
|
+
print(`\n${style.header(`${role.name} ← team ${role.team}`)}`);
|
|
274
|
+
const step = `role ${role.name}`;
|
|
275
|
+
let plan;
|
|
276
|
+
try {
|
|
277
|
+
plan = await planForRole({
|
|
278
|
+
notifications,
|
|
279
|
+
source,
|
|
280
|
+
role: role.name,
|
|
281
|
+
team: role.team,
|
|
282
|
+
...input.org ? { org: input.org } : {},
|
|
283
|
+
links
|
|
284
|
+
});
|
|
285
|
+
} catch (err) {
|
|
286
|
+
const message = describeError(err);
|
|
287
|
+
print(` ${style.fail(`${step}: ${message}`)}`);
|
|
288
|
+
result.failures.push({
|
|
289
|
+
step,
|
|
290
|
+
message
|
|
291
|
+
});
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
const outcome = {
|
|
295
|
+
role: role.name,
|
|
296
|
+
team: role.team,
|
|
297
|
+
plan,
|
|
298
|
+
added: [],
|
|
299
|
+
removed: []
|
|
300
|
+
};
|
|
301
|
+
result.roles.push(outcome);
|
|
302
|
+
result.skipped += plan.inSync;
|
|
303
|
+
if (plan.inSync > 0) print(` ${style.skip(`${plan.inSync} already have it`)}`);
|
|
304
|
+
const act = async (verb, who) => {
|
|
305
|
+
const label = `${verb === "add" ? "gave" : "took"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})`;
|
|
306
|
+
if (dryRun || verb === "remove" && keep) {
|
|
307
|
+
print(` ${style.skip(`would ${verb === "add" ? "give" : "take"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})${keep && verb === "remove" ? " (kept: --keep)" : ""}`)}`);
|
|
308
|
+
result.skipped++;
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
try {
|
|
312
|
+
if (verb === "add") await notifications.addRoleMember(role.name, who.member);
|
|
313
|
+
else await notifications.removeRoleMember(role.name, who.member);
|
|
314
|
+
(verb === "add" ? outcome.added : outcome.removed).push(who.member);
|
|
315
|
+
print(` ${style.success(label)}`);
|
|
316
|
+
result.ok++;
|
|
317
|
+
} catch (err) {
|
|
318
|
+
const message = describeError(err);
|
|
319
|
+
print(` ${style.fail(`${step}: ${verb} ${who.login}: ${message}`)}`);
|
|
320
|
+
result.failures.push({
|
|
321
|
+
step: `${step} ${verb} ${who.login}`,
|
|
322
|
+
message
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
for (const who of plan.add) await act("add", who);
|
|
327
|
+
for (const who of plan.remove) await act("remove", who);
|
|
328
|
+
for (const person of plan.unlinked) {
|
|
329
|
+
print(` ${style.skip(`${person.login} is on the team but has not linked their account`)}`);
|
|
330
|
+
result.skipped++;
|
|
331
|
+
}
|
|
332
|
+
for (const holder of plan.unknownHolders) {
|
|
333
|
+
print(` ${style.skip(`${holder.name ?? holder.member} holds ${role.name} but is not linked to anyone: left alone`)}`);
|
|
334
|
+
result.skipped++;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
// src/commands/notifications-sync-roles/notifications-sync-roles.ts
|
|
340
|
+
/** What a source provider needs to be able to do to feed a role sync, or the reason it cannot. */
|
|
341
|
+
function sourceProblem(source) {
|
|
342
|
+
if (!source) return "no `source` provider is available to read the team and the links file";
|
|
343
|
+
if (!source.teamMembers) return `the \`${source.providerName}\` provider cannot list team members`;
|
|
344
|
+
if (!source.readFile) return `the \`${source.providerName}\` provider cannot read the links file`;
|
|
345
|
+
}
|
|
346
|
+
/** Reads the links file; a file that does not exist yet is an empty one, a damaged one throws. */
|
|
347
|
+
async function readLinks(source, layout, org, provider) {
|
|
348
|
+
const { repo, path } = linksLocation(layout, org, provider);
|
|
349
|
+
const file = await source.readFile(path, repo);
|
|
350
|
+
if (!file) return EMPTY_LINKS;
|
|
351
|
+
try {
|
|
352
|
+
return parseLinks(file.content);
|
|
353
|
+
} catch (err) {
|
|
354
|
+
throw new Error(`${repo}/${path}: ${errorMessage(err)}`, { cause: err });
|
|
355
|
+
}
|
|
114
356
|
}
|
|
115
|
-
|
|
116
|
-
//#region src/commands/setup/derived-properties.ts
|
|
357
|
+
// src/commands/setup/derived-properties/derived-properties.ts
|
|
117
358
|
/**
|
|
118
359
|
* Repo archetype, in priority order:
|
|
119
360
|
* 1. `*-template` repo name → `template` (independent of package shape).
|
|
@@ -153,6 +394,7 @@ function deriveProfile(input) {
|
|
|
153
394
|
if (pkg?.private) return "app";
|
|
154
395
|
return "library";
|
|
155
396
|
}
|
|
397
|
+
/** The framework and build-tool names `deriveStack()` can detect, in the order it lists them; `StackName` is derived from it. */
|
|
156
398
|
const KNOWN_STACK_DEPS = [
|
|
157
399
|
"next",
|
|
158
400
|
"vite",
|
|
@@ -192,6 +434,7 @@ function deriveCapabilities(providers) {
|
|
|
192
434
|
* a Phase B (GitHub App) refinement once it can post *why* on a check run.
|
|
193
435
|
*/
|
|
194
436
|
const REQUIRED_BASELINE = ["source", "ci"];
|
|
437
|
+
/** Whether a repo's capabilities include the required baseline (`source` and `ci`); `non-compliant` means drift. */
|
|
195
438
|
function deriveCompliance(capabilities) {
|
|
196
439
|
return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
|
|
197
440
|
}
|
|
@@ -213,287 +456,273 @@ function missingCapabilities(capabilities) {
|
|
|
213
456
|
*/
|
|
214
457
|
async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
215
458
|
const results = [];
|
|
216
|
-
for (const { slug, dir = "packages" } of workspacePackages)
|
|
217
|
-
const
|
|
218
|
-
results.push(
|
|
219
|
-
}
|
|
459
|
+
for (const { slug, dir = "packages", path } of workspacePackages) {
|
|
460
|
+
const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
|
|
461
|
+
if (pkg) results.push(pkg);
|
|
462
|
+
}
|
|
220
463
|
return results;
|
|
221
464
|
}
|
|
222
|
-
|
|
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-";
|
|
465
|
+
// src/commands/setup/labels.ts
|
|
229
466
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* is how third-party plugins published outside the org work.
|
|
467
|
+
* The labels every repository gets from `setup`, with their GitHub colours (hex, no `#`) and descriptions. A
|
|
468
|
+
* plugin that makes labels of its own, such as Linear's setup, takes the colour of the one with the same name.
|
|
233
469
|
*/
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
470
|
+
const CANONICAL_LABELS = [
|
|
471
|
+
{
|
|
472
|
+
name: "bug",
|
|
473
|
+
color: "d73a4a",
|
|
474
|
+
description: "Something isn't working"
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: "chore",
|
|
478
|
+
color: "ededed",
|
|
479
|
+
description: "Maintenance, no user-facing change"
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: "ci",
|
|
483
|
+
color: "0075ca",
|
|
484
|
+
description: "CI/CD pipeline changes"
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
name: "dependencies",
|
|
488
|
+
color: "0366d6",
|
|
489
|
+
description: "Dependency update"
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
name: "documentation",
|
|
493
|
+
color: "0075ca",
|
|
494
|
+
description: "Documentation only"
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
name: "duplicate",
|
|
498
|
+
color: "cfd3d7",
|
|
499
|
+
description: "Already reported"
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
name: "enhancement",
|
|
503
|
+
color: "a2eeef",
|
|
504
|
+
description: "New feature or request"
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: "good first issue",
|
|
508
|
+
color: "7057ff",
|
|
509
|
+
description: "Good for newcomers"
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
name: "help wanted",
|
|
513
|
+
color: "008672",
|
|
514
|
+
description: "Extra attention needed"
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
name: "invalid",
|
|
518
|
+
color: "e4e669",
|
|
519
|
+
description: "Doesn't seem right"
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
name: "performance",
|
|
523
|
+
color: "fbca04",
|
|
524
|
+
description: "Performance improvement"
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
name: "question",
|
|
528
|
+
color: "d876e3",
|
|
529
|
+
description: "Further information requested"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
name: "refactor",
|
|
533
|
+
color: "cfd3d7",
|
|
534
|
+
description: "Code restructuring"
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
name: "released",
|
|
538
|
+
color: "ededed",
|
|
539
|
+
description: "Included in a release"
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
name: "test",
|
|
543
|
+
color: "bfd4f2",
|
|
544
|
+
description: "Test-related changes"
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
name: "triage",
|
|
548
|
+
color: "e4e669",
|
|
549
|
+
description: "Needs investigation"
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
name: "wontfix",
|
|
553
|
+
color: "ffffff",
|
|
554
|
+
description: "Won't be addressed"
|
|
281
555
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
556
|
+
];
|
|
557
|
+
// src/commands/token-rotation/token-rotation.ts
|
|
558
|
+
/** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
|
|
559
|
+
const DEFAULT_TOKEN_ROTATION = {
|
|
560
|
+
maxAgeDays: 90,
|
|
561
|
+
warnDays: 14
|
|
562
|
+
};
|
|
563
|
+
const DAY_MS = 864e5;
|
|
564
|
+
/** The whole days from `from` to `to`, rounded down (negative once `to` is past). */
|
|
565
|
+
function daysBetween(from, to) {
|
|
566
|
+
return Math.floor((to.getTime() - from.getTime()) / DAY_MS);
|
|
291
567
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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;
|
|
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
|
-
};
|
|
568
|
+
/** `2026-11-13` of a valid date. */
|
|
569
|
+
const day = (d) => d.toISOString().slice(0, 10);
|
|
570
|
+
/** A valid `Date` of an ISO string, or `undefined` when there is none or it does not parse. */
|
|
571
|
+
function parse(value) {
|
|
572
|
+
if (value === void 0) return void 0;
|
|
573
|
+
const date = new Date(value);
|
|
574
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
329
575
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
576
|
+
/**
|
|
577
|
+
* Rows saying whether a token is due for rotation, from what its provider exposes. Provider-neutral: a token probe reads
|
|
578
|
+
* the lifetime however its provider offers it and hands it here, with the layer's `rotation` from `tokenExpectations()`.
|
|
579
|
+
* `lifetime` is `undefined` when the provider exposes nothing (the row says so rather than passing), and a date the
|
|
580
|
+
* provider gave that does not parse is an `info` row, never a pass. An expired or near-expiry token fails, and so does
|
|
581
|
+
* one older than `maxAgeDays`. Only dates are printed, never the token.
|
|
582
|
+
*/
|
|
583
|
+
function tokenRotationRows(lifetime, rotation, now) {
|
|
584
|
+
if (!lifetime) return [{
|
|
585
|
+
status: "info",
|
|
586
|
+
label: "rotation",
|
|
587
|
+
detail: `the provider does not expose this token's age or expiry; rotate it by hand every ${rotation.maxAgeDays} days`
|
|
588
|
+
}];
|
|
589
|
+
const rows = [];
|
|
590
|
+
const expires = parse(lifetime.expiresAt);
|
|
591
|
+
if (lifetime.expiresAt !== void 0 && !expires) rows.push({
|
|
592
|
+
status: "info",
|
|
593
|
+
label: "expiry",
|
|
594
|
+
detail: "the provider's expiry date could not be read"
|
|
595
|
+
});
|
|
596
|
+
else if (expires) {
|
|
597
|
+
const left = daysBetween(now, expires);
|
|
598
|
+
if (expires.getTime() <= now.getTime()) rows.push({
|
|
599
|
+
status: "fail",
|
|
600
|
+
label: "expiry",
|
|
601
|
+
detail: `expired on ${day(expires)}`
|
|
602
|
+
});
|
|
603
|
+
else if (left < rotation.warnDays) rows.push({
|
|
604
|
+
status: "fail",
|
|
605
|
+
label: "expiry",
|
|
606
|
+
detail: `expires on ${day(expires)} (${left} days left, warns under ${rotation.warnDays}); rotate it`
|
|
607
|
+
});
|
|
608
|
+
else rows.push({
|
|
609
|
+
status: "ok",
|
|
610
|
+
label: "expiry",
|
|
611
|
+
detail: `expires on ${day(expires)} (${left} days left)`
|
|
612
|
+
});
|
|
613
|
+
} else rows.push({
|
|
614
|
+
status: "info",
|
|
615
|
+
label: "expiry",
|
|
616
|
+
detail: "the token has no expiry"
|
|
617
|
+
});
|
|
618
|
+
const created = parse(lifetime.createdAt);
|
|
619
|
+
if (lifetime.createdAt !== void 0 && !created) rows.push({
|
|
620
|
+
status: "info",
|
|
621
|
+
label: "age",
|
|
622
|
+
detail: "the provider's creation date could not be read"
|
|
623
|
+
});
|
|
624
|
+
else if (created) {
|
|
625
|
+
const age = daysBetween(created, now);
|
|
626
|
+
const due = age > rotation.maxAgeDays;
|
|
627
|
+
rows.push({
|
|
628
|
+
status: due ? "fail" : "ok",
|
|
629
|
+
label: "age",
|
|
630
|
+
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})`
|
|
631
|
+
});
|
|
632
|
+
} else rows.push({
|
|
633
|
+
status: "info",
|
|
634
|
+
label: "age",
|
|
635
|
+
detail: "the provider does not say when the token was made"
|
|
636
|
+
});
|
|
637
|
+
return rows;
|
|
334
638
|
}
|
|
639
|
+
// src/commands/token-expectations/token-expectations.ts
|
|
335
640
|
/**
|
|
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());
|
|
641
|
+
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
642
|
+
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
643
|
+
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
355
644
|
*/
|
|
356
|
-
function
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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];
|
|
645
|
+
function tokenExpectations(tokens, filter = {}) {
|
|
646
|
+
const found = [];
|
|
647
|
+
for (const token of tokens) {
|
|
648
|
+
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
649
|
+
const { layers = [], permissions = {} } = token.expect;
|
|
650
|
+
for (const layer of ENVIRONMENT_LAYERS) {
|
|
651
|
+
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
652
|
+
const rules = permissions[layer];
|
|
653
|
+
if (!rules && !layers.includes(layer)) continue;
|
|
654
|
+
const entries = Object.entries(rules ?? {});
|
|
655
|
+
found.push({
|
|
656
|
+
envName: token.envName,
|
|
657
|
+
layer,
|
|
658
|
+
rules: rules ?? {},
|
|
659
|
+
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
660
|
+
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name),
|
|
661
|
+
rotation: {
|
|
662
|
+
...DEFAULT_TOKEN_ROTATION,
|
|
663
|
+
...token.expect.rotation
|
|
664
|
+
}
|
|
665
|
+
});
|
|
393
666
|
}
|
|
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;
|
|
407
667
|
}
|
|
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
|
-
};
|
|
668
|
+
return found;
|
|
417
669
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
670
|
+
// src/commands/auth-export/stdout-kind/stdout-kind.ts
|
|
671
|
+
/**
|
|
672
|
+
* What file descriptor `fd` (stdout) is, for deciding where tokens may go: a `terminal`, a `pipe` (a FIFO, or the
|
|
673
|
+
* socket some shells and runners use for one), or `other` (a regular file, a device, or anything that cannot be
|
|
674
|
+
* inspected). Only a pipe is safe to write the lines to, so anything unknown is `other`.
|
|
675
|
+
*/
|
|
676
|
+
function stdoutKind(isTerminal, fd = 1, stat = fstatSync) {
|
|
677
|
+
if (isTerminal) return "terminal";
|
|
678
|
+
try {
|
|
679
|
+
const s = stat(fd);
|
|
680
|
+
return s.isFIFO() || s.isSocket() ? "pipe" : "other";
|
|
681
|
+
} catch {
|
|
682
|
+
return "other";
|
|
683
|
+
}
|
|
422
684
|
}
|
|
423
|
-
|
|
424
|
-
//#region src/config/load-config.ts
|
|
685
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
425
686
|
/**
|
|
426
|
-
* `holocron.
|
|
687
|
+
* The vault Environment `holocron sync secrets --env <environment>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
688
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
689
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
690
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
427
691
|
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
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.
|
|
692
|
+
* @param id - The `--env` value the user gave.
|
|
693
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
694
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
435
695
|
*/
|
|
436
|
-
|
|
696
|
+
async function resolveEnvironmentId(id, input) {
|
|
697
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
698
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
699
|
+
}
|
|
700
|
+
// src/private-dir/ignore-advice/ignore-advice.ts
|
|
701
|
+
/** The line that says how to fix a credentials path the version control ignore rules do not cover. */
|
|
702
|
+
function ignoreAdvice(isDefault, choose) {
|
|
703
|
+
return isDefault ? "the private directory's ignore rule is missing: run `holocron sync` to add it" : `add it to .gitignore, or ${choose}`;
|
|
704
|
+
}
|
|
705
|
+
/** The file `export tokens` and `new github-app` write by default, relative to the repository root. */
|
|
706
|
+
const PRIVATE_CREDENTIALS_FILE = `.holocron/.private/.credentials`;
|
|
707
|
+
// src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
|
|
437
708
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
709
|
+
* The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
|
|
710
|
+
* under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
|
|
711
|
+
* about a path whose directory exists and the file cannot be written without it.
|
|
441
712
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
713
|
+
function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
|
|
714
|
+
recursive: true,
|
|
715
|
+
mode: 448
|
|
716
|
+
})) {
|
|
717
|
+
if (file) return {
|
|
718
|
+
path: resolve(base, file),
|
|
719
|
+
isDefault: false
|
|
720
|
+
};
|
|
721
|
+
const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
|
|
722
|
+
makeDir(dirname(path));
|
|
448
723
|
return {
|
|
449
|
-
|
|
450
|
-
|
|
724
|
+
path,
|
|
725
|
+
isDefault: true
|
|
451
726
|
};
|
|
452
727
|
}
|
|
453
|
-
|
|
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];
|
|
497
|
-
}
|
|
498
|
-
//#endregion
|
|
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 };
|
|
728
|
+
export { AuthError, CANONICAL_LABELS, CARDINALITY, ConfigError, ConfigFileError, DEFAULT_TOKEN_ROTATION, ElevationRequiredError, HOLOCRON_AREAS, KNOWN_STACK_DEPS, MissingTokenError, PRIVATE_CREDENTIALS_FILE, ProviderApiError, REQUIRED_CAPABILITIES, SHARED_AREAS, WebhookVerificationError, compose, connectionProbe, createFeatureResolver, createResolveToken, createRestClient, credentialsEnvironment, defineConfig, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, ignoreAdvice, isMulti, keyring, loadConfig, missingCapabilities, orderKeys, pickByCreation, placeAreas, readKeysLimited, readLinks, readWorkspacePackageJsons, reportProgress, resolveConfig, resolveCredentialsFile, resolveEntry, resolveEnvironmentId, resolvePluginPackage, resolveValue, roleTeamProblem, sourceProblem, stdoutKind, syncRoles, tokenExpectations, tokenRotationRows };
|