@theholocron/cli 5.0.0-alpha.273 → 5.0.0-alpha.275
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 +3 -1
- package/dist/cli.mjs +894 -387
- package/dist/cli.mjs.map +1 -1
- package/dist/{index-EayNimLh.d.mts → index-Cs7LmYWL.d.mts} +74 -1
- package/dist/{index-CmNllp81.d.mts → index-DgjlIpm1.d.mts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/plugin/capabilities.d.mts +2 -2
- package/dist/presets.d.mts +1 -1
- package/package.json +9 -9
package/dist/cli.mjs
CHANGED
|
@@ -221,6 +221,8 @@ const COMMAND_CONTEXTS = {
|
|
|
221
221
|
"doctor all": "workspace",
|
|
222
222
|
"doctor notifications": "workspace",
|
|
223
223
|
"doctor environments": "workspace",
|
|
224
|
+
"doctor dns": "workspace",
|
|
225
|
+
"doctor repo": "workspace",
|
|
224
226
|
"doctor secrets": "workspace",
|
|
225
227
|
"doctor tokens": "workspace",
|
|
226
228
|
"doctor monitoring": "workspace",
|
|
@@ -1423,6 +1425,13 @@ const doctorAllEntry = {
|
|
|
1423
1425
|
supportsDryRun: false,
|
|
1424
1426
|
spawnArgs: ["doctor", "--all"]
|
|
1425
1427
|
};
|
|
1428
|
+
// src/commands/doctor-dns/doctor-dns.entry.ts
|
|
1429
|
+
const doctorDnsEntry = {
|
|
1430
|
+
name: "doctor dns",
|
|
1431
|
+
description: "Check that the DNS records the config makes setup write exist and point where they should (read-only)",
|
|
1432
|
+
positionals: [],
|
|
1433
|
+
supportsDryRun: false
|
|
1434
|
+
};
|
|
1426
1435
|
// src/commands/doctor-environments/doctor-environments.entry.ts
|
|
1427
1436
|
const doctorEnvironmentsEntry = {
|
|
1428
1437
|
name: "doctor environments",
|
|
@@ -1451,6 +1460,13 @@ const doctorNotificationsEntry = {
|
|
|
1451
1460
|
}],
|
|
1452
1461
|
supportsDryRun: false
|
|
1453
1462
|
};
|
|
1463
|
+
// src/commands/doctor-repo/doctor-repo.entry.ts
|
|
1464
|
+
const doctorRepoEntry = {
|
|
1465
|
+
name: "doctor repo",
|
|
1466
|
+
description: "Check the repository settings against the config (read-only): description, topics, labels, teams, protection, security",
|
|
1467
|
+
positionals: [],
|
|
1468
|
+
supportsDryRun: false
|
|
1469
|
+
};
|
|
1454
1470
|
// src/commands/doctor-secrets/doctor-secrets.entry.ts
|
|
1455
1471
|
const doctorSecretsEntry = {
|
|
1456
1472
|
name: "doctor secrets",
|
|
@@ -1678,6 +1694,8 @@ const COMMAND_REGISTRY = [
|
|
|
1678
1694
|
doctorMonitoringEntry,
|
|
1679
1695
|
doctorNotificationsEntry,
|
|
1680
1696
|
doctorEnvironmentsEntry,
|
|
1697
|
+
doctorDnsEntry,
|
|
1698
|
+
doctorRepoEntry,
|
|
1681
1699
|
doctorSecretsEntry,
|
|
1682
1700
|
doctorTokensEntry,
|
|
1683
1701
|
doctorVariablesEntry,
|
|
@@ -4437,6 +4455,246 @@ function layoutSecretNames(layout) {
|
|
|
4437
4455
|
const fromRoles = (layout.roles ?? []).flatMap((role) => role.secret ? [role.secret] : []);
|
|
4438
4456
|
return [...fromChannels, ...fromRoles];
|
|
4439
4457
|
}
|
|
4458
|
+
// src/commands/notifications-setup/avatar-problem.ts
|
|
4459
|
+
/** The first reason a feed's `avatar` cannot work, or undefined. `feed` names the key for the message (`monitoring`, `errors`). */
|
|
4460
|
+
function avatarProblem(channel, feed, picture) {
|
|
4461
|
+
if (typeof picture !== "object") return void 0;
|
|
4462
|
+
if (!picture.url && !picture.image) return `channel \`${channel}\`: \`feeds.${feed}.avatar\` needs a \`url\`, an \`image\`, or both`;
|
|
4463
|
+
if (picture.url && !/^https:\/\//i.test(picture.url)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.url\` must be an https:// URL`;
|
|
4464
|
+
if (picture.image && /^https?:\/\//i.test(picture.image)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.image\` must be a file in the repo, not a URL`;
|
|
4465
|
+
}
|
|
4466
|
+
/** The webhook name a channel's error feed uses: its own, else the provider's name, capitalised (`Sentry`). */
|
|
4467
|
+
function errorsFeedWebhook(feed, errors) {
|
|
4468
|
+
return (typeof feed === "object" ? feed.webhook : void 0) ?? capitalised(errors.providerName);
|
|
4469
|
+
}
|
|
4470
|
+
const capitalised = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
4471
|
+
/** The Worker binding that holds the webhook URL for a source (the contract `apps/comlink` reads). */
|
|
4472
|
+
const relayWebhookBinding = (source) => `COMLINK_${source.toUpperCase()}_WEBHOOK`;
|
|
4473
|
+
/** The Worker binding that holds a source's signing secret (the contract `apps/comlink` reads). */
|
|
4474
|
+
const relaySecretBinding = (source) => `COMLINK_${source.toUpperCase()}_SECRET`;
|
|
4475
|
+
/** Whether any channel in the layout is fed by the error tracker. */
|
|
4476
|
+
function wantsRelay(layout) {
|
|
4477
|
+
return (layout.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.feeds?.errors));
|
|
4478
|
+
}
|
|
4479
|
+
/**
|
|
4480
|
+
* The first reason the relay cannot be deployed, or undefined. One source has one webhook, so only one channel can be
|
|
4481
|
+
* fed by it; and the Worker needs somewhere to answer.
|
|
4482
|
+
*/
|
|
4483
|
+
function relayProblem(layout, errors, monitoring) {
|
|
4484
|
+
const fed = (layout.categories ?? []).flatMap((c) => c.channels ?? []).filter((ch) => ch.feeds?.errors);
|
|
4485
|
+
if (fed.length === 0) return void 0;
|
|
4486
|
+
if (!layout.relay?.host) return `channel \`${fed[0].name}\` is fed by the error tracker, which needs \`relay.host\` — where the relay Worker answers`;
|
|
4487
|
+
if (fed.length > 1) return `channels ${fed.map((c) => `\`${c.name}\``).join(" and ")} are all fed by the error tracker, but its relay posts to one channel — feed one`;
|
|
4488
|
+
const channel = fed[0];
|
|
4489
|
+
const errorsFeed = channel.feeds.errors;
|
|
4490
|
+
const picture = typeof errorsFeed === "object" ? errorsFeed.avatar : void 0;
|
|
4491
|
+
const pictureProblem = avatarProblem(channel.name, "errors", picture);
|
|
4492
|
+
if (pictureProblem) return pictureProblem;
|
|
4493
|
+
if (errors) {
|
|
4494
|
+
const feed = errorsFeedWebhook(errorsFeed, errors).toLowerCase();
|
|
4495
|
+
const own = (typeof channel.webhook === "object" ? channel.webhook.name : void 0) ?? channel.name;
|
|
4496
|
+
if (channel.webhook && feed === own.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the channel's own webhook are both named ${own} — rename one`;
|
|
4497
|
+
const monitoringFeed = channel.feeds.monitoring;
|
|
4498
|
+
if (monitoring && monitoringFeed) {
|
|
4499
|
+
const other = (typeof monitoringFeed === "object" ? monitoringFeed.webhook : void 0) ?? capitalised(monitoring.providerName);
|
|
4500
|
+
if (feed === other.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the monitoring webhook are both named ${other} — rename one`;
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
/**
|
|
4505
|
+
* What to hand the `dns` capability as the zone: the layout's, else the host itself. The provider looks a name up from
|
|
4506
|
+
* the full name towards the apex until it finds a zone it holds, so this is right for any suffix (`example.co.uk`).
|
|
4507
|
+
*/
|
|
4508
|
+
const relayZone = (relay) => relay.zone ?? relay.host;
|
|
4509
|
+
/**
|
|
4510
|
+
* Deploy the Worker with its webhook secret and its route, then point the host at it with a proxied placeholder record
|
|
4511
|
+
* (the Worker answers before any origin is asked). The built file is read first and the DNS record comes last, so a
|
|
4512
|
+
* missing build or a failed deploy leaves the host untouched.
|
|
4513
|
+
*/
|
|
4514
|
+
async function deployRelay(input) {
|
|
4515
|
+
const { relay, workers, dns } = input;
|
|
4516
|
+
const path = join(input.repoRoot, relay.code ?? "apps/comlink/dist/worker.js");
|
|
4517
|
+
let code;
|
|
4518
|
+
try {
|
|
4519
|
+
code = await (input.readCode ?? ((p) => readFile(p, "utf8")))(path);
|
|
4520
|
+
} catch {
|
|
4521
|
+
throw new Error(`the relay Worker is not built (${relay.code ?? "apps/comlink/dist/worker.js"}) — run \`pnpm --filter @theholocron/comlink run delivery.build\``);
|
|
4522
|
+
}
|
|
4523
|
+
const script = relay.script ?? "comlink";
|
|
4524
|
+
await workers.deployScript(script, {
|
|
4525
|
+
code,
|
|
4526
|
+
secrets: {
|
|
4527
|
+
[relayWebhookBinding(input.source)]: input.webhook,
|
|
4528
|
+
...input.signingSecret ? { [relaySecretBinding(input.source)]: input.signingSecret } : {}
|
|
4529
|
+
},
|
|
4530
|
+
routes: [`${relay.host}/*`]
|
|
4531
|
+
});
|
|
4532
|
+
await dns.upsertRecord(relayZone(relay), {
|
|
4533
|
+
type: "AAAA",
|
|
4534
|
+
name: relay.host,
|
|
4535
|
+
content: "100::",
|
|
4536
|
+
ttl: 1,
|
|
4537
|
+
proxied: true
|
|
4538
|
+
});
|
|
4539
|
+
return {
|
|
4540
|
+
host: relay.host,
|
|
4541
|
+
script
|
|
4542
|
+
};
|
|
4543
|
+
}
|
|
4544
|
+
// src/commands/setup/preview-config-of.ts
|
|
4545
|
+
/**
|
|
4546
|
+
* The preview configuration (the Pages project and the preview domain) that drives project and DNS provisioning.
|
|
4547
|
+
* `delivery.deploy`, `knowledge.docs` and `knowledge.components` all share the same combined production and preview
|
|
4548
|
+
* mechanism, so any one of them can carry it. `null` when none does.
|
|
4549
|
+
*/
|
|
4550
|
+
function previewConfigOf(config) {
|
|
4551
|
+
const entry = (config.tasks ?? []).map((e) => typeof e === "string" ? { name: e } : e).find((e) => e.name === "delivery.deploy" || e.name === "knowledge.docs" || e.name === "knowledge.components");
|
|
4552
|
+
return entry?.with ? extractPreviewConfig(entry.with, {
|
|
4553
|
+
org: config.org,
|
|
4554
|
+
domain: config.domain
|
|
4555
|
+
}) : null;
|
|
4556
|
+
}
|
|
4557
|
+
// src/commands/doctor-dns/expected-dns-records.ts
|
|
4558
|
+
/**
|
|
4559
|
+
* The DNS records the config makes `holocron repo setup` and `notifications setup` write, as far as they can be
|
|
4560
|
+
* known without writing anything: the preview domain's apex and wildcard CNAMEs (on a Cloudflare deployment), the
|
|
4561
|
+
* docs host a wiki provider asks for, and the relay Worker's proxied placeholder. A record that
|
|
4562
|
+
* `Deployment.ensureCustomDomain()` returns is left out, since asking for it creates the domain.
|
|
4563
|
+
*/
|
|
4564
|
+
function expectedDnsRecords(config, sources) {
|
|
4565
|
+
const expected = [];
|
|
4566
|
+
const preview = previewConfigOf(config);
|
|
4567
|
+
if (preview?.domain && sources.deployment?.providerName === "cloudflare") {
|
|
4568
|
+
const content = `${preview.project}.pages.dev`;
|
|
4569
|
+
for (const name of [preview.domain, `*.${preview.domain}`]) expected.push({
|
|
4570
|
+
zone: preview.domain,
|
|
4571
|
+
record: {
|
|
4572
|
+
type: "CNAME",
|
|
4573
|
+
name,
|
|
4574
|
+
content
|
|
4575
|
+
}
|
|
4576
|
+
});
|
|
4577
|
+
}
|
|
4578
|
+
const docs = sources.wiki?.dnsRecord?.();
|
|
4579
|
+
if (docs) {
|
|
4580
|
+
const { type, name, content } = docs.record;
|
|
4581
|
+
expected.push({
|
|
4582
|
+
zone: docs.zone,
|
|
4583
|
+
record: {
|
|
4584
|
+
type,
|
|
4585
|
+
name,
|
|
4586
|
+
content,
|
|
4587
|
+
...sources.wiki?.proxyConfig?.() ? { proxied: true } : {}
|
|
4588
|
+
}
|
|
4589
|
+
});
|
|
4590
|
+
}
|
|
4591
|
+
for (const { relay } of sources.layouts) if (relay) expected.push({
|
|
4592
|
+
zone: relayZone(relay),
|
|
4593
|
+
record: {
|
|
4594
|
+
type: "AAAA",
|
|
4595
|
+
name: relay.host,
|
|
4596
|
+
content: "100::",
|
|
4597
|
+
proxied: true
|
|
4598
|
+
}
|
|
4599
|
+
});
|
|
4600
|
+
return expected;
|
|
4601
|
+
}
|
|
4602
|
+
// src/commands/doctor-dns/doctor-dns.ts
|
|
4603
|
+
/**
|
|
4604
|
+
* `holocron doctor dns` — do the DNS records the config makes setup write exist, pointing where they should?
|
|
4605
|
+
*
|
|
4606
|
+
* Read-only. One row per zone, each record looked up by type and name (case-insensitively) in what the `dns`
|
|
4607
|
+
* provider lists for the zone. A record that is missing, points elsewhere, or is not proxied where it must be is a
|
|
4608
|
+
* problem; a record in the zone that is not expected never is. With no `dns` provider and records expected, the
|
|
4609
|
+
* rows are skips with the reason; a provider with no token for the read skips its zone.
|
|
4610
|
+
*/
|
|
4611
|
+
/** `CNAME *.example.com`: a record is its type and its name, however the provider spells the case or the final dot. */
|
|
4612
|
+
const keyOf = (record) => `${record.type} ${record.name.toLowerCase().replace(/\.$/, "")}`;
|
|
4613
|
+
const sameContent = (a, b) => a.toLowerCase().replace(/\.$/, "") === b.toLowerCase().replace(/\.$/, "");
|
|
4614
|
+
async function runDoctorDns(input) {
|
|
4615
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
4616
|
+
const logger = input.logger ?? getLogger();
|
|
4617
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
4618
|
+
await loader.load();
|
|
4619
|
+
assertPluginsResolvable(loader, "doctor dns");
|
|
4620
|
+
const expected = expectedDnsRecords(input.loaded.resolved, {
|
|
4621
|
+
...loader.has("deployment") ? { deployment: loader.get("deployment") } : {},
|
|
4622
|
+
...loader.has("wiki") ? { wiki: loader.get("wiki") } : {},
|
|
4623
|
+
layouts: (loader.has("notifications") ? loader.get("notifications") : []).flatMap((p) => p.layout ? [p.layout] : [])
|
|
4624
|
+
});
|
|
4625
|
+
const zones = [...new Set(expected.map((e) => e.zone))];
|
|
4626
|
+
const rows = [];
|
|
4627
|
+
if (zones.length === 0) rows.push({
|
|
4628
|
+
id: "dns",
|
|
4629
|
+
title: "dns",
|
|
4630
|
+
status: "ok",
|
|
4631
|
+
detail: "none declared",
|
|
4632
|
+
problems: []
|
|
4633
|
+
});
|
|
4634
|
+
else if (!loader.has("dns")) {
|
|
4635
|
+
const why = whyMissing(loader, "dns", "no `dns` provider to check them with");
|
|
4636
|
+
for (const zone of zones) rows.push(row$3(zone, "skip", why));
|
|
4637
|
+
} else {
|
|
4638
|
+
const dns = loader.get("dns");
|
|
4639
|
+
for (const zone of zones) rows.push(await checkZone(dns, zone, expected.filter((e) => e.zone === zone).map((e) => e.record)));
|
|
4640
|
+
}
|
|
4641
|
+
printCheckRows(rows, print);
|
|
4642
|
+
const summary = summariseChecks(rows);
|
|
4643
|
+
printCheckSummary(summary, print);
|
|
4644
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
4645
|
+
logger.info({
|
|
4646
|
+
...summary,
|
|
4647
|
+
status
|
|
4648
|
+
}, "doctor dns");
|
|
4649
|
+
return {
|
|
4650
|
+
status,
|
|
4651
|
+
rows,
|
|
4652
|
+
summary,
|
|
4653
|
+
...status === "skip" ? { reason: [...new Set(rows.map((r) => r.detail))].join("; ") } : {}
|
|
4654
|
+
};
|
|
4655
|
+
}
|
|
4656
|
+
function row$3(zone, status, detail, problems = []) {
|
|
4657
|
+
return {
|
|
4658
|
+
id: `dns-${zone}`,
|
|
4659
|
+
title: `${zone} records exist`,
|
|
4660
|
+
status,
|
|
4661
|
+
detail,
|
|
4662
|
+
problems
|
|
4663
|
+
};
|
|
4664
|
+
}
|
|
4665
|
+
async function checkZone(dns, zone, wanted) {
|
|
4666
|
+
try {
|
|
4667
|
+
const have = await dns.listRecords(zone);
|
|
4668
|
+
const problems = declaredVsActual(new Map(wanted.map((w) => [keyOf(w), w])), new Map(have.map((h) => [keyOf(h), h])), {
|
|
4669
|
+
noun: "record",
|
|
4670
|
+
flagExtra: false,
|
|
4671
|
+
equal: (want, found) => sameContent(want.content, found.content) && (want.proxied !== true || found.proxied === true),
|
|
4672
|
+
show: (r) => `${r.content}${r.proxied ? " (proxied)" : ""}`
|
|
4673
|
+
});
|
|
4674
|
+
return problems.length > 0 ? row$3(zone, "fail", `${problems.length} problem(s)`, problems) : row$3(zone, "ok", `${wanted.length} of ${wanted.length} exist`);
|
|
4675
|
+
} catch (err) {
|
|
4676
|
+
return err instanceof MissingTokenError ? row$3(zone, "skip", err.message) : row$3(zone, "fail", errorMessage(err));
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
// src/commands/doctor-dns/doctor-dns.command.ts
|
|
4680
|
+
const doctorDnsCommand = {
|
|
4681
|
+
command: "dns",
|
|
4682
|
+
describe: "Check that the DNS records the config makes setup write exist and point where they should (read-only)",
|
|
4683
|
+
handler: async (argv) => {
|
|
4684
|
+
const tokens = tokenContext(argv.token);
|
|
4685
|
+
if (!tokens) return;
|
|
4686
|
+
const loaded = await loadConfig(argv.cwd);
|
|
4687
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
4688
|
+
if ((await runDoctorDns({
|
|
4689
|
+
loaded,
|
|
4690
|
+
context: {
|
|
4691
|
+
repoRoot: argv.cwd,
|
|
4692
|
+
...tokens,
|
|
4693
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
4694
|
+
}
|
|
4695
|
+
})).status === "fail") process.exitCode = 1;
|
|
4696
|
+
}
|
|
4697
|
+
};
|
|
4440
4698
|
// src/commands/setup/setup-environments.ts
|
|
4441
4699
|
/** The deployment environments `holocron repo setup` creates when an `environments` provider is configured. */
|
|
4442
4700
|
const SETUP_ENVIRONMENTS = ["staging", "production"];
|
|
@@ -5803,73 +6061,609 @@ const doctorNotificationsCommand = {
|
|
|
5803
6061
|
})).status === "fail") process.exitCode = 1;
|
|
5804
6062
|
}
|
|
5805
6063
|
};
|
|
5806
|
-
// src/commands/
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
const seen = /* @__PURE__ */ new Map();
|
|
5810
|
-
for (const name of names) if (!seen.has(name.toUpperCase())) seen.set(name.toUpperCase(), name);
|
|
5811
|
-
return [...seen.values()];
|
|
5812
|
-
};
|
|
5813
|
-
// src/commands/doctor-secrets/expected-secrets.ts
|
|
5814
|
-
/**
|
|
5815
|
-
* The secret a Chromatic project reads: `CHROMATIC_PROJECT_TOKEN` for `default` (or no name), otherwise
|
|
5816
|
-
* `CHROMATIC_PROJECT_TOKEN_<NAME>`.
|
|
5817
|
-
*/
|
|
5818
|
-
const chromaticSecret = (tokenName) => !tokenName || tokenName === "default" ? "CHROMATIC_PROJECT_TOKEN" : `CHROMATIC_PROJECT_TOKEN_${tokenName.toUpperCase()}`;
|
|
5819
|
-
/**
|
|
5820
|
-
* The secrets the config says must exist: the names listed in `repo.secrets`, plus the ones it implies. A
|
|
5821
|
-
* notification layout fills a secret per webhook and per role (organization scope), and each project of a
|
|
5822
|
-
* `verification.visualRegression` task reads a Chromatic token (repository scope).
|
|
5823
|
-
*/
|
|
5824
|
-
function expectedSecrets(config, layouts) {
|
|
5825
|
-
const declared = config.repo?.secrets;
|
|
5826
|
-
const chromatic = (config.tasks ?? []).flatMap((task) => typeof task === "object" && task.name === "verification.visualRegression" ? (task.with?.["chromatic-projects"] ?? []).map((project) => chromaticSecret(project.tokenName)) : []);
|
|
6064
|
+
// src/commands/setup/branch-protection.ts
|
|
6065
|
+
const RULESET_NAME = "holocron-default-branch";
|
|
6066
|
+
function buildClassicProtectionPayload(requiredChecks = []) {
|
|
5827
6067
|
return {
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
6068
|
+
required_status_checks: requiredChecks.length > 0 ? {
|
|
6069
|
+
strict: false,
|
|
6070
|
+
contexts: requiredChecks
|
|
6071
|
+
} : null,
|
|
6072
|
+
enforce_admins: false,
|
|
6073
|
+
required_pull_request_reviews: {
|
|
6074
|
+
required_approving_review_count: 0,
|
|
6075
|
+
dismiss_stale_reviews: false,
|
|
6076
|
+
require_code_owner_reviews: false
|
|
6077
|
+
},
|
|
6078
|
+
restrictions: null,
|
|
6079
|
+
allow_force_pushes: false,
|
|
6080
|
+
allow_deletions: false
|
|
5831
6081
|
};
|
|
5832
6082
|
}
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
for (const entry of entries) {
|
|
5848
|
-
const id = `sync-${entry.environment}`;
|
|
5849
|
-
const title = `${entry.environment} vault environment is synced`;
|
|
5850
|
-
let scope;
|
|
5851
|
-
try {
|
|
5852
|
-
scope = parseScope(entry.scope ?? "repo");
|
|
5853
|
-
} catch (err) {
|
|
5854
|
-
rows.push({
|
|
5855
|
-
id,
|
|
5856
|
-
title,
|
|
5857
|
-
status: "fail",
|
|
5858
|
-
detail: "1 problem(s)",
|
|
5859
|
-
problems: [describeProviderError(err)]
|
|
5860
|
-
});
|
|
5861
|
-
continue;
|
|
5862
|
-
}
|
|
5863
|
-
if (entry.keys) {
|
|
5864
|
-
scopes.push({
|
|
5865
|
-
scope,
|
|
5866
|
-
names: entry.keys
|
|
5867
|
-
});
|
|
5868
|
-
continue;
|
|
6083
|
+
function buildRulesetPayload(requiredChecks = []) {
|
|
6084
|
+
const rules = [
|
|
6085
|
+
{ type: "deletion" },
|
|
6086
|
+
{ type: "non_fast_forward" },
|
|
6087
|
+
{
|
|
6088
|
+
type: "pull_request",
|
|
6089
|
+
parameters: {
|
|
6090
|
+
required_approving_review_count: 0,
|
|
6091
|
+
dismiss_stale_reviews_on_push: false,
|
|
6092
|
+
require_code_owner_review: false,
|
|
6093
|
+
require_last_push_approval: false,
|
|
6094
|
+
required_review_thread_resolution: true,
|
|
6095
|
+
require_extra_approval_for_unattributed_changes: false
|
|
6096
|
+
}
|
|
5869
6097
|
}
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
6098
|
+
];
|
|
6099
|
+
if (requiredChecks.length > 0) rules.push({
|
|
6100
|
+
type: "required_status_checks",
|
|
6101
|
+
parameters: {
|
|
6102
|
+
required_status_checks: requiredChecks.map((context) => ({ context })),
|
|
6103
|
+
strict_required_status_checks_policy: false
|
|
6104
|
+
}
|
|
6105
|
+
});
|
|
6106
|
+
return {
|
|
6107
|
+
name: RULESET_NAME,
|
|
6108
|
+
target: "branch",
|
|
6109
|
+
enforcement: "active",
|
|
6110
|
+
bypass_actors: [{
|
|
6111
|
+
actor_id: 4,
|
|
6112
|
+
actor_type: "RepositoryRole",
|
|
6113
|
+
bypass_mode: "always"
|
|
6114
|
+
}],
|
|
6115
|
+
conditions: { ref_name: {
|
|
6116
|
+
include: ["~DEFAULT_BRANCH"],
|
|
6117
|
+
exclude: []
|
|
6118
|
+
} },
|
|
6119
|
+
rules
|
|
6120
|
+
};
|
|
6121
|
+
}
|
|
6122
|
+
async function upsertBranchProtection(source, dryRun, requiredChecks) {
|
|
6123
|
+
const step = `upsert ruleset ${RULESET_NAME}`;
|
|
6124
|
+
if (dryRun) return {
|
|
6125
|
+
capability: "source",
|
|
6126
|
+
step,
|
|
6127
|
+
status: "dry-run"
|
|
6128
|
+
};
|
|
6129
|
+
try {
|
|
6130
|
+
const found = (await source.listRulesets()).find((r) => r.name === RULESET_NAME);
|
|
6131
|
+
if (found) {
|
|
6132
|
+
await source.updateRuleset(found.id, buildRulesetPayload(requiredChecks));
|
|
6133
|
+
return {
|
|
6134
|
+
capability: "source",
|
|
6135
|
+
step,
|
|
6136
|
+
status: "ok",
|
|
6137
|
+
message: "updated"
|
|
6138
|
+
};
|
|
6139
|
+
}
|
|
6140
|
+
await source.createRuleset(buildRulesetPayload(requiredChecks));
|
|
6141
|
+
return {
|
|
6142
|
+
capability: "source",
|
|
6143
|
+
step,
|
|
6144
|
+
status: "ok",
|
|
6145
|
+
message: "created"
|
|
6146
|
+
};
|
|
6147
|
+
} catch (err) {
|
|
6148
|
+
if (!(err instanceof ProviderApiError$1) || err.status !== 403) return {
|
|
6149
|
+
capability: "source",
|
|
6150
|
+
step,
|
|
6151
|
+
status: "fail",
|
|
6152
|
+
message: errorMessage(err)
|
|
6153
|
+
};
|
|
6154
|
+
}
|
|
6155
|
+
try {
|
|
6156
|
+
const repo = await source.getRepo();
|
|
6157
|
+
await source.protectBranch(repo.defaultBranch, buildClassicProtectionPayload(requiredChecks));
|
|
6158
|
+
return {
|
|
6159
|
+
capability: "source",
|
|
6160
|
+
step,
|
|
6161
|
+
status: "ok",
|
|
6162
|
+
message: `classic protection on ${repo.defaultBranch}`
|
|
6163
|
+
};
|
|
6164
|
+
} catch (err) {
|
|
6165
|
+
if (err instanceof ProviderApiError$1 && err.status === 403) return {
|
|
6166
|
+
capability: "source",
|
|
6167
|
+
step,
|
|
6168
|
+
status: "skip",
|
|
6169
|
+
message: "branch protection unavailable on private repos without GitHub Pro/Team"
|
|
6170
|
+
};
|
|
6171
|
+
return {
|
|
6172
|
+
capability: "source",
|
|
6173
|
+
step,
|
|
6174
|
+
status: "fail",
|
|
6175
|
+
message: errorMessage(err)
|
|
6176
|
+
};
|
|
6177
|
+
}
|
|
6178
|
+
}
|
|
6179
|
+
// src/commands/setup/labels.ts
|
|
6180
|
+
const CANONICAL_LABELS = [
|
|
6181
|
+
{
|
|
6182
|
+
name: "bug",
|
|
6183
|
+
color: "d73a4a",
|
|
6184
|
+
description: "Something isn't working"
|
|
6185
|
+
},
|
|
6186
|
+
{
|
|
6187
|
+
name: "chore",
|
|
6188
|
+
color: "ededed",
|
|
6189
|
+
description: "Maintenance, no user-facing change"
|
|
6190
|
+
},
|
|
6191
|
+
{
|
|
6192
|
+
name: "ci",
|
|
6193
|
+
color: "0075ca",
|
|
6194
|
+
description: "CI/CD pipeline changes"
|
|
6195
|
+
},
|
|
6196
|
+
{
|
|
6197
|
+
name: "dependencies",
|
|
6198
|
+
color: "0366d6",
|
|
6199
|
+
description: "Dependency update"
|
|
6200
|
+
},
|
|
6201
|
+
{
|
|
6202
|
+
name: "documentation",
|
|
6203
|
+
color: "0075ca",
|
|
6204
|
+
description: "Documentation only"
|
|
6205
|
+
},
|
|
6206
|
+
{
|
|
6207
|
+
name: "duplicate",
|
|
6208
|
+
color: "cfd3d7",
|
|
6209
|
+
description: "Already reported"
|
|
6210
|
+
},
|
|
6211
|
+
{
|
|
6212
|
+
name: "enhancement",
|
|
6213
|
+
color: "a2eeef",
|
|
6214
|
+
description: "New feature or request"
|
|
6215
|
+
},
|
|
6216
|
+
{
|
|
6217
|
+
name: "good first issue",
|
|
6218
|
+
color: "7057ff",
|
|
6219
|
+
description: "Good for newcomers"
|
|
6220
|
+
},
|
|
6221
|
+
{
|
|
6222
|
+
name: "help wanted",
|
|
6223
|
+
color: "008672",
|
|
6224
|
+
description: "Extra attention needed"
|
|
6225
|
+
},
|
|
6226
|
+
{
|
|
6227
|
+
name: "invalid",
|
|
6228
|
+
color: "e4e669",
|
|
6229
|
+
description: "Doesn't seem right"
|
|
6230
|
+
},
|
|
6231
|
+
{
|
|
6232
|
+
name: "performance",
|
|
6233
|
+
color: "fbca04",
|
|
6234
|
+
description: "Performance improvement"
|
|
6235
|
+
},
|
|
6236
|
+
{
|
|
6237
|
+
name: "question",
|
|
6238
|
+
color: "d876e3",
|
|
6239
|
+
description: "Further information requested"
|
|
6240
|
+
},
|
|
6241
|
+
{
|
|
6242
|
+
name: "refactor",
|
|
6243
|
+
color: "cfd3d7",
|
|
6244
|
+
description: "Code restructuring"
|
|
6245
|
+
},
|
|
6246
|
+
{
|
|
6247
|
+
name: "released",
|
|
6248
|
+
color: "ededed",
|
|
6249
|
+
description: "Included in a release"
|
|
6250
|
+
},
|
|
6251
|
+
{
|
|
6252
|
+
name: "test",
|
|
6253
|
+
color: "bfd4f2",
|
|
6254
|
+
description: "Test-related changes"
|
|
6255
|
+
},
|
|
6256
|
+
{
|
|
6257
|
+
name: "triage",
|
|
6258
|
+
color: "e4e669",
|
|
6259
|
+
description: "Needs investigation"
|
|
6260
|
+
},
|
|
6261
|
+
{
|
|
6262
|
+
name: "wontfix",
|
|
6263
|
+
color: "ffffff",
|
|
6264
|
+
description: "Won't be addressed"
|
|
6265
|
+
}
|
|
6266
|
+
];
|
|
6267
|
+
const STALE_LABELS = [
|
|
6268
|
+
"github_actions",
|
|
6269
|
+
"javascript",
|
|
6270
|
+
"autorelease: pending",
|
|
6271
|
+
"autorelease: tagged",
|
|
6272
|
+
"released on @alpha"
|
|
6273
|
+
];
|
|
6274
|
+
// src/commands/setup/repo-settings.ts
|
|
6275
|
+
const BALANCED_REPO_SETTINGS = {
|
|
6276
|
+
allow_squash_merge: true,
|
|
6277
|
+
allow_merge_commit: false,
|
|
6278
|
+
allow_rebase_merge: false,
|
|
6279
|
+
allow_auto_merge: true,
|
|
6280
|
+
allow_update_branch: true,
|
|
6281
|
+
delete_branch_on_merge: true,
|
|
6282
|
+
has_issues: true,
|
|
6283
|
+
has_discussions: true,
|
|
6284
|
+
has_projects: true,
|
|
6285
|
+
has_wiki: false
|
|
6286
|
+
};
|
|
6287
|
+
// src/commands/doctor-repo/repo-checks.ts
|
|
6288
|
+
const quote = (value) => JSON.stringify(value);
|
|
6289
|
+
const onOff = (value) => value ? "on" : "off";
|
|
6290
|
+
/**
|
|
6291
|
+
* The groups of repository settings `repo setup` writes through the `source` capability, each only when the config
|
|
6292
|
+
* declares it (labels and security toggles are always written, so they are always checked). Variables, secrets and
|
|
6293
|
+
* environments are separate checks. Pages, `CODEOWNERS` and the generated files are not compared here.
|
|
6294
|
+
*/
|
|
6295
|
+
function repoChecks(config, repoRoot) {
|
|
6296
|
+
const repo = config.repo;
|
|
6297
|
+
const preset = repo?.protection && repo.protection !== "none" ? repo.protection : void 0;
|
|
6298
|
+
const checks = [];
|
|
6299
|
+
if (config.description || config.homepage) checks.push({
|
|
6300
|
+
id: "repo-description",
|
|
6301
|
+
title: "description and homepage match",
|
|
6302
|
+
needs: "getRepoInfo",
|
|
6303
|
+
async run(source) {
|
|
6304
|
+
const info = await source.getRepoInfo();
|
|
6305
|
+
const declared = /* @__PURE__ */ new Map();
|
|
6306
|
+
if (config.description) declared.set("description", config.description);
|
|
6307
|
+
if (config.homepage) declared.set("homepage", config.homepage);
|
|
6308
|
+
return {
|
|
6309
|
+
problems: declaredVsActual(declared, /* @__PURE__ */ new Map([["description", info.description ?? ""], ["homepage", info.homepage ?? ""]]), {
|
|
6310
|
+
noun: "repository field",
|
|
6311
|
+
flagExtra: false,
|
|
6312
|
+
show: quote
|
|
6313
|
+
}),
|
|
6314
|
+
checked: declared.size
|
|
6315
|
+
};
|
|
6316
|
+
}
|
|
6317
|
+
});
|
|
6318
|
+
if (repo?.defaultBranch || preset) checks.push({
|
|
6319
|
+
id: "repo-settings",
|
|
6320
|
+
title: "default branch and settings match",
|
|
6321
|
+
needs: "getRepoInfo",
|
|
6322
|
+
async run(source) {
|
|
6323
|
+
const info = await source.getRepoInfo();
|
|
6324
|
+
const declared = new Map(Object.entries(preset ? BALANCED_REPO_SETTINGS : {}));
|
|
6325
|
+
if (repo?.defaultBranch) declared.set("default_branch", repo.defaultBranch);
|
|
6326
|
+
return {
|
|
6327
|
+
problems: declaredVsActual(declared, new Map(Object.entries(info.settings)), {
|
|
6328
|
+
noun: "repository setting",
|
|
6329
|
+
flagExtra: false,
|
|
6330
|
+
show: quote
|
|
6331
|
+
}),
|
|
6332
|
+
checked: declared.size
|
|
6333
|
+
};
|
|
6334
|
+
}
|
|
6335
|
+
});
|
|
6336
|
+
if (repo?.topics && repo.topics.length > 0) {
|
|
6337
|
+
const topics = repo.topics;
|
|
6338
|
+
checks.push({
|
|
6339
|
+
id: "repo-topics",
|
|
6340
|
+
title: "topics match",
|
|
6341
|
+
needs: "getRepoInfo",
|
|
6342
|
+
async run(source) {
|
|
6343
|
+
const info = await source.getRepoInfo();
|
|
6344
|
+
return {
|
|
6345
|
+
problems: declaredVsActual(new Map(topics.map((t) => [t, true])), new Map(info.topics.map((t) => [t, true])), { noun: "topic" }),
|
|
6346
|
+
checked: topics.length
|
|
6347
|
+
};
|
|
6348
|
+
}
|
|
6349
|
+
});
|
|
6350
|
+
}
|
|
6351
|
+
const properties = declaredProperties(config);
|
|
6352
|
+
if (properties.size > 0) checks.push({
|
|
6353
|
+
id: "repo-properties",
|
|
6354
|
+
title: "custom properties match",
|
|
6355
|
+
needs: "getProperties",
|
|
6356
|
+
async run(source) {
|
|
6357
|
+
const found = await source.getProperties();
|
|
6358
|
+
const actual = new Map(Object.entries(found).map(([name, v]) => [name, Array.isArray(v) ? v.join(",") : v]));
|
|
6359
|
+
return {
|
|
6360
|
+
problems: declaredVsActual(properties, actual, {
|
|
6361
|
+
noun: "property",
|
|
6362
|
+
flagExtra: false,
|
|
6363
|
+
show: quote
|
|
6364
|
+
}),
|
|
6365
|
+
checked: properties.size
|
|
6366
|
+
};
|
|
6367
|
+
}
|
|
6368
|
+
});
|
|
6369
|
+
checks.push({
|
|
6370
|
+
id: "repo-labels",
|
|
6371
|
+
title: "labels match",
|
|
6372
|
+
needs: "listLabels",
|
|
6373
|
+
async run(source) {
|
|
6374
|
+
const found = await source.listLabels();
|
|
6375
|
+
const actual = new Map(found.map((l) => [l.name.toLowerCase(), l]));
|
|
6376
|
+
const problems = declaredVsActual(new Map(CANONICAL_LABELS.map((l) => [l.name, l])), actual, {
|
|
6377
|
+
noun: "label",
|
|
6378
|
+
flagExtra: false,
|
|
6379
|
+
equal: (a, b) => a.color === b.color && a.description === b.description,
|
|
6380
|
+
show: (l) => `${l.color} ${quote(l.description)}`
|
|
6381
|
+
});
|
|
6382
|
+
for (const name of STALE_LABELS) if (actual.has(name)) problems.push(`stale label ${name} (repo setup removes it)`);
|
|
6383
|
+
return {
|
|
6384
|
+
problems,
|
|
6385
|
+
checked: CANONICAL_LABELS.length
|
|
6386
|
+
};
|
|
6387
|
+
}
|
|
6388
|
+
});
|
|
6389
|
+
if (repo?.teams && repo.teams.length > 0) {
|
|
6390
|
+
const teams = repo.teams;
|
|
6391
|
+
checks.push({
|
|
6392
|
+
id: "repo-teams",
|
|
6393
|
+
title: "team access matches",
|
|
6394
|
+
needs: "listTeamAccess",
|
|
6395
|
+
async run(source) {
|
|
6396
|
+
const found = await source.listTeamAccess();
|
|
6397
|
+
return {
|
|
6398
|
+
problems: declaredVsActual(new Map(teams.map(teamPermission)), new Map(found.map((t) => [t.slug, t.permission])), {
|
|
6399
|
+
noun: "team",
|
|
6400
|
+
flagExtra: false,
|
|
6401
|
+
show: quote
|
|
6402
|
+
}),
|
|
6403
|
+
checked: teams.length
|
|
6404
|
+
};
|
|
6405
|
+
}
|
|
6406
|
+
});
|
|
6407
|
+
}
|
|
6408
|
+
if (preset) checks.push({
|
|
6409
|
+
id: "repo-protection",
|
|
6410
|
+
title: "branch protection matches",
|
|
6411
|
+
needs: "getRulesetDetail",
|
|
6412
|
+
async run(source) {
|
|
6413
|
+
let rulesets;
|
|
6414
|
+
try {
|
|
6415
|
+
rulesets = await source.listRulesets();
|
|
6416
|
+
} catch (err) {
|
|
6417
|
+
if (err instanceof ProviderApiError$1 && err.status === 403) return { skip: "rulesets are not available on this plan (classic branch protection is not read)" };
|
|
6418
|
+
throw err;
|
|
6419
|
+
}
|
|
6420
|
+
const found = rulesets.find((r) => r.name === RULESET_NAME);
|
|
6421
|
+
if (!found) return {
|
|
6422
|
+
problems: [`missing ruleset ${RULESET_NAME}`],
|
|
6423
|
+
checked: 1
|
|
6424
|
+
};
|
|
6425
|
+
const detail = await source.getRulesetDetail(found.id);
|
|
6426
|
+
const required = preset === "strict" ? strictChecks(config, repoRoot) : [];
|
|
6427
|
+
const rules = [
|
|
6428
|
+
"deletion",
|
|
6429
|
+
"non_fast_forward",
|
|
6430
|
+
"pull_request",
|
|
6431
|
+
...required.length > 0 ? ["required_status_checks"] : []
|
|
6432
|
+
];
|
|
6433
|
+
return {
|
|
6434
|
+
problems: [
|
|
6435
|
+
...declaredVsActual(/* @__PURE__ */ new Map([["enforcement", "active"]]), /* @__PURE__ */ new Map([["enforcement", detail.enforcement]]), {
|
|
6436
|
+
noun: "ruleset",
|
|
6437
|
+
show: quote
|
|
6438
|
+
}),
|
|
6439
|
+
...declaredVsActual(new Map(rules.map((r) => [r, true])), new Map(detail.ruleTypes.map((r) => [r, true])), { noun: "ruleset rule" }),
|
|
6440
|
+
...declaredVsActual(new Map(required.map((c) => [c, true])), new Map(detail.requiredChecks.map((c) => [c, true])), { noun: "required check" })
|
|
6441
|
+
],
|
|
6442
|
+
checked: 1 + rules.length + required.length
|
|
6443
|
+
};
|
|
6444
|
+
}
|
|
6445
|
+
});
|
|
6446
|
+
checks.push({
|
|
6447
|
+
id: "repo-security",
|
|
6448
|
+
title: "security settings match",
|
|
6449
|
+
needs: "getSecurity",
|
|
6450
|
+
async run(source) {
|
|
6451
|
+
const found = await source.getSecurity();
|
|
6452
|
+
const wanted = {
|
|
6453
|
+
vulnerabilityAlerts: true,
|
|
6454
|
+
automatedSecurityFixes: true,
|
|
6455
|
+
secretScanning: true,
|
|
6456
|
+
secretScanningPushProtection: true,
|
|
6457
|
+
privateVulnerabilityReporting: true,
|
|
6458
|
+
codeScanningDefaultSetup: !(config.tasks ?? []).map((e) => typeof e === "string" ? e : e.name).includes("security.codeScanning")
|
|
6459
|
+
};
|
|
6460
|
+
const declared = new Map(Object.entries(wanted).filter(([k]) => k in found));
|
|
6461
|
+
if (declared.size === 0) return { skip: "the provider reported none of the security settings" };
|
|
6462
|
+
return {
|
|
6463
|
+
problems: declaredVsActual(declared, new Map(Object.entries(found)), {
|
|
6464
|
+
noun: "security setting",
|
|
6465
|
+
flagExtra: false,
|
|
6466
|
+
show: onOff
|
|
6467
|
+
}),
|
|
6468
|
+
checked: declared.size
|
|
6469
|
+
};
|
|
6470
|
+
}
|
|
6471
|
+
});
|
|
6472
|
+
return checks;
|
|
6473
|
+
}
|
|
6474
|
+
function teamPermission(entry) {
|
|
6475
|
+
return typeof entry === "string" ? [entry, "push"] : [entry.slug, entry.permission];
|
|
6476
|
+
}
|
|
6477
|
+
/** The custom properties the config declares (and the protection level `repo setup` stamps), as text. */
|
|
6478
|
+
function declaredProperties(config) {
|
|
6479
|
+
const repo = config.repo;
|
|
6480
|
+
const out = /* @__PURE__ */ new Map();
|
|
6481
|
+
if (repo?.protection && repo.protection !== "none") out.set("holocron_branch_protection_level", repo.protection);
|
|
6482
|
+
const manual = repo?.properties ?? {};
|
|
6483
|
+
if (manual.lifecycle) out.set("lifecycle", manual.lifecycle);
|
|
6484
|
+
if (manual.open_source !== void 0) out.set("open_source", String(manual.open_source));
|
|
6485
|
+
if (manual.runtime_environment) out.set("runtime_environment", manual.runtime_environment);
|
|
6486
|
+
if (manual.uses_external_packages !== void 0) out.set("uses_external_packages", String(manual.uses_external_packages));
|
|
6487
|
+
return out;
|
|
6488
|
+
}
|
|
6489
|
+
/** The status checks a `strict` ruleset requires, derived from the task manifest exactly as `repo setup` does. */
|
|
6490
|
+
function strictChecks(config, repoRoot) {
|
|
6491
|
+
const tasksConfig = { tasks: config.tasks };
|
|
6492
|
+
if (config.extraRequiredChecks) tasksConfig.extraRequiredChecks = config.extraRequiredChecks;
|
|
6493
|
+
return ["DCO", ...createAstromech({
|
|
6494
|
+
cwd: repoRoot,
|
|
6495
|
+
config: tasksConfig,
|
|
6496
|
+
logger: getLogger()
|
|
6497
|
+
}).requiredChecks()];
|
|
6498
|
+
}
|
|
6499
|
+
// src/commands/doctor-repo/doctor-repo.ts
|
|
6500
|
+
/**
|
|
6501
|
+
* `holocron doctor repo` — do the repository settings `repo setup` writes match the config?
|
|
6502
|
+
*
|
|
6503
|
+
* Read-only. One row per group `repo setup` manages through the `source` capability, each only when the config
|
|
6504
|
+
* declares it: description and homepage, default branch and merge settings, topics, custom properties, labels, team
|
|
6505
|
+
* access, branch protection and security settings (see {@link repoChecks}). Something that exists but is not declared
|
|
6506
|
+
* is a problem only where `repo setup` would remove it (topics, stale labels, a ruleset's rules). A group that cannot
|
|
6507
|
+
* be read because there is no provider, the provider lacks the read method or the token is missing is a skip with the
|
|
6508
|
+
* reason, not a failure. Variables, secrets and environments have their own checks.
|
|
6509
|
+
*/
|
|
6510
|
+
async function runDoctorRepo(input) {
|
|
6511
|
+
const print = input.print ?? ((line) => console.log(line));
|
|
6512
|
+
const logger = input.logger ?? getLogger();
|
|
6513
|
+
const loader = input.loader ?? new PluginLoader(input.loaded.resolved, input.context);
|
|
6514
|
+
await loader.load();
|
|
6515
|
+
assertPluginsResolvable(loader, "doctor repo");
|
|
6516
|
+
const checks = repoChecks(input.loaded.resolved, input.context.repoRoot);
|
|
6517
|
+
const rows = [];
|
|
6518
|
+
if (!loader.has("source")) {
|
|
6519
|
+
const why = whyMissing(loader, "source", "no `source` provider to read the repository with");
|
|
6520
|
+
for (const check of checks) rows.push(row$2(check, { skip: why }));
|
|
6521
|
+
} else {
|
|
6522
|
+
const source = loader.get("source");
|
|
6523
|
+
for (const check of checks) {
|
|
6524
|
+
if (typeof source[check.needs] !== "function") {
|
|
6525
|
+
rows.push(row$2(check, { skip: `provider does not implement ${check.needs}` }));
|
|
6526
|
+
continue;
|
|
6527
|
+
}
|
|
6528
|
+
try {
|
|
6529
|
+
rows.push(row$2(check, await check.run(source)));
|
|
6530
|
+
} catch (err) {
|
|
6531
|
+
if (err instanceof MissingTokenError) rows.push(row$2(check, { skip: err.message }));
|
|
6532
|
+
else rows.push({
|
|
6533
|
+
id: check.id,
|
|
6534
|
+
title: check.title,
|
|
6535
|
+
status: "fail",
|
|
6536
|
+
detail: errorMessage(err),
|
|
6537
|
+
problems: []
|
|
6538
|
+
});
|
|
6539
|
+
}
|
|
6540
|
+
}
|
|
6541
|
+
}
|
|
6542
|
+
printCheckRows(rows, print);
|
|
6543
|
+
const summary = summariseChecks(rows);
|
|
6544
|
+
printCheckSummary(summary, print);
|
|
6545
|
+
const status = summary.fail > 0 ? "fail" : summary.ok === 0 ? "skip" : "ok";
|
|
6546
|
+
logger.info({
|
|
6547
|
+
...summary,
|
|
6548
|
+
status
|
|
6549
|
+
}, "doctor repo");
|
|
6550
|
+
return {
|
|
6551
|
+
status,
|
|
6552
|
+
rows,
|
|
6553
|
+
summary,
|
|
6554
|
+
...status === "skip" ? { reason: rows.map((r) => r.detail).join("; ") } : {}
|
|
6555
|
+
};
|
|
6556
|
+
}
|
|
6557
|
+
function row$2(check, result) {
|
|
6558
|
+
const { id, title } = check;
|
|
6559
|
+
if ("skip" in result) return {
|
|
6560
|
+
id,
|
|
6561
|
+
title,
|
|
6562
|
+
status: "skip",
|
|
6563
|
+
detail: result.skip,
|
|
6564
|
+
problems: []
|
|
6565
|
+
};
|
|
6566
|
+
if (result.problems.length > 0) return {
|
|
6567
|
+
id,
|
|
6568
|
+
title,
|
|
6569
|
+
status: "fail",
|
|
6570
|
+
detail: `${result.problems.length} problem(s)`,
|
|
6571
|
+
problems: result.problems
|
|
6572
|
+
};
|
|
6573
|
+
return {
|
|
6574
|
+
id,
|
|
6575
|
+
title,
|
|
6576
|
+
status: "ok",
|
|
6577
|
+
detail: `${result.checked} of ${result.checked} match`,
|
|
6578
|
+
problems: []
|
|
6579
|
+
};
|
|
6580
|
+
}
|
|
6581
|
+
// src/commands/doctor-repo/doctor-repo.command.ts
|
|
6582
|
+
const doctorRepoCommand = {
|
|
6583
|
+
command: "repo",
|
|
6584
|
+
describe: "Check the repository settings against the config (read-only): description, topics, labels, teams, protection, security",
|
|
6585
|
+
handler: async (argv) => {
|
|
6586
|
+
const tokens = tokenContext(argv.token);
|
|
6587
|
+
if (!tokens) return;
|
|
6588
|
+
const loaded = await loadConfig(argv.cwd);
|
|
6589
|
+
applyResolvedConfig(argv, loaded.resolved);
|
|
6590
|
+
if ((await runDoctorRepo({
|
|
6591
|
+
loaded,
|
|
6592
|
+
context: {
|
|
6593
|
+
repoRoot: argv.cwd,
|
|
6594
|
+
...tokens,
|
|
6595
|
+
org: resolveOrg(argv, loaded.resolved)
|
|
6596
|
+
}
|
|
6597
|
+
})).status === "fail") process.exitCode = 1;
|
|
6598
|
+
}
|
|
6599
|
+
};
|
|
6600
|
+
// src/commands/doctor-secrets/unique-names.ts
|
|
6601
|
+
/** Names that differ only in case are one secret to GitHub, so the first spelling wins. */
|
|
6602
|
+
const uniqueNames = (names) => {
|
|
6603
|
+
const seen = /* @__PURE__ */ new Map();
|
|
6604
|
+
for (const name of names) if (!seen.has(name.toUpperCase())) seen.set(name.toUpperCase(), name);
|
|
6605
|
+
return [...seen.values()];
|
|
6606
|
+
};
|
|
6607
|
+
// src/commands/doctor-secrets/expected-secrets.ts
|
|
6608
|
+
/**
|
|
6609
|
+
* The secret a Chromatic project reads: `CHROMATIC_PROJECT_TOKEN` for `default` (or no name), otherwise
|
|
6610
|
+
* `CHROMATIC_PROJECT_TOKEN_<NAME>`.
|
|
6611
|
+
*/
|
|
6612
|
+
const chromaticSecret = (tokenName) => !tokenName || tokenName === "default" ? "CHROMATIC_PROJECT_TOKEN" : `CHROMATIC_PROJECT_TOKEN_${tokenName.toUpperCase()}`;
|
|
6613
|
+
/**
|
|
6614
|
+
* The secrets the config says must exist: the names listed in `repo.secrets`, plus the ones it implies. A
|
|
6615
|
+
* notification layout fills a secret per webhook and per role (organization scope), and each project of a
|
|
6616
|
+
* `verification.visualRegression` task reads a Chromatic token (repository scope).
|
|
6617
|
+
*/
|
|
6618
|
+
function expectedSecrets(config, layouts) {
|
|
6619
|
+
const declared = config.repo?.secrets;
|
|
6620
|
+
const chromatic = (config.tasks ?? []).flatMap((task) => typeof task === "object" && task.name === "verification.visualRegression" ? (task.with?.["chromatic-projects"] ?? []).map((project) => chromaticSecret(project.tokenName)) : []);
|
|
6621
|
+
return {
|
|
6622
|
+
repo: uniqueNames([...declared?.repo ?? [], ...chromatic]),
|
|
6623
|
+
org: uniqueNames([...declared?.org ?? [], ...layouts.flatMap(layoutSecretNames)]),
|
|
6624
|
+
environments: Object.fromEntries(Object.entries(declared?.environments ?? {}).map(([env, names]) => [env, uniqueNames(names)]))
|
|
6625
|
+
};
|
|
6626
|
+
}
|
|
6627
|
+
// src/commands/doctor-secrets/synced-secrets.ts
|
|
6628
|
+
/**
|
|
6629
|
+
* The secrets `holocron secrets sync` fills from a vault, as `repo.secrets.sync` declares them: which names land at
|
|
6630
|
+
* which scope. An entry that lists `keys` needs no vault. One that does not asks the vault which keys the environment
|
|
6631
|
+
* holds, and only the names are kept: the values the provider returns are dropped at once and never logged or printed.
|
|
6632
|
+
* An entry that cannot be resolved (no vault, no token, an environment the vault cannot list) is a skipped row with
|
|
6633
|
+
* the reason, and an unreadable `scope` is a failed one.
|
|
6634
|
+
*
|
|
6635
|
+
* @param entries - `repo.secrets.sync`.
|
|
6636
|
+
* @param vault - The `vault` provider, or why there is none.
|
|
6637
|
+
*/
|
|
6638
|
+
async function syncedSecrets(entries, vault) {
|
|
6639
|
+
const scopes = [];
|
|
6640
|
+
const rows = [];
|
|
6641
|
+
for (const entry of entries) {
|
|
6642
|
+
const id = `sync-${entry.environment}`;
|
|
6643
|
+
const title = `${entry.environment} vault environment is synced`;
|
|
6644
|
+
let scope;
|
|
6645
|
+
try {
|
|
6646
|
+
scope = parseScope(entry.scope ?? "repo");
|
|
6647
|
+
} catch (err) {
|
|
6648
|
+
rows.push({
|
|
6649
|
+
id,
|
|
6650
|
+
title,
|
|
6651
|
+
status: "fail",
|
|
6652
|
+
detail: "1 problem(s)",
|
|
6653
|
+
problems: [describeProviderError(err)]
|
|
6654
|
+
});
|
|
6655
|
+
continue;
|
|
6656
|
+
}
|
|
6657
|
+
if (entry.keys) {
|
|
6658
|
+
scopes.push({
|
|
6659
|
+
scope,
|
|
6660
|
+
names: entry.keys
|
|
6661
|
+
});
|
|
6662
|
+
continue;
|
|
6663
|
+
}
|
|
6664
|
+
const skip = (detail) => rows.push({
|
|
6665
|
+
id,
|
|
6666
|
+
title,
|
|
5873
6667
|
status: "skip",
|
|
5874
6668
|
detail,
|
|
5875
6669
|
problems: []
|
|
@@ -6384,6 +7178,32 @@ const DEEP_CHECKS = [
|
|
|
6384
7178
|
};
|
|
6385
7179
|
}
|
|
6386
7180
|
},
|
|
7181
|
+
{
|
|
7182
|
+
name: "dns",
|
|
7183
|
+
capability: "dns",
|
|
7184
|
+
command: doctorDnsCommand,
|
|
7185
|
+
async run(input) {
|
|
7186
|
+
const report = await runDoctorDns(input);
|
|
7187
|
+
return {
|
|
7188
|
+
status: report.status,
|
|
7189
|
+
summary: report.summary,
|
|
7190
|
+
...report.reason ? { reason: report.reason } : {}
|
|
7191
|
+
};
|
|
7192
|
+
}
|
|
7193
|
+
},
|
|
7194
|
+
{
|
|
7195
|
+
name: "repo",
|
|
7196
|
+
capability: "source",
|
|
7197
|
+
command: doctorRepoCommand,
|
|
7198
|
+
async run(input) {
|
|
7199
|
+
const report = await runDoctorRepo(input);
|
|
7200
|
+
return {
|
|
7201
|
+
status: report.status,
|
|
7202
|
+
summary: report.summary,
|
|
7203
|
+
...report.reason ? { reason: report.reason } : {}
|
|
7204
|
+
};
|
|
7205
|
+
}
|
|
7206
|
+
},
|
|
6387
7207
|
{
|
|
6388
7208
|
name: "secrets",
|
|
6389
7209
|
capability: "secrets",
|
|
@@ -8972,105 +9792,19 @@ function findGuildId(source) {
|
|
|
8972
9792
|
* each other's `guildId`. Returns a function that releases it, or undefined when another run holds it. The lock
|
|
8973
9793
|
* is a file made only if absent; one left behind by a crashed run has to be deleted by hand, and the caller says so.
|
|
8974
9794
|
*/
|
|
8975
|
-
async function lockConfig(filepath) {
|
|
8976
|
-
const path = `${filepath}.create-server.lock`;
|
|
8977
|
-
try {
|
|
8978
|
-
const handle = await open(path, "wx");
|
|
8979
|
-
await handle.writeFile(`${process.pid}\n`);
|
|
8980
|
-
await handle.close();
|
|
8981
|
-
} catch (err) {
|
|
8982
|
-
if (err.code === "EEXIST") return void 0;
|
|
8983
|
-
throw err;
|
|
8984
|
-
}
|
|
8985
|
-
return {
|
|
8986
|
-
path,
|
|
8987
|
-
release: () => unlink(path).catch(() => void 0)
|
|
8988
|
-
};
|
|
8989
|
-
}
|
|
8990
|
-
// src/commands/notifications-setup/avatar-problem.ts
|
|
8991
|
-
/** The first reason a feed's `avatar` cannot work, or undefined. `feed` names the key for the message (`monitoring`, `errors`). */
|
|
8992
|
-
function avatarProblem(channel, feed, picture) {
|
|
8993
|
-
if (typeof picture !== "object") return void 0;
|
|
8994
|
-
if (!picture.url && !picture.image) return `channel \`${channel}\`: \`feeds.${feed}.avatar\` needs a \`url\`, an \`image\`, or both`;
|
|
8995
|
-
if (picture.url && !/^https:\/\//i.test(picture.url)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.url\` must be an https:// URL`;
|
|
8996
|
-
if (picture.image && /^https?:\/\//i.test(picture.image)) return `channel \`${channel}\`: \`feeds.${feed}.avatar.image\` must be a file in the repo, not a URL`;
|
|
8997
|
-
}
|
|
8998
|
-
/** The webhook name a channel's error feed uses: its own, else the provider's name, capitalised (`Sentry`). */
|
|
8999
|
-
function errorsFeedWebhook(feed, errors) {
|
|
9000
|
-
return (typeof feed === "object" ? feed.webhook : void 0) ?? capitalised(errors.providerName);
|
|
9001
|
-
}
|
|
9002
|
-
const capitalised = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
9003
|
-
/** The Worker binding that holds the webhook URL for a source (the contract `apps/comlink` reads). */
|
|
9004
|
-
const relayWebhookBinding = (source) => `COMLINK_${source.toUpperCase()}_WEBHOOK`;
|
|
9005
|
-
/** The Worker binding that holds a source's signing secret (the contract `apps/comlink` reads). */
|
|
9006
|
-
const relaySecretBinding = (source) => `COMLINK_${source.toUpperCase()}_SECRET`;
|
|
9007
|
-
/** Whether any channel in the layout is fed by the error tracker. */
|
|
9008
|
-
function wantsRelay(layout) {
|
|
9009
|
-
return (layout.categories ?? []).some((c) => (c.channels ?? []).some((ch) => ch.feeds?.errors));
|
|
9010
|
-
}
|
|
9011
|
-
/**
|
|
9012
|
-
* The first reason the relay cannot be deployed, or undefined. One source has one webhook, so only one channel can be
|
|
9013
|
-
* fed by it; and the Worker needs somewhere to answer.
|
|
9014
|
-
*/
|
|
9015
|
-
function relayProblem(layout, errors, monitoring) {
|
|
9016
|
-
const fed = (layout.categories ?? []).flatMap((c) => c.channels ?? []).filter((ch) => ch.feeds?.errors);
|
|
9017
|
-
if (fed.length === 0) return void 0;
|
|
9018
|
-
if (!layout.relay?.host) return `channel \`${fed[0].name}\` is fed by the error tracker, which needs \`relay.host\` — where the relay Worker answers`;
|
|
9019
|
-
if (fed.length > 1) return `channels ${fed.map((c) => `\`${c.name}\``).join(" and ")} are all fed by the error tracker, but its relay posts to one channel — feed one`;
|
|
9020
|
-
const channel = fed[0];
|
|
9021
|
-
const errorsFeed = channel.feeds.errors;
|
|
9022
|
-
const picture = typeof errorsFeed === "object" ? errorsFeed.avatar : void 0;
|
|
9023
|
-
const pictureProblem = avatarProblem(channel.name, "errors", picture);
|
|
9024
|
-
if (pictureProblem) return pictureProblem;
|
|
9025
|
-
if (errors) {
|
|
9026
|
-
const feed = errorsFeedWebhook(errorsFeed, errors).toLowerCase();
|
|
9027
|
-
const own = (typeof channel.webhook === "object" ? channel.webhook.name : void 0) ?? channel.name;
|
|
9028
|
-
if (channel.webhook && feed === own.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the channel's own webhook are both named ${own} — rename one`;
|
|
9029
|
-
const monitoringFeed = channel.feeds.monitoring;
|
|
9030
|
-
if (monitoring && monitoringFeed) {
|
|
9031
|
-
const other = (typeof monitoringFeed === "object" ? monitoringFeed.webhook : void 0) ?? capitalised(monitoring.providerName);
|
|
9032
|
-
if (feed === other.toLowerCase()) return `channel \`${channel.name}\`: the relay webhook and the monitoring webhook are both named ${other} — rename one`;
|
|
9033
|
-
}
|
|
9034
|
-
}
|
|
9035
|
-
}
|
|
9036
|
-
/**
|
|
9037
|
-
* What to hand the `dns` capability as the zone: the layout's, else the host itself. The provider looks a name up from
|
|
9038
|
-
* the full name towards the apex until it finds a zone it holds, so this is right for any suffix (`example.co.uk`).
|
|
9039
|
-
*/
|
|
9040
|
-
const relayZone = (relay) => relay.zone ?? relay.host;
|
|
9041
|
-
/**
|
|
9042
|
-
* Deploy the Worker with its webhook secret and its route, then point the host at it with a proxied placeholder record
|
|
9043
|
-
* (the Worker answers before any origin is asked). The built file is read first and the DNS record comes last, so a
|
|
9044
|
-
* missing build or a failed deploy leaves the host untouched.
|
|
9045
|
-
*/
|
|
9046
|
-
async function deployRelay(input) {
|
|
9047
|
-
const { relay, workers, dns } = input;
|
|
9048
|
-
const path = join(input.repoRoot, relay.code ?? "apps/comlink/dist/worker.js");
|
|
9049
|
-
let code;
|
|
9795
|
+
async function lockConfig(filepath) {
|
|
9796
|
+
const path = `${filepath}.create-server.lock`;
|
|
9050
9797
|
try {
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9798
|
+
const handle = await open(path, "wx");
|
|
9799
|
+
await handle.writeFile(`${process.pid}\n`);
|
|
9800
|
+
await handle.close();
|
|
9801
|
+
} catch (err) {
|
|
9802
|
+
if (err.code === "EEXIST") return void 0;
|
|
9803
|
+
throw err;
|
|
9054
9804
|
}
|
|
9055
|
-
const script = relay.script ?? "comlink";
|
|
9056
|
-
await workers.deployScript(script, {
|
|
9057
|
-
code,
|
|
9058
|
-
secrets: {
|
|
9059
|
-
[relayWebhookBinding(input.source)]: input.webhook,
|
|
9060
|
-
...input.signingSecret ? { [relaySecretBinding(input.source)]: input.signingSecret } : {}
|
|
9061
|
-
},
|
|
9062
|
-
routes: [`${relay.host}/*`]
|
|
9063
|
-
});
|
|
9064
|
-
await dns.upsertRecord(relayZone(relay), {
|
|
9065
|
-
type: "AAAA",
|
|
9066
|
-
name: relay.host,
|
|
9067
|
-
content: "100::",
|
|
9068
|
-
ttl: 1,
|
|
9069
|
-
proxied: true
|
|
9070
|
-
});
|
|
9071
9805
|
return {
|
|
9072
|
-
|
|
9073
|
-
|
|
9806
|
+
path,
|
|
9807
|
+
release: () => unlink(path).catch(() => void 0)
|
|
9074
9808
|
};
|
|
9075
9809
|
}
|
|
9076
9810
|
// src/commands/notifications-setup/with-elevation.ts
|
|
@@ -12707,101 +13441,6 @@ async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
|
12707
13441
|
}
|
|
12708
13442
|
return results;
|
|
12709
13443
|
}
|
|
12710
|
-
// src/commands/setup/labels.ts
|
|
12711
|
-
const CANONICAL_LABELS = [
|
|
12712
|
-
{
|
|
12713
|
-
name: "bug",
|
|
12714
|
-
color: "d73a4a",
|
|
12715
|
-
description: "Something isn't working"
|
|
12716
|
-
},
|
|
12717
|
-
{
|
|
12718
|
-
name: "chore",
|
|
12719
|
-
color: "ededed",
|
|
12720
|
-
description: "Maintenance, no user-facing change"
|
|
12721
|
-
},
|
|
12722
|
-
{
|
|
12723
|
-
name: "ci",
|
|
12724
|
-
color: "0075ca",
|
|
12725
|
-
description: "CI/CD pipeline changes"
|
|
12726
|
-
},
|
|
12727
|
-
{
|
|
12728
|
-
name: "dependencies",
|
|
12729
|
-
color: "0366d6",
|
|
12730
|
-
description: "Dependency update"
|
|
12731
|
-
},
|
|
12732
|
-
{
|
|
12733
|
-
name: "documentation",
|
|
12734
|
-
color: "0075ca",
|
|
12735
|
-
description: "Documentation only"
|
|
12736
|
-
},
|
|
12737
|
-
{
|
|
12738
|
-
name: "duplicate",
|
|
12739
|
-
color: "cfd3d7",
|
|
12740
|
-
description: "Already reported"
|
|
12741
|
-
},
|
|
12742
|
-
{
|
|
12743
|
-
name: "enhancement",
|
|
12744
|
-
color: "a2eeef",
|
|
12745
|
-
description: "New feature or request"
|
|
12746
|
-
},
|
|
12747
|
-
{
|
|
12748
|
-
name: "good first issue",
|
|
12749
|
-
color: "7057ff",
|
|
12750
|
-
description: "Good for newcomers"
|
|
12751
|
-
},
|
|
12752
|
-
{
|
|
12753
|
-
name: "help wanted",
|
|
12754
|
-
color: "008672",
|
|
12755
|
-
description: "Extra attention needed"
|
|
12756
|
-
},
|
|
12757
|
-
{
|
|
12758
|
-
name: "invalid",
|
|
12759
|
-
color: "e4e669",
|
|
12760
|
-
description: "Doesn't seem right"
|
|
12761
|
-
},
|
|
12762
|
-
{
|
|
12763
|
-
name: "performance",
|
|
12764
|
-
color: "fbca04",
|
|
12765
|
-
description: "Performance improvement"
|
|
12766
|
-
},
|
|
12767
|
-
{
|
|
12768
|
-
name: "question",
|
|
12769
|
-
color: "d876e3",
|
|
12770
|
-
description: "Further information requested"
|
|
12771
|
-
},
|
|
12772
|
-
{
|
|
12773
|
-
name: "refactor",
|
|
12774
|
-
color: "cfd3d7",
|
|
12775
|
-
description: "Code restructuring"
|
|
12776
|
-
},
|
|
12777
|
-
{
|
|
12778
|
-
name: "released",
|
|
12779
|
-
color: "ededed",
|
|
12780
|
-
description: "Included in a release"
|
|
12781
|
-
},
|
|
12782
|
-
{
|
|
12783
|
-
name: "test",
|
|
12784
|
-
color: "bfd4f2",
|
|
12785
|
-
description: "Test-related changes"
|
|
12786
|
-
},
|
|
12787
|
-
{
|
|
12788
|
-
name: "triage",
|
|
12789
|
-
color: "e4e669",
|
|
12790
|
-
description: "Needs investigation"
|
|
12791
|
-
},
|
|
12792
|
-
{
|
|
12793
|
-
name: "wontfix",
|
|
12794
|
-
color: "ffffff",
|
|
12795
|
-
description: "Won't be addressed"
|
|
12796
|
-
}
|
|
12797
|
-
];
|
|
12798
|
-
const STALE_LABELS = [
|
|
12799
|
-
"github_actions",
|
|
12800
|
-
"javascript",
|
|
12801
|
-
"autorelease: pending",
|
|
12802
|
-
"autorelease: tagged",
|
|
12803
|
-
"released on @alpha"
|
|
12804
|
-
];
|
|
12805
13444
|
// src/commands/setup/agent-prompts-data.ts
|
|
12806
13445
|
/**
|
|
12807
13446
|
* Canonical AI engineering workflow role prompts.
|
|
@@ -13210,121 +13849,6 @@ async function installAgentPrompts({ repoRoot }) {
|
|
|
13210
13849
|
});
|
|
13211
13850
|
return `wrote ${Object.keys(AGENT_PROMPTS).length} prompt files to ${AGENTS_PROMPTS_ROOT}/`;
|
|
13212
13851
|
}
|
|
13213
|
-
// src/commands/setup/branch-protection.ts
|
|
13214
|
-
const RULESET_NAME = "holocron-default-branch";
|
|
13215
|
-
function buildClassicProtectionPayload(requiredChecks = []) {
|
|
13216
|
-
return {
|
|
13217
|
-
required_status_checks: requiredChecks.length > 0 ? {
|
|
13218
|
-
strict: false,
|
|
13219
|
-
contexts: requiredChecks
|
|
13220
|
-
} : null,
|
|
13221
|
-
enforce_admins: false,
|
|
13222
|
-
required_pull_request_reviews: {
|
|
13223
|
-
required_approving_review_count: 0,
|
|
13224
|
-
dismiss_stale_reviews: false,
|
|
13225
|
-
require_code_owner_reviews: false
|
|
13226
|
-
},
|
|
13227
|
-
restrictions: null,
|
|
13228
|
-
allow_force_pushes: false,
|
|
13229
|
-
allow_deletions: false
|
|
13230
|
-
};
|
|
13231
|
-
}
|
|
13232
|
-
function buildRulesetPayload(requiredChecks = []) {
|
|
13233
|
-
const rules = [
|
|
13234
|
-
{ type: "deletion" },
|
|
13235
|
-
{ type: "non_fast_forward" },
|
|
13236
|
-
{
|
|
13237
|
-
type: "pull_request",
|
|
13238
|
-
parameters: {
|
|
13239
|
-
required_approving_review_count: 0,
|
|
13240
|
-
dismiss_stale_reviews_on_push: false,
|
|
13241
|
-
require_code_owner_review: false,
|
|
13242
|
-
require_last_push_approval: false,
|
|
13243
|
-
required_review_thread_resolution: true,
|
|
13244
|
-
require_extra_approval_for_unattributed_changes: false
|
|
13245
|
-
}
|
|
13246
|
-
}
|
|
13247
|
-
];
|
|
13248
|
-
if (requiredChecks.length > 0) rules.push({
|
|
13249
|
-
type: "required_status_checks",
|
|
13250
|
-
parameters: {
|
|
13251
|
-
required_status_checks: requiredChecks.map((context) => ({ context })),
|
|
13252
|
-
strict_required_status_checks_policy: false
|
|
13253
|
-
}
|
|
13254
|
-
});
|
|
13255
|
-
return {
|
|
13256
|
-
name: RULESET_NAME,
|
|
13257
|
-
target: "branch",
|
|
13258
|
-
enforcement: "active",
|
|
13259
|
-
bypass_actors: [{
|
|
13260
|
-
actor_id: 4,
|
|
13261
|
-
actor_type: "RepositoryRole",
|
|
13262
|
-
bypass_mode: "always"
|
|
13263
|
-
}],
|
|
13264
|
-
conditions: { ref_name: {
|
|
13265
|
-
include: ["~DEFAULT_BRANCH"],
|
|
13266
|
-
exclude: []
|
|
13267
|
-
} },
|
|
13268
|
-
rules
|
|
13269
|
-
};
|
|
13270
|
-
}
|
|
13271
|
-
async function upsertBranchProtection(source, dryRun, requiredChecks) {
|
|
13272
|
-
const step = `upsert ruleset ${RULESET_NAME}`;
|
|
13273
|
-
if (dryRun) return {
|
|
13274
|
-
capability: "source",
|
|
13275
|
-
step,
|
|
13276
|
-
status: "dry-run"
|
|
13277
|
-
};
|
|
13278
|
-
try {
|
|
13279
|
-
const found = (await source.listRulesets()).find((r) => r.name === RULESET_NAME);
|
|
13280
|
-
if (found) {
|
|
13281
|
-
await source.updateRuleset(found.id, buildRulesetPayload(requiredChecks));
|
|
13282
|
-
return {
|
|
13283
|
-
capability: "source",
|
|
13284
|
-
step,
|
|
13285
|
-
status: "ok",
|
|
13286
|
-
message: "updated"
|
|
13287
|
-
};
|
|
13288
|
-
}
|
|
13289
|
-
await source.createRuleset(buildRulesetPayload(requiredChecks));
|
|
13290
|
-
return {
|
|
13291
|
-
capability: "source",
|
|
13292
|
-
step,
|
|
13293
|
-
status: "ok",
|
|
13294
|
-
message: "created"
|
|
13295
|
-
};
|
|
13296
|
-
} catch (err) {
|
|
13297
|
-
if (!(err instanceof ProviderApiError$1) || err.status !== 403) return {
|
|
13298
|
-
capability: "source",
|
|
13299
|
-
step,
|
|
13300
|
-
status: "fail",
|
|
13301
|
-
message: errorMessage(err)
|
|
13302
|
-
};
|
|
13303
|
-
}
|
|
13304
|
-
try {
|
|
13305
|
-
const repo = await source.getRepo();
|
|
13306
|
-
await source.protectBranch(repo.defaultBranch, buildClassicProtectionPayload(requiredChecks));
|
|
13307
|
-
return {
|
|
13308
|
-
capability: "source",
|
|
13309
|
-
step,
|
|
13310
|
-
status: "ok",
|
|
13311
|
-
message: `classic protection on ${repo.defaultBranch}`
|
|
13312
|
-
};
|
|
13313
|
-
} catch (err) {
|
|
13314
|
-
if (err instanceof ProviderApiError$1 && err.status === 403) return {
|
|
13315
|
-
capability: "source",
|
|
13316
|
-
step,
|
|
13317
|
-
status: "skip",
|
|
13318
|
-
message: "branch protection unavailable on private repos without GitHub Pro/Team"
|
|
13319
|
-
};
|
|
13320
|
-
return {
|
|
13321
|
-
capability: "source",
|
|
13322
|
-
step,
|
|
13323
|
-
status: "fail",
|
|
13324
|
-
message: errorMessage(err)
|
|
13325
|
-
};
|
|
13326
|
-
}
|
|
13327
|
-
}
|
|
13328
13852
|
// src/commands/setup/engineering.ts
|
|
13329
13853
|
async function writeIfAbsent(filePath, content) {
|
|
13330
13854
|
try {
|
|
@@ -13346,19 +13870,6 @@ async function installEngineeringStructure({ repoRoot }) {
|
|
|
13346
13870
|
for (const [path, content] of writes) if (await writeIfAbsent(path, content)) results.push(path.replace(repoRoot + "/", ""));
|
|
13347
13871
|
return results.length > 0 ? `created: ${results.join(", ")}` : "all files already exist — nothing to write";
|
|
13348
13872
|
}
|
|
13349
|
-
// src/commands/setup/repo-settings.ts
|
|
13350
|
-
const BALANCED_REPO_SETTINGS = {
|
|
13351
|
-
allow_squash_merge: true,
|
|
13352
|
-
allow_merge_commit: false,
|
|
13353
|
-
allow_rebase_merge: false,
|
|
13354
|
-
allow_auto_merge: true,
|
|
13355
|
-
allow_update_branch: true,
|
|
13356
|
-
delete_branch_on_merge: true,
|
|
13357
|
-
has_issues: true,
|
|
13358
|
-
has_discussions: true,
|
|
13359
|
-
has_projects: true,
|
|
13360
|
-
has_wiki: false
|
|
13361
|
-
};
|
|
13362
13873
|
// src/commands/setup/run-step/run-step.ts
|
|
13363
13874
|
async function runStep(capability, step, dryRun, body, opts = {}) {
|
|
13364
13875
|
const result = await execStep(capability, step, dryRun, body, opts);
|
|
@@ -13927,11 +14438,7 @@ async function runSetup(input) {
|
|
|
13927
14438
|
if (loader.has("deployment")) {
|
|
13928
14439
|
const deploy = loader.get("deployment");
|
|
13929
14440
|
print(style.step("deployment"));
|
|
13930
|
-
const
|
|
13931
|
-
const previewCfg = deployEntry?.with ? extractPreviewConfig(deployEntry.with, {
|
|
13932
|
-
org: config.org,
|
|
13933
|
-
domain: config.domain
|
|
13934
|
-
}) : null;
|
|
14441
|
+
const previewCfg = previewConfigOf(config);
|
|
13935
14442
|
const ensureCustomDomain = async (projectId, hostname) => {
|
|
13936
14443
|
if (!deploy.ensureCustomDomain) return;
|
|
13937
14444
|
const customDomainDns = { value: null };
|