@theholocron/cli 5.0.0-alpha.423 → 5.0.0-alpha.424

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/dist/cli.mjs CHANGED
@@ -2877,6 +2877,34 @@ async function loadAvatar(source, baseDir = process.cwd(), fetchImpl = fetch) {
2877
2877
  if (!type) throw new Error("it is not a PNG, JPEG or GIF image, which are the formats providers accept");
2878
2878
  return `data:${type};base64,${bytes.toString("base64")}`;
2879
2879
  }
2880
+ // src/commands/secrets-sync/repo-name/repo-name.ts
2881
+ /** `holocron` from `holocron` or `theholocron/holocron`: the config accepts both, the provider takes the name. */
2882
+ function repoName(repo) {
2883
+ return repo.slice(repo.indexOf("/") + 1);
2884
+ }
2885
+ // src/commands/notifications-channel-add/layout-secret-scope.ts
2886
+ /**
2887
+ * Where the notification secrets are written, with who may read them (spec `tech-org-secret-visibility`, #2131).
2888
+ * A repository or environment scope is returned as it is. An organization scope gets visibility `selected` and the
2889
+ * layout's `readers` (as repository names in that organization), so a Discord webhook is never readable by every
2890
+ * repository. It fails closed: no `readers` is a problem naming the field, not a silent `all`, and a reader outside the
2891
+ * organization is one too. An existing secret with another visibility is narrowed when it is written again.
2892
+ *
2893
+ * @param scope - The scope the run writes to.
2894
+ * @param readers - The layout's `readers`, as `owner/repo`.
2895
+ * @returns The scope to write to, or why there is none.
2896
+ */
2897
+ function layoutSecretScope(scope, readers) {
2898
+ if (scope.kind !== "organization") return { scope };
2899
+ if (!readers || readers.length === 0) return { problem: `the notification secrets would be readable by every repository of ${scope.name}: list the repositories that read them in the layout's \`readers\` (for example ["${scope.name}/<repo>"])` };
2900
+ const outside = readers.filter((r) => !r.startsWith(`${scope.name}/`));
2901
+ if (outside.length > 0) return { problem: `\`readers\` must be repositories of ${scope.name} (owner/repo); not: ${outside.join(", ")}` };
2902
+ return { scope: {
2903
+ ...scope,
2904
+ visibility: "selected",
2905
+ repos: [...new Set(readers.map(repoName))]
2906
+ } };
2907
+ }
2880
2908
  // src/commands/notifications-channel-add/notifications-channel-add.ts
2881
2909
  /**
2882
2910
  * `holocron new channel` — create one channel (and, with
@@ -3181,11 +3209,16 @@ async function runNotificationsChannelAdd(input) {
3181
3209
  secrets = loader.get("secrets");
3182
3210
  }
3183
3211
  const org = input.context.org;
3184
- const scope = input.scope ?? (org ? {
3212
+ let scope = input.scope ?? (org ? {
3185
3213
  kind: "organization",
3186
3214
  name: org
3187
3215
  } : void 0);
3188
3216
  if (input.withWebhook && !scope && !dryRun) throw new Error("no org to store the webhook secret under — pass --scope or set `org` in holocron.config.ts");
3217
+ if (input.withWebhook && scope && !dryRun) {
3218
+ const narrowed = layoutSecretScope(scope, notifications.layout?.readers);
3219
+ if ("problem" in narrowed) throw new Error(narrowed.problem);
3220
+ scope = narrowed.scope;
3221
+ }
3189
3222
  if (secrets && scope && !dryRun) await assertSecretsReachable(secrets, scope);
3190
3223
  const channel = await provisionChannel({
3191
3224
  notifications,
@@ -8250,7 +8283,7 @@ async function runNotificationsSetup(input$1) {
8250
8283
  secrets = loader.get("secrets");
8251
8284
  }
8252
8285
  const org = input$1.context.org;
8253
- const scope = input$1.scope ?? (org ? {
8286
+ let scope = input$1.scope ?? (org ? {
8254
8287
  kind: "organization",
8255
8288
  name: org
8256
8289
  } : void 0);
@@ -8300,10 +8333,15 @@ async function runNotificationsSetup(input$1) {
8300
8333
  return refuse(`webhook avatar ${errorMessage(err)}`);
8301
8334
  }
8302
8335
  }
8303
- if (secrets && scope && !dryRun) try {
8304
- await assertSecretsReachable(secrets, scope);
8305
- } catch (err) {
8306
- return refuse(errorMessage(err), logReason(err));
8336
+ if (secrets && scope && !dryRun) {
8337
+ const narrowed = layoutSecretScope(scope, layout.readers);
8338
+ if ("problem" in narrowed) return refuse(narrowed.problem);
8339
+ scope = narrowed.scope;
8340
+ try {
8341
+ await assertSecretsReachable(secrets, scope);
8342
+ } catch (err) {
8343
+ return refuse(errorMessage(err), logReason(err));
8344
+ }
8307
8345
  }
8308
8346
  const secretProblem = layoutSecretProblem(layout);
8309
8347
  if (secretProblem) return refuse(secretProblem);
@@ -11677,11 +11715,6 @@ function expectedSecrets(config, layouts) {
11677
11715
  environments: Object.fromEntries(Object.entries(declared?.environments ?? {}).map(([env, names]) => [env, uniqueNames(names)]))
11678
11716
  };
11679
11717
  }
11680
- // src/commands/secrets-sync/repo-name/repo-name.ts
11681
- /** `holocron` from `holocron` or `theholocron/holocron`: the config accepts both, the provider takes the name. */
11682
- function repoName(repo) {
11683
- return repo.slice(repo.indexOf("/") + 1);
11684
- }
11685
11718
  // src/commands/doctor-secrets/synced-secrets.ts
11686
11719
  /**
11687
11720
  * The secrets `holocron sync secrets` fills from a vault, as `repo.secrets.sync` declares them: which names land at
@@ -11762,7 +11795,8 @@ async function runDoctorSecrets(input) {
11762
11795
  await loader.load();
11763
11796
  assertPluginsResolvable$1(loader, "doctor secrets");
11764
11797
  const config = input.loaded.resolved;
11765
- const expected = expectedSecrets(config, (loader.has("notifications") ? loader.get("notifications") : []).flatMap((p) => p.layout ? [p.layout] : []));
11798
+ const layouts = (loader.has("notifications") ? loader.get("notifications") : []).flatMap((p) => p.layout ? [p.layout] : []);
11799
+ const expected = expectedSecrets(config, layouts);
11766
11800
  const org = input.context.org ?? (input.context.repo ?? config.repo?.name ?? "").split("/")[0];
11767
11801
  const synced = await syncedSecrets(config.repo?.secrets?.sync ?? [], loader.has("vault") ? loader.get("vault") : { why: whyMissing(loader, "vault", "no `vault` provider to list the environment's keys with") });
11768
11802
  const foreignOrgs = /* @__PURE__ */ new Map();
@@ -11841,6 +11875,16 @@ async function runDoctorSecrets(input) {
11841
11875
  for (const name of names) entry.declared.set(name, [...new Set(repos)].sort());
11842
11876
  readers.set(scope.name, entry);
11843
11877
  }
11878
+ for (const layout of layouts) {
11879
+ if (!org || !layout.readers?.length) continue;
11880
+ const entry = readers.get(org) ?? {
11881
+ org,
11882
+ declared: /* @__PURE__ */ new Map()
11883
+ };
11884
+ const repos = [...new Set(layout.readers.map(repoName))].sort();
11885
+ for (const name of layoutSecretNames(layout)) entry.declared.set(name, repos);
11886
+ readers.set(org, entry);
11887
+ }
11844
11888
  for (const entry of readers.values()) rows.push(await accessRow(secrets, entry, entry.org === org));
11845
11889
  if (expected.org.length > 0) rows.push(await shadowRow(secrets, expected.org));
11846
11890
  }
@@ -13770,6 +13814,12 @@ function hooksEnabled(input) {
13770
13814
  return config.repo?.protection === "strict";
13771
13815
  }
13772
13816
  // src/commands/repo-files/generate-config-files.ts
13817
+ /** Where a repo that hosts the reusables keeps the sources of its generated workflows and the actions they run. */
13818
+ const HOSTED_SOURCES = [
13819
+ "/ci/workflows",
13820
+ "/ci/workflows/*",
13821
+ "/ci/actions/*"
13822
+ ];
13773
13823
  function file(path, content, note) {
13774
13824
  const step = `write ${path}`;
13775
13825
  return {
@@ -13791,7 +13841,10 @@ async function generateConfigFiles(input) {
13791
13841
  const taskNames = (config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name);
13792
13842
  const entries = [];
13793
13843
  if (taskNames.includes("bookkeeping")) entries.push(file(".github/labeler.yml", createLabeler()));
13794
- if (config.repo?.protection !== "none") entries.push(file(".github/dependabot.yml", createDependabot({ ignore: ownCatalogPackages(input.repoRoot) })), file(".github/dco.yml", createDco()));
13844
+ if (config.repo?.protection !== "none") entries.push(file(".github/dependabot.yml", createDependabot({
13845
+ ignore: ownCatalogPackages(input.repoRoot),
13846
+ sources: hostsReusables(input.repoRoot) ? HOSTED_SOURCES : []
13847
+ })), file(".github/dco.yml", createDco()));
13795
13848
  entries.push(file(".alexrc.json", createAlexrc()), file(".alexignore", createAlexignore()), file(".yamllint.yml", createYamllint()), file(".yamlignore", createYamlignore()), file(".editorconfig", createEditorconfig()), file(".editorconfig-checker.json", createEditorconfigChecker()), file("devmoji.config.cjs", createDevmoji()), file(".husky/prepare-commit-msg", createPrepareCommitMsg()), file(".husky/commit-msg", createCommitMsg(config.holocronScript)));
13796
13849
  if (hooksEnabled(input)) entries.push(file(".husky/pre-push", createPrePush(config.holocronScript), "runs `holocron run ci` before push — bypass with `git push --no-verify`"), file(".husky/pre-commit", createPreCommit(), "runs GitLeaks (staged-only) + lint-staged before commit"));
13797
13850
  else for (const hook of [".husky/pre-push", ".husky/pre-commit"]) entries.push({