@aspruyt/xfg 8.0.0 → 8.1.0

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.
Files changed (41) hide show
  1. package/dist/cli/secrets-command.js +12 -2
  2. package/dist/cli/settings-factories.d.ts +2 -1
  3. package/dist/cli/settings-factories.js +7 -1
  4. package/dist/cli/settings-report-builder.d.ts +6 -1
  5. package/dist/cli/settings-report-builder.js +7 -1
  6. package/dist/cli/settings-runner.js +24 -15
  7. package/dist/cli/types.d.ts +4 -2
  8. package/dist/config/index.d.ts +1 -1
  9. package/dist/config/merge.d.ts +9 -5
  10. package/dist/config/merge.js +148 -67
  11. package/dist/config/normalizer.js +87 -18
  12. package/dist/config/types.d.ts +28 -0
  13. package/dist/config/validator.js +17 -3
  14. package/dist/config/validators/ruleset-validator.js +6 -5
  15. package/dist/config/validators/shared.js +123 -0
  16. package/dist/output/settings-report.d.ts +6 -1
  17. package/dist/output/settings-report.js +31 -9
  18. package/dist/settings/environments/diff.d.ts +22 -0
  19. package/dist/settings/environments/diff.js +78 -0
  20. package/dist/settings/environments/formatter.d.ts +17 -0
  21. package/dist/settings/environments/formatter.js +62 -0
  22. package/dist/settings/environments/github-environments-strategy.d.ts +23 -0
  23. package/dist/settings/environments/github-environments-strategy.js +54 -0
  24. package/dist/settings/environments/index.d.ts +5 -0
  25. package/dist/settings/environments/index.js +3 -0
  26. package/dist/settings/environments/processor.d.ts +21 -0
  27. package/dist/settings/environments/processor.js +100 -0
  28. package/dist/settings/environments/types.d.ts +38 -0
  29. package/dist/settings/environments/types.js +1 -0
  30. package/dist/settings/index.d.ts +1 -0
  31. package/dist/settings/index.js +1 -0
  32. package/dist/settings/secrets/diff.d.ts +2 -0
  33. package/dist/settings/secrets/formatter.d.ts +4 -0
  34. package/dist/settings/secrets/formatter.js +17 -4
  35. package/dist/settings/secrets/index.d.ts +2 -2
  36. package/dist/settings/secrets/index.js +1 -1
  37. package/dist/settings/secrets/processor.d.ts +16 -2
  38. package/dist/settings/secrets/processor.js +132 -28
  39. package/dist/shared/sequential.d.ts +2 -0
  40. package/dist/shared/sequential.js +4 -0
  41. package/package.json +2 -2
@@ -0,0 +1,17 @@
1
+ import type { DeploymentBranchPattern } from "../../config/index.js";
2
+ import type { BranchPolicyKind, EnvironmentChange } from "./diff.js";
3
+ export interface EnvironmentsPlanEntry {
4
+ name: string;
5
+ action: "create" | "update";
6
+ /** Set on updates that change the policy kind */
7
+ currentKind?: BranchPolicyKind;
8
+ desiredKind: BranchPolicyKind;
9
+ addedPatterns: DeploymentBranchPattern[];
10
+ }
11
+ export interface EnvironmentsPlanResult {
12
+ lines: string[];
13
+ entries: EnvironmentsPlanEntry[];
14
+ }
15
+ export declare function formatPolicyLine(entry: EnvironmentsPlanEntry): string | null;
16
+ export declare function formatPatternLabel(pattern: DeploymentBranchPattern): string;
17
+ export declare function formatEnvironmentsPlan(changes: EnvironmentChange[], dryRun: boolean): EnvironmentsPlanResult;
@@ -0,0 +1,62 @@
1
+ import chalk from "chalk";
2
+ import { quoted } from "../../shared/string-utils.js";
3
+ import { countActions } from "../base-processor.js";
4
+ import { formatActionCountEntry } from "../../shared/count-format.js";
5
+ function toEntry(change) {
6
+ if (change.action === "unchanged")
7
+ return null;
8
+ const entry = {
9
+ name: change.name,
10
+ action: change.action,
11
+ desiredKind: change.desiredKind,
12
+ addedPatterns: change.missingPatterns,
13
+ };
14
+ if (change.action === "update" && change.putPolicy) {
15
+ entry.currentKind = change.currentKind;
16
+ }
17
+ return entry;
18
+ }
19
+ export function formatPolicyLine(entry) {
20
+ if (entry.action === "create") {
21
+ return `deployment branches: ${entry.desiredKind}`;
22
+ }
23
+ if (entry.currentKind !== undefined) {
24
+ return `deployment branches: ${entry.currentKind} → ${entry.desiredKind}`;
25
+ }
26
+ return null;
27
+ }
28
+ export function formatPatternLabel(pattern) {
29
+ return `${pattern.type} ${quoted(pattern.name)}`;
30
+ }
31
+ function formatEntry(entry) {
32
+ const color = entry.action === "create" ? chalk.green : chalk.yellow;
33
+ const sign = entry.action === "create" ? "+" : "~";
34
+ const lines = [color(` ${sign} environment ${quoted(entry.name)}`)];
35
+ const policy = formatPolicyLine(entry);
36
+ if (policy)
37
+ lines.push(` ${policy}`);
38
+ for (const pattern of entry.addedPatterns) {
39
+ lines.push(chalk.green(` + ${formatPatternLabel(pattern)}`));
40
+ }
41
+ return lines;
42
+ }
43
+ function actionRank(entry) {
44
+ return entry.action === "create" ? 0 : 1;
45
+ }
46
+ export function formatEnvironmentsPlan(changes, dryRun) {
47
+ const entries = changes
48
+ .map(toEntry)
49
+ .filter((e) => e !== null)
50
+ .sort((a, b) => actionRank(a) - actionRank(b));
51
+ const summary = formatActionCountEntry("environment", "environments", countActions(entries), dryRun);
52
+ if (!summary) {
53
+ return { lines: [], entries };
54
+ }
55
+ return {
56
+ lines: [
57
+ ...entries.flatMap(formatEntry),
58
+ ` ${dryRun ? "Plan" : "Applied"}: ${summary}`,
59
+ ],
60
+ entries,
61
+ };
62
+ }
@@ -0,0 +1,23 @@
1
+ import type { ICommandExecutor } from "../../shared/command-executor.js";
2
+ import { type RepoInfo } from "../../repo/index.js";
3
+ import { type GhApiOptions } from "../../shared/gh-api-utils.js";
4
+ import type { DeploymentBranchPattern } from "../../config/index.js";
5
+ import type { GitHubPublicKey, GitHubSecret } from "../secrets/types.js";
6
+ import type { GitHubDeploymentBranchPolicy, GitHubEnvironment, IEnvironmentSecretsStrategy, IEnvironmentsStrategy } from "./types.js";
7
+ interface GitHubEnvironmentsStrategyOptions {
8
+ retries?: number;
9
+ cwd: string;
10
+ }
11
+ export declare class GitHubEnvironmentsStrategy implements IEnvironmentsStrategy, IEnvironmentSecretsStrategy {
12
+ private readonly api;
13
+ constructor(executor: ICommandExecutor, options: GitHubEnvironmentsStrategyOptions);
14
+ private base;
15
+ list(repoInfo: RepoInfo, options?: GhApiOptions): Promise<GitHubEnvironment[]>;
16
+ createOrUpdate(repoInfo: RepoInfo, name: string, policy: GitHubDeploymentBranchPolicy | null, options?: GhApiOptions): Promise<void>;
17
+ listBranchPolicies(repoInfo: RepoInfo, environment: string, options?: GhApiOptions): Promise<DeploymentBranchPattern[]>;
18
+ createBranchPolicy(repoInfo: RepoInfo, environment: string, pattern: DeploymentBranchPattern, options?: GhApiOptions): Promise<void>;
19
+ listSecrets(repoInfo: RepoInfo, environment: string, options?: GhApiOptions): Promise<GitHubSecret[]>;
20
+ getSecretsPublicKey(repoInfo: RepoInfo, environment: string, options?: GhApiOptions): Promise<GitHubPublicKey>;
21
+ upsertSecret(repoInfo: RepoInfo, environment: string, name: string, encryptedValue: string, keyId: string, options?: GhApiOptions): Promise<void>;
22
+ }
23
+ export {};
@@ -0,0 +1,54 @@
1
+ import { assertGitHubRepo } from "../../repo/index.js";
2
+ import { GhApiClient } from "../../shared/gh-api-utils.js";
3
+ import { parseApiJson } from "../../shared/json-utils.js";
4
+ const LABEL = "GitHub Environments strategy";
5
+ export class GitHubEnvironmentsStrategy {
6
+ api;
7
+ constructor(executor, options) {
8
+ this.api = new GhApiClient(executor, options.retries ?? 3, options.cwd);
9
+ }
10
+ base(repoInfo, environment) {
11
+ assertGitHubRepo(repoInfo, LABEL);
12
+ const root = `/repos/${repoInfo.owner}/${repoInfo.repo}/environments`;
13
+ return environment === undefined
14
+ ? root
15
+ : `${root}/${encodeURIComponent(environment)}`;
16
+ }
17
+ async list(repoInfo, options) {
18
+ const result = await this.api.call("GET", `${this.base(repoInfo)}?per_page=100`, { options, paginate: true });
19
+ const response = parseApiJson(result, "environments response");
20
+ return (response.environments ?? []).map((env) => ({
21
+ name: env.name,
22
+ deployment_branch_policy: env.deployment_branch_policy ?? null,
23
+ }));
24
+ }
25
+ async createOrUpdate(repoInfo, name, policy, options) {
26
+ await this.api.call("PUT", this.base(repoInfo, name), {
27
+ payload: { deployment_branch_policy: policy },
28
+ options,
29
+ });
30
+ }
31
+ async listBranchPolicies(repoInfo, environment, options) {
32
+ const result = await this.api.call("GET", `${this.base(repoInfo, environment)}/deployment-branch-policies?per_page=100`, { options, paginate: true });
33
+ const response = parseApiJson(result, "deployment branch policies response");
34
+ return (response.branch_policies ?? []).map((p) => ({
35
+ type: p.type ?? "branch",
36
+ name: p.name,
37
+ }));
38
+ }
39
+ async createBranchPolicy(repoInfo, environment, pattern, options) {
40
+ await this.api.call("POST", `${this.base(repoInfo, environment)}/deployment-branch-policies`, { payload: { name: pattern.name, type: pattern.type }, options });
41
+ }
42
+ async listSecrets(repoInfo, environment, options) {
43
+ const result = await this.api.call("GET", `${this.base(repoInfo, environment)}/secrets?per_page=100`, { options, paginate: true });
44
+ const response = parseApiJson(result, "environment secrets response");
45
+ return response.secrets ?? [];
46
+ }
47
+ async getSecretsPublicKey(repoInfo, environment, options) {
48
+ const result = await this.api.call("GET", `${this.base(repoInfo, environment)}/secrets/public-key`, { options });
49
+ return parseApiJson(result, "environment public key response");
50
+ }
51
+ async upsertSecret(repoInfo, environment, name, encryptedValue, keyId, options) {
52
+ await this.api.call("PUT", `${this.base(repoInfo, environment)}/secrets/${encodeURIComponent(name)}`, { payload: { encrypted_value: encryptedValue, key_id: keyId }, options });
53
+ }
54
+ }
@@ -0,0 +1,5 @@
1
+ export { type BranchPolicyKind, type EnvironmentChange, type EnvironmentAction, } from "./diff.js";
2
+ export { type EnvironmentsPlanEntry, type EnvironmentsPlanResult, formatPolicyLine, formatPatternLabel, } from "./formatter.js";
3
+ export { EnvironmentsProcessor, type IEnvironmentsProcessor, type EnvironmentsProcessorResult, } from "./processor.js";
4
+ export { GitHubEnvironmentsStrategy } from "./github-environments-strategy.js";
5
+ export type { IEnvironmentsStrategy, IEnvironmentSecretsStrategy, GitHubEnvironment, GitHubDeploymentBranchPolicy, } from "./types.js";
@@ -0,0 +1,3 @@
1
+ export { formatPolicyLine, formatPatternLabel, } from "./formatter.js";
2
+ export { EnvironmentsProcessor, } from "./processor.js";
3
+ export { GitHubEnvironmentsStrategy } from "./github-environments-strategy.js";
@@ -0,0 +1,21 @@
1
+ import type { RepoConfig } from "../../config/index.js";
2
+ import type { IRepoMetadataProvider, RepoInfo } from "../../repo/index.js";
3
+ import { type EnvironmentsPlanResult } from "./formatter.js";
4
+ import type { IEnvironmentsStrategy } from "./types.js";
5
+ import { type BaseProcessorOptions, type BaseProcessorResult, type ISettingsProcessor, type ChangeCounts } from "../base-processor.js";
6
+ export type IEnvironmentsProcessor = ISettingsProcessor<BaseProcessorOptions, EnvironmentsProcessorResult>;
7
+ export interface EnvironmentsProcessorResult extends BaseProcessorResult {
8
+ changes?: ChangeCounts;
9
+ planOutput?: EnvironmentsPlanResult;
10
+ warnings?: string[];
11
+ }
12
+ export declare class EnvironmentsProcessor implements IEnvironmentsProcessor {
13
+ private readonly strategy;
14
+ private readonly metadataProvider;
15
+ constructor(strategy: IEnvironmentsStrategy, metadataProvider: IRepoMetadataProvider);
16
+ process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: BaseProcessorOptions): Promise<EnvironmentsProcessorResult>;
17
+ private readPatterns;
18
+ private applySettings;
19
+ private applyChange;
20
+ private skipIfNotPublic;
21
+ }
@@ -0,0 +1,100 @@
1
+ import { runSequentially } from "../../shared/sequential.js";
2
+ import { quoted } from "../../shared/string-utils.js";
3
+ import { toErrorMessage } from "../../shared/type-guards.js";
4
+ import { diffEnvironments, needsPatternLookup, toGitHubPolicy, } from "./diff.js";
5
+ import { formatEnvironmentsPlan, formatPatternLabel, } from "./formatter.js";
6
+ import { withGitHubGuards, countActions, buildDryRunResult, buildApplyResult, } from "../base-processor.js";
7
+ function unmanagedWarnings(repoName, changes) {
8
+ return changes.flatMap((c) => c.unmanagedPatterns.map((p) => `${repoName}: environment ${quoted(c.name)} has ${formatPatternLabel(p)} not in config - left in place`));
9
+ }
10
+ // GitHub's plan-gate replies: 422 for environment protection rules, 403 for other plan-gated features.
11
+ function isPaidPlanError(error) {
12
+ const message = toErrorMessage(error);
13
+ return ((message.includes("HTTP 422") && /billing plan/i.test(message)) ||
14
+ (message.includes("HTTP 403") &&
15
+ message.includes("Upgrade to GitHub Pro or make this repository public")));
16
+ }
17
+ function withWarnings(extra, warnings) {
18
+ return warnings.length > 0 ? { ...extra, warnings } : extra;
19
+ }
20
+ export class EnvironmentsProcessor {
21
+ strategy;
22
+ metadataProvider;
23
+ constructor(strategy, metadataProvider) {
24
+ this.strategy = strategy;
25
+ this.metadataProvider = metadataProvider;
26
+ }
27
+ async process(repoConfig, repoInfo, options) {
28
+ return withGitHubGuards(repoConfig, repoInfo, options, {
29
+ hasDesiredSettings: (rc) => Object.keys(rc.settings?.environments ?? {}).length > 0,
30
+ emptySettingsMessage: "No environments configured",
31
+ applySettings: (githubRepo, rc, opts, token, repoName) => this.applySettings(githubRepo, rc, opts, token, repoName),
32
+ });
33
+ }
34
+ async readPatterns(githubRepo, names, strategyOptions) {
35
+ const patterns = new Map();
36
+ // Serial: GitHub asks for serial requests to avoid secondary rate limits
37
+ await runSequentially(names, async (name) => {
38
+ patterns.set(name.toLowerCase(), await this.strategy.listBranchPolicies(githubRepo, name, strategyOptions));
39
+ });
40
+ return patterns;
41
+ }
42
+ async applySettings(githubRepo, repoConfig, options, effectiveToken, repoName) {
43
+ const desired = repoConfig.settings?.environments ?? {};
44
+ const strategyOptions = { token: effectiveToken, host: githubRepo.host };
45
+ const current = await this.strategy.list(githubRepo, strategyOptions);
46
+ const patterns = await this.readPatterns(githubRepo, needsPatternLookup(desired, current), strategyOptions);
47
+ const changes = diffEnvironments(desired, current, patterns);
48
+ const changeCounts = countActions(changes);
49
+ const warnings = unmanagedWarnings(repoName, changes);
50
+ if (options.dryRun) {
51
+ return buildDryRunResult(repoName, changeCounts, withWarnings({ planOutput: formatEnvironmentsPlan(changes, true) }, warnings));
52
+ }
53
+ const progress = { writes: 0 };
54
+ let appliedCount = 0;
55
+ try {
56
+ // Serial: GitHub asks for serial requests to avoid secondary rate limits
57
+ await runSequentially(changes.filter((c) => c.action !== "unchanged"), async (change) => {
58
+ await this.applyChange(githubRepo, change, strategyOptions, progress);
59
+ appliedCount++;
60
+ });
61
+ }
62
+ catch (error) {
63
+ if (progress.writes > 0 || !isPaidPlanError(error))
64
+ throw error;
65
+ return this.skipIfNotPublic(githubRepo, strategyOptions, repoName, error);
66
+ }
67
+ return buildApplyResult(repoName, changeCounts, appliedCount, withWarnings({ planOutput: formatEnvironmentsPlan(changes, false) }, warnings));
68
+ }
69
+ async applyChange(githubRepo, change, strategyOptions, progress) {
70
+ if (change.putPolicy) {
71
+ await this.strategy.createOrUpdate(githubRepo, change.name, toGitHubPolicy(change.desiredKind), strategyOptions);
72
+ progress.writes++;
73
+ }
74
+ let missing = change.missingPatterns;
75
+ if (!change.patternsKnown) {
76
+ const existing = await this.strategy.listBranchPolicies(githubRepo, change.name, strategyOptions);
77
+ missing = missing.filter((p) => !existing.some((e) => e.type === p.type && e.name === p.name));
78
+ }
79
+ // Serial: GitHub asks for serial requests to avoid secondary rate limits
80
+ await runSequentially(missing, async (pattern) => {
81
+ await this.strategy.createBranchPolicy(githubRepo, change.name, pattern, strategyOptions);
82
+ progress.writes++;
83
+ });
84
+ }
85
+ // GitHub can't report the plan up front: listing a free private repo's environments still succeeds.
86
+ async skipIfNotPublic(githubRepo, strategyOptions, repoName, error) {
87
+ const metadata = await this.metadataProvider.getMetadata(githubRepo, strategyOptions);
88
+ if (metadata.visibility === "public")
89
+ throw error;
90
+ return {
91
+ success: true,
92
+ repoName,
93
+ message: "Skipped: environments need a paid plan on private repos",
94
+ skipped: true,
95
+ warnings: [
96
+ `${repoName}: environments on private repos need a paid GitHub plan (Pro, Team or Enterprise) - skipped (${toErrorMessage(error)})`,
97
+ ],
98
+ };
99
+ }
100
+ }
@@ -0,0 +1,38 @@
1
+ import type { RepoInfo } from "../../repo/index.js";
2
+ import type { GhApiOptions } from "../../shared/gh-api-utils.js";
3
+ import type { DeploymentBranchPattern } from "../../config/index.js";
4
+ import type { GitHubPublicKey, GitHubSecret } from "../secrets/types.js";
5
+ export interface GitHubDeploymentBranchPolicy {
6
+ protected_branches: boolean;
7
+ custom_branch_policies: boolean;
8
+ }
9
+ export interface GitHubEnvironment {
10
+ name: string;
11
+ /** null: any branch can deploy */
12
+ deployment_branch_policy: GitHubDeploymentBranchPolicy | null;
13
+ }
14
+ export interface GitHubEnvironmentsListResponse {
15
+ total_count: number;
16
+ environments?: GitHubEnvironment[];
17
+ }
18
+ export interface GitHubBranchPolicy {
19
+ id: number;
20
+ name: string;
21
+ type?: "branch" | "tag";
22
+ }
23
+ export interface GitHubBranchPoliciesResponse {
24
+ total_count: number;
25
+ branch_policies?: GitHubBranchPolicy[];
26
+ }
27
+ export interface IEnvironmentsStrategy {
28
+ list(repoInfo: RepoInfo, options?: GhApiOptions): Promise<GitHubEnvironment[]>;
29
+ createOrUpdate(repoInfo: RepoInfo, name: string, policy: GitHubDeploymentBranchPolicy | null, options?: GhApiOptions): Promise<void>;
30
+ listBranchPolicies(repoInfo: RepoInfo, environment: string, options?: GhApiOptions): Promise<DeploymentBranchPattern[]>;
31
+ createBranchPolicy(repoInfo: RepoInfo, environment: string, pattern: DeploymentBranchPattern, options?: GhApiOptions): Promise<void>;
32
+ }
33
+ export interface IEnvironmentSecretsStrategy {
34
+ list(repoInfo: RepoInfo, options?: GhApiOptions): Promise<GitHubEnvironment[]>;
35
+ listSecrets(repoInfo: RepoInfo, environment: string, options?: GhApiOptions): Promise<GitHubSecret[]>;
36
+ getSecretsPublicKey(repoInfo: RepoInfo, environment: string, options?: GhApiOptions): Promise<GitHubPublicKey>;
37
+ upsertSecret(repoInfo: RepoInfo, environment: string, name: string, encryptedValue: string, keyId: string, options?: GhApiOptions): Promise<void>;
38
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -5,4 +5,5 @@ export { type LabelsPlanEntry, LabelsProcessor, type ILabelsProcessor, GitHubLab
5
5
  export { type CodeScanningPlanEntry, CodeScanningProcessor, type ICodeScanningProcessor, GitHubCodeScanningStrategy, } from "./code-scanning/index.js";
6
6
  export { type VariablesPlanEntry, VariablesProcessor, type IVariablesProcessor, GitHubVariablesStrategy, } from "./variables/index.js";
7
7
  export { type CollaboratorsPlanEntry, CollaboratorsProcessor, type ICollaboratorsProcessor, GitHubCollaboratorsStrategy, } from "./collaborators/index.js";
8
+ export { type EnvironmentsPlanEntry, type EnvironmentsProcessorResult, EnvironmentsProcessor, type IEnvironmentsProcessor, type IEnvironmentSecretsStrategy, GitHubEnvironmentsStrategy, } from "./environments/index.js";
8
9
  export { SecretsProcessor, type SecretsPlanEntry, type ISecretsProcessor, type SecretsProcessorOptions, type SecretsProcessorResult, GitHubSecretsStrategy, SodiumEncryptor, type ISecretEncryptor, } from "./secrets/index.js";
@@ -5,5 +5,6 @@ export { LabelsProcessor, GitHubLabelsStrategy, } from "./labels/index.js";
5
5
  export { CodeScanningProcessor, GitHubCodeScanningStrategy, } from "./code-scanning/index.js";
6
6
  export { VariablesProcessor, GitHubVariablesStrategy, } from "./variables/index.js";
7
7
  export { CollaboratorsProcessor, GitHubCollaboratorsStrategy, } from "./collaborators/index.js";
8
+ export { EnvironmentsProcessor, GitHubEnvironmentsStrategy, } from "./environments/index.js";
8
9
  // Secrets — not wired into `xfg sync`; driven by `xfg secrets sync` only.
9
10
  export { SecretsProcessor, GitHubSecretsStrategy, SodiumEncryptor, } from "./secrets/index.js";
@@ -4,6 +4,8 @@ export type SecretAction = SettingsAction;
4
4
  export interface SecretChange {
5
5
  action: SecretAction;
6
6
  name: string;
7
+ /** Set for environment secrets */
8
+ environment?: string;
7
9
  }
8
10
  /**
9
11
  * Diffs remote secrets against the desired name set.
@@ -3,9 +3,13 @@ import { type ActiveAction } from "../base-processor.js";
3
3
  export interface SecretsPlanEntry {
4
4
  name: string;
5
5
  action: ActiveAction;
6
+ /** Set for environment secrets */
7
+ environment?: string;
6
8
  }
7
9
  export interface SecretsPlanResult {
8
10
  lines: string[];
9
11
  entries: SecretsPlanEntry[];
10
12
  }
13
+ /** `secret "X"` plus its notes, e.g. `secret "X" (environment "release", update, value write-only)`. */
14
+ export declare function formatSecretLabel(entry: SecretsPlanEntry): string;
11
15
  export declare function formatSecretsPlan(changes: SecretChange[], dryRun: boolean): SecretsPlanResult;
@@ -7,21 +7,34 @@ const ACTION_ORDER = {
7
7
  update: 1,
8
8
  delete: 2,
9
9
  };
10
+ /** `secret "X"` plus its notes, e.g. `secret "X" (environment "release", update, value write-only)`. */
11
+ export function formatSecretLabel(entry) {
12
+ const notes = [];
13
+ if (entry.environment !== undefined) {
14
+ notes.push(`environment ${quoted(entry.environment)}`);
15
+ }
16
+ if (entry.action === "update")
17
+ notes.push("update", "value write-only");
18
+ const suffix = notes.length > 0 ? ` (${notes.join(", ")})` : "";
19
+ return `secret ${quoted(entry.name)}${suffix}`;
20
+ }
10
21
  // Names only: this formatter must never receive or print a secret value.
11
22
  function formatEntry(entry) {
12
23
  switch (entry.action) {
13
24
  case "create":
14
- return chalk.green(` + secret ${quoted(entry.name)}`);
25
+ return chalk.green(` + ${formatSecretLabel(entry)}`);
15
26
  case "update":
16
- return chalk.yellow(` ~ secret ${quoted(entry.name)} (update, value write-only)`);
27
+ return chalk.yellow(` ~ ${formatSecretLabel(entry)}`);
17
28
  case "delete":
18
- return chalk.red(` - secret ${quoted(entry.name)}`);
29
+ return chalk.red(` - ${formatSecretLabel(entry)}`);
19
30
  }
20
31
  }
21
32
  export function formatSecretsPlan(changes, dryRun) {
22
33
  const entries = changes
23
34
  .filter(isActiveAction)
24
- .map((c) => ({ name: c.name, action: c.action }))
35
+ .map((c) => c.environment === undefined
36
+ ? { name: c.name, action: c.action }
37
+ : { name: c.name, action: c.action, environment: c.environment })
25
38
  .sort((a, b) => ACTION_ORDER[a.action] - ACTION_ORDER[b.action]);
26
39
  const summary = formatActionCountEntry("secret", "secrets", countActions(entries), dryRun);
27
40
  if (!summary) {
@@ -1,6 +1,6 @@
1
1
  export { SecretsProcessor } from "./processor.js";
2
- export type { ISecretsProcessor, SecretsProcessorOptions, SecretsProcessorResult, } from "./processor.js";
3
- export { formatSecretsPlan, type SecretsPlanEntry, type SecretsPlanResult, } from "./formatter.js";
2
+ export type { EnvironmentSecretsDependencies, ISecretsProcessor, SecretsProcessorOptions, SecretsProcessorResult, } from "./processor.js";
3
+ export { formatSecretsPlan, formatSecretLabel, type SecretsPlanEntry, type SecretsPlanResult, } from "./formatter.js";
4
4
  export { diffSecrets, type SecretAction, type SecretChange } from "./diff.js";
5
5
  export { GitHubSecretsStrategy } from "./github-secrets-strategy.js";
6
6
  export { SodiumEncryptor, type ISecretEncryptor } from "./encryption.js";
@@ -1,5 +1,5 @@
1
1
  export { SecretsProcessor } from "./processor.js";
2
- export { formatSecretsPlan, } from "./formatter.js";
2
+ export { formatSecretsPlan, formatSecretLabel, } from "./formatter.js";
3
3
  export { diffSecrets } from "./diff.js";
4
4
  export { GitHubSecretsStrategy } from "./github-secrets-strategy.js";
5
5
  export { SodiumEncryptor } from "./encryption.js";
@@ -1,6 +1,7 @@
1
- import type { RepoInfo } from "../../repo/index.js";
1
+ import type { IRepoMetadataProvider, RepoInfo } from "../../repo/index.js";
2
2
  import type { RepoConfig } from "../../config/index.js";
3
3
  import type { ISecretsStrategy } from "./types.js";
4
+ import type { IEnvironmentSecretsStrategy } from "../environments/types.js";
4
5
  import type { ISecretEncryptor } from "./encryption.js";
5
6
  import type { IEnvResolver } from "../../shared/env-resolver.js";
6
7
  import { type IGitHubTokenProvider } from "../../shared/gh-token-utils.js";
@@ -15,13 +16,26 @@ export interface SecretsProcessorResult extends BaseProcessorResult {
15
16
  planOutput?: SecretsPlanResult;
16
17
  /** Set when the skip is "nothing configured here" rather than "not a GitHub repo". */
17
18
  noSecretsConfigured?: boolean;
19
+ warnings?: string[];
20
+ }
21
+ export interface EnvironmentSecretsDependencies {
22
+ strategy: IEnvironmentSecretsStrategy;
23
+ metadataProvider: IRepoMetadataProvider;
18
24
  }
19
25
  export declare class SecretsProcessor implements ISecretsProcessor {
20
26
  private readonly strategy;
21
27
  private readonly encryptor;
22
28
  private readonly envResolver;
23
29
  private readonly tokenProvider?;
24
- constructor(strategy: ISecretsStrategy, encryptor: ISecretEncryptor, envResolver: IEnvResolver, tokenProvider?: IGitHubTokenProvider | undefined);
30
+ private readonly environments?;
31
+ constructor(strategy: ISecretsStrategy, encryptor: ISecretEncryptor, envResolver: IEnvResolver, tokenProvider?: IGitHubTokenProvider | undefined, environments?: EnvironmentSecretsDependencies | undefined);
32
+ private hasDesiredSecrets;
25
33
  process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: SecretsProcessorOptions): Promise<SecretsProcessorResult>;
26
34
  private applySettings;
35
+ private writeChange;
36
+ /** On a public repo a missing environment is an error; elsewhere it may be the plan, so warn and skip. */
37
+ private gateMissingEnvironments;
38
+ private resolve;
39
+ private readEnvironments;
40
+ private diffEnvironmentSecrets;
27
41
  }