@aspruyt/xfg 7.1.0 → 7.2.1
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/secrets-command.d.ts +3 -1
- package/dist/cli/secrets-command.js +66 -15
- package/dist/cli/settings-report-builder.d.ts +6 -5
- package/dist/cli/settings-report-builder.js +11 -0
- package/dist/cli/sync-command.js +2 -7
- package/dist/cli/unified-summary.js +21 -97
- package/dist/output/index.d.ts +2 -1
- package/dist/output/index.js +2 -1
- package/dist/output/lifecycle-report.d.ts +0 -3
- package/dist/output/lifecycle-report.js +1 -11
- package/dist/output/settings-report.d.ts +9 -13
- package/dist/output/settings-report.js +41 -72
- package/dist/output/sync-report.js +2 -11
- package/dist/settings/index.d.ts +1 -1
- package/dist/settings/index.js +0 -6
- package/dist/settings/secrets/formatter.d.ts +11 -0
- package/dist/settings/secrets/formatter.js +36 -0
- package/dist/settings/secrets/index.d.ts +1 -0
- package/dist/settings/secrets/index.js +1 -0
- package/dist/settings/secrets/processor.d.ts +5 -1
- package/dist/settings/secrets/processor.js +45 -18
- package/dist/shared/count-format.d.ts +10 -0
- package/dist/shared/count-format.js +17 -0
- package/dist/shared/gh-token-utils.d.ts +18 -6
- package/dist/shared/gh-token-utils.js +23 -1
- package/dist/sync/auth-options-builder.js +2 -2
- package/dist/vcs/commit-strategy-selector.d.ts +1 -0
- package/dist/vcs/commit-strategy-selector.js +5 -0
- package/dist/vcs/github-app-token-manager.js +32 -20
- package/dist/vcs/index.d.ts +1 -1
- package/dist/vcs/index.js +1 -1
- package/package.json +3 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type IGitHubTokenProvider, type ITokenManager } from "../shared/gh-token-utils.js";
|
|
1
2
|
import type { SecretsProcessorResult } from "../settings/secrets/index.js";
|
|
2
3
|
import type { RepoConfig } from "../config/index.js";
|
|
3
4
|
import type { RepoInfo } from "../repo/index.js";
|
|
@@ -9,7 +10,8 @@ export interface ISecretsProcessorAdapter {
|
|
|
9
10
|
}): Promise<SecretsProcessorResult>;
|
|
10
11
|
}
|
|
11
12
|
export interface SecretsSyncDependencies {
|
|
12
|
-
processorFactory?: (cwd: string, retries: number) => ISecretsProcessorAdapter;
|
|
13
|
+
processorFactory?: (cwd: string, retries: number, tokenProvider: IGitHubTokenProvider) => ISecretsProcessorAdapter;
|
|
14
|
+
tokenManager?: ITokenManager | null;
|
|
13
15
|
}
|
|
14
16
|
export interface SecretsSyncOptions {
|
|
15
17
|
config: string;
|
|
@@ -3,10 +3,14 @@ import { loadRawConfig, normalizeConfig, validateSecretsConfig, validateNormaliz
|
|
|
3
3
|
import { SecretsProcessor, GitHubSecretsStrategy, SodiumEncryptor, } from "../settings/secrets/index.js";
|
|
4
4
|
import { EnvResolver } from "../shared/env-resolver.js";
|
|
5
5
|
import { ProcessExecutor } from "../shared/command-executor.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createTokenManagerFromEnv } from "../vcs/index.js";
|
|
7
|
+
import { GitHubTokenProvider, } from "../shared/gh-token-utils.js";
|
|
8
|
+
import { parseGitUrl, getRepoDisplayName } from "../repo/index.js";
|
|
7
9
|
import { Logger } from "../shared/logger.js";
|
|
8
10
|
import { toErrorMessage } from "../shared/type-guards.js";
|
|
9
|
-
|
|
11
|
+
import { buildSettingsReport, } from "./settings-report-builder.js";
|
|
12
|
+
import { writeUnifiedSummary } from "./unified-summary.js";
|
|
13
|
+
function createDefaultProcessor(cwd, retries, tokenProvider) {
|
|
10
14
|
const executor = new ProcessExecutor(process.env);
|
|
11
15
|
const encryptor = new SodiumEncryptor();
|
|
12
16
|
const envResolver = new EnvResolver(process.env);
|
|
@@ -14,7 +18,21 @@ function createDefaultProcessor(cwd, retries) {
|
|
|
14
18
|
cwd,
|
|
15
19
|
retries,
|
|
16
20
|
});
|
|
17
|
-
return new SecretsProcessor(strategy, encryptor, envResolver);
|
|
21
|
+
return new SecretsProcessor(strategy, encryptor, envResolver, tokenProvider);
|
|
22
|
+
}
|
|
23
|
+
function hostQualifiedName(repoInfo) {
|
|
24
|
+
const name = getRepoDisplayName(repoInfo);
|
|
25
|
+
return "host" in repoInfo ? `${repoInfo.host}/${name}` : name;
|
|
26
|
+
}
|
|
27
|
+
// owner/repo alone is ambiguous when the same path exists on several hosts;
|
|
28
|
+
// GitHub treats owner/repo case-insensitively, so compare lowercased.
|
|
29
|
+
function repoLabels(repos, parsed) {
|
|
30
|
+
const names = parsed.map((p, i) => "repoInfo" in p ? getRepoDisplayName(p.repoInfo) : repos[i].git);
|
|
31
|
+
const keys = names.map((n) => n.toLowerCase());
|
|
32
|
+
return parsed.map((p, i) => {
|
|
33
|
+
const shared = keys.filter((k) => k === keys[i]).length > 1;
|
|
34
|
+
return shared && "repoInfo" in p ? hostQualifiedName(p.repoInfo) : names[i];
|
|
35
|
+
});
|
|
18
36
|
}
|
|
19
37
|
export async function runSecretsSync(options, deps = {}) {
|
|
20
38
|
const logger = new Logger(!!(process.env.DEBUG || process.env.XFG_DEBUG));
|
|
@@ -26,22 +44,39 @@ export async function runSecretsSync(options, deps = {}) {
|
|
|
26
44
|
validateSecretsConfig(rawConfig);
|
|
27
45
|
const config = normalizeConfig(rawConfig, process.env);
|
|
28
46
|
validateNormalizedConfig(config);
|
|
47
|
+
const tokenManager = deps.tokenManager !== undefined
|
|
48
|
+
? deps.tokenManager
|
|
49
|
+
: createTokenManagerFromEnv(process.env);
|
|
50
|
+
const tokenProvider = new GitHubTokenProvider(tokenManager, process.env.GH_TOKEN || process.env.GITHUB_TOKEN, logger);
|
|
29
51
|
const processorFactory = deps.processorFactory ?? createDefaultProcessor;
|
|
30
|
-
const processor = processorFactory(cwd, retries ?? 3);
|
|
31
|
-
const token = process.env.GH_TOKEN || process.env.GITHUB_TOKEN;
|
|
52
|
+
const processor = processorFactory(cwd, retries ?? 3, tokenProvider);
|
|
32
53
|
let hasErrors = false;
|
|
33
54
|
let anySecretsConfigured = false;
|
|
55
|
+
const reportResults = [];
|
|
34
56
|
logger.setTotal(config.repos.length);
|
|
57
|
+
const parsed = config.repos.map((repoConfig) => {
|
|
58
|
+
try {
|
|
59
|
+
return {
|
|
60
|
+
repoInfo: parseGitUrl(repoConfig.git, {
|
|
61
|
+
githubHosts: config.githubHosts,
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return { error };
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const labels = repoLabels(config.repos, parsed);
|
|
35
70
|
for (let i = 0; i < config.repos.length; i++) {
|
|
36
71
|
const repoConfig = config.repos[i];
|
|
37
|
-
const
|
|
72
|
+
const displayName = labels[i];
|
|
73
|
+
const parsedRepo = parsed[i];
|
|
38
74
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
75
|
+
if ("error" in parsedRepo)
|
|
76
|
+
throw parsedRepo.error;
|
|
77
|
+
const { repoInfo } = parsedRepo;
|
|
42
78
|
const result = await processor.process(repoConfig, repoInfo, {
|
|
43
79
|
dryRun,
|
|
44
|
-
token,
|
|
45
80
|
noDelete,
|
|
46
81
|
});
|
|
47
82
|
if (result.noSecretsConfigured) {
|
|
@@ -51,25 +86,41 @@ export async function runSecretsSync(options, deps = {}) {
|
|
|
51
86
|
}
|
|
52
87
|
anySecretsConfigured = true;
|
|
53
88
|
if (result.skipped) {
|
|
54
|
-
logger.skip(i + 1,
|
|
89
|
+
logger.skip(i + 1, displayName, result.message);
|
|
90
|
+
continue;
|
|
55
91
|
}
|
|
56
|
-
|
|
57
|
-
logger.success(i + 1,
|
|
92
|
+
if (result.success) {
|
|
93
|
+
logger.success(i + 1, displayName, `Secrets: ${result.message}`);
|
|
58
94
|
}
|
|
59
95
|
else {
|
|
60
|
-
logger.error(i + 1,
|
|
96
|
+
logger.error(i + 1, displayName, `Secrets: ${result.message}`);
|
|
61
97
|
hasErrors = true;
|
|
62
98
|
}
|
|
99
|
+
for (const line of result.planOutput?.lines ?? []) {
|
|
100
|
+
logger.info(line);
|
|
101
|
+
}
|
|
102
|
+
reportResults.push({
|
|
103
|
+
repoName: displayName,
|
|
104
|
+
secretsResult: result,
|
|
105
|
+
...(result.success ? {} : { error: result.message }),
|
|
106
|
+
});
|
|
63
107
|
}
|
|
64
108
|
catch (error) {
|
|
65
109
|
anySecretsConfigured = true;
|
|
66
|
-
|
|
110
|
+
const message = toErrorMessage(error);
|
|
111
|
+
logger.error(i + 1, displayName, `Secrets: ${message}`);
|
|
112
|
+
reportResults.push({ repoName: displayName, error: message });
|
|
67
113
|
hasErrors = true;
|
|
68
114
|
}
|
|
69
115
|
}
|
|
70
116
|
if (!anySecretsConfigured) {
|
|
71
117
|
logger.info("No secrets configured. Nothing to do.");
|
|
72
118
|
}
|
|
119
|
+
writeUnifiedSummary({
|
|
120
|
+
settings: buildSettingsReport(reportResults),
|
|
121
|
+
dryRun: dryRun ?? false,
|
|
122
|
+
summaryPath: process.env.GITHUB_STEP_SUMMARY,
|
|
123
|
+
});
|
|
73
124
|
if (hasErrors) {
|
|
74
125
|
throw new Error("One or more repositories failed secrets sync.");
|
|
75
126
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import type { SettingsReport } from "../output/index.js";
|
|
2
|
-
import { type RepoSettingsPlanEntry, type RulesetPlanEntry, type LabelsPlanEntry, type CodeScanningPlanEntry, type VariablesPlanEntry } from "../settings/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Result from processing a repository's settings and rulesets.
|
|
5
|
-
* Used to collect results during settings command execution.
|
|
6
|
-
*/
|
|
2
|
+
import { type RepoSettingsPlanEntry, type RulesetPlanEntry, type LabelsPlanEntry, type CodeScanningPlanEntry, type VariablesPlanEntry, type SecretsPlanEntry } from "../settings/index.js";
|
|
7
3
|
export interface ProcessorResults {
|
|
8
4
|
repoName: string;
|
|
9
5
|
settingsResult?: {
|
|
@@ -31,6 +27,11 @@ export interface ProcessorResults {
|
|
|
31
27
|
entries?: VariablesPlanEntry[];
|
|
32
28
|
};
|
|
33
29
|
};
|
|
30
|
+
secretsResult?: {
|
|
31
|
+
planOutput?: {
|
|
32
|
+
entries?: SecretsPlanEntry[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
34
35
|
error?: string;
|
|
35
36
|
}
|
|
36
37
|
export declare function buildSettingsReport(results: ProcessorResults[]): SettingsReport;
|
|
@@ -6,6 +6,7 @@ export function buildSettingsReport(results) {
|
|
|
6
6
|
rulesets: { create: 0, update: 0, delete: 0 },
|
|
7
7
|
labels: { create: 0, update: 0, delete: 0 },
|
|
8
8
|
variables: { create: 0, update: 0, delete: 0 },
|
|
9
|
+
secrets: { create: 0, update: 0, delete: 0 },
|
|
9
10
|
};
|
|
10
11
|
for (const result of results) {
|
|
11
12
|
const repoChanges = {
|
|
@@ -14,6 +15,7 @@ export function buildSettingsReport(results) {
|
|
|
14
15
|
rulesets: [],
|
|
15
16
|
labels: [],
|
|
16
17
|
variables: [],
|
|
18
|
+
secrets: [],
|
|
17
19
|
};
|
|
18
20
|
if (result.settingsResult?.planOutput?.entries) {
|
|
19
21
|
for (const entry of result.settingsResult.planOutput.entries) {
|
|
@@ -93,6 +95,15 @@ export function buildSettingsReport(results) {
|
|
|
93
95
|
totals.variables.update += counts.update;
|
|
94
96
|
totals.variables.delete += counts.delete;
|
|
95
97
|
}
|
|
98
|
+
if (result.secretsResult?.planOutput?.entries) {
|
|
99
|
+
for (const entry of result.secretsResult.planOutput.entries) {
|
|
100
|
+
repoChanges.secrets.push({ name: entry.name, action: entry.action });
|
|
101
|
+
}
|
|
102
|
+
const counts = countActions(repoChanges.secrets);
|
|
103
|
+
totals.secrets.create += counts.create;
|
|
104
|
+
totals.secrets.update += counts.update;
|
|
105
|
+
totals.secrets.delete += counts.delete;
|
|
106
|
+
}
|
|
96
107
|
if (result.error) {
|
|
97
108
|
repoChanges.error = result.error;
|
|
98
109
|
}
|
package/dist/cli/sync-command.js
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { loadRawConfig, normalizeConfig, validateForSync, validateNormalizedConfig, } from "../config/index.js";
|
|
4
4
|
import { ValidationError, SyncError } from "../shared/errors.js";
|
|
5
5
|
import { validateBranchName } from "./branch-utils.js";
|
|
6
|
-
import {
|
|
6
|
+
import { createTokenManagerFromEnv } from "../vcs/index.js";
|
|
7
7
|
import { RepositoryProcessor } from "../sync/index.js";
|
|
8
8
|
import { ProcessExecutor } from "../shared/command-executor.js";
|
|
9
9
|
import { Logger } from "../shared/logger.js";
|
|
@@ -80,12 +80,7 @@ export async function runSync(options, deps = {}) {
|
|
|
80
80
|
logger.log(`Found ${config.repos.length} repositories to process`);
|
|
81
81
|
logger.log(`Target files: ${formatFileNames(fileNames)}`);
|
|
82
82
|
logger.log(`Branch: ${branchName}\n`);
|
|
83
|
-
const tokenManager =
|
|
84
|
-
? {
|
|
85
|
-
clientId: process.env.XFG_GITHUB_CLIENT_ID,
|
|
86
|
-
privateKey: process.env.XFG_GITHUB_APP_PRIVATE_KEY,
|
|
87
|
-
}
|
|
88
|
-
: undefined);
|
|
83
|
+
const tokenManager = createTokenManagerFromEnv(process.env);
|
|
89
84
|
const processor = deps.processorFactory
|
|
90
85
|
? deps.processorFactory()
|
|
91
86
|
: new RepositoryProcessor(undefined, logger, {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { hasLifecycleChanges, writeGitHubStepSummary, renderSyncLines, renderRepoSettingsDiffLines, formatCountEntry, } from "../output/index.js";
|
|
2
|
-
|
|
3
|
-
// Helpers
|
|
4
|
-
// =============================================================================
|
|
1
|
+
import { hasLifecycleChanges, writeGitHubStepSummary, renderSyncLines, renderRepoSettingsDiffLines, formatCountEntry, formatSettingsCountEntries, hasRepoSettingsChanges, } from "../output/index.js";
|
|
2
|
+
import { formatActionCountEntry } from "../shared/count-format.js";
|
|
5
3
|
function selectLabel(dry, pastLabel, futureLabel) {
|
|
6
4
|
return dry ? futureLabel : pastLabel;
|
|
7
5
|
}
|
|
@@ -19,70 +17,12 @@ function formatCombinedSummary(input) {
|
|
|
19
17
|
parts.push(entry);
|
|
20
18
|
}
|
|
21
19
|
if (input.sync) {
|
|
22
|
-
const
|
|
23
|
-
const entry = formatCountEntry("file", "files", [
|
|
24
|
-
{
|
|
25
|
-
label: selectLabel(dry, "created", "to create"),
|
|
26
|
-
value: t.files.create,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
label: selectLabel(dry, "updated", "to update"),
|
|
30
|
-
value: t.files.update,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
label: selectLabel(dry, "deleted", "to delete"),
|
|
34
|
-
value: t.files.delete,
|
|
35
|
-
},
|
|
36
|
-
]);
|
|
20
|
+
const entry = formatActionCountEntry("file", "files", input.sync.totals.files, dry);
|
|
37
21
|
if (entry)
|
|
38
22
|
parts.push(entry);
|
|
39
23
|
}
|
|
40
24
|
if (input.settings) {
|
|
41
|
-
|
|
42
|
-
const settingsEntry = formatCountEntry("setting", "settings", [
|
|
43
|
-
{
|
|
44
|
-
label: selectLabel(dry, "created", "to create"),
|
|
45
|
-
value: t.settings.create,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
label: selectLabel(dry, "updated", "to update"),
|
|
49
|
-
value: t.settings.update,
|
|
50
|
-
},
|
|
51
|
-
]);
|
|
52
|
-
if (settingsEntry)
|
|
53
|
-
parts.push(settingsEntry);
|
|
54
|
-
const rulesetsEntry = formatCountEntry("ruleset", "rulesets", [
|
|
55
|
-
{
|
|
56
|
-
label: selectLabel(dry, "created", "to create"),
|
|
57
|
-
value: t.rulesets.create,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
label: selectLabel(dry, "updated", "to update"),
|
|
61
|
-
value: t.rulesets.update,
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
label: selectLabel(dry, "deleted", "to delete"),
|
|
65
|
-
value: t.rulesets.delete,
|
|
66
|
-
},
|
|
67
|
-
]);
|
|
68
|
-
if (rulesetsEntry)
|
|
69
|
-
parts.push(rulesetsEntry);
|
|
70
|
-
const labelsEntry = formatCountEntry("label", "labels", [
|
|
71
|
-
{
|
|
72
|
-
label: selectLabel(dry, "created", "to create"),
|
|
73
|
-
value: t.labels.create,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
label: selectLabel(dry, "updated", "to update"),
|
|
77
|
-
value: t.labels.update,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
label: selectLabel(dry, "deleted", "to delete"),
|
|
81
|
-
value: t.labels.delete,
|
|
82
|
-
},
|
|
83
|
-
]);
|
|
84
|
-
if (labelsEntry)
|
|
85
|
-
parts.push(labelsEntry);
|
|
25
|
+
parts.push(...formatSettingsCountEntries(input.settings.totals, dry));
|
|
86
26
|
}
|
|
87
27
|
if (parts.length === 0) {
|
|
88
28
|
return "No changes";
|
|
@@ -95,16 +35,8 @@ function hasAnyChanges(input) {
|
|
|
95
35
|
return true;
|
|
96
36
|
if (input.sync?.repos.some((r) => r.files.length > 0 || r.error))
|
|
97
37
|
return true;
|
|
98
|
-
|
|
99
|
-
r.rulesets.length > 0 ||
|
|
100
|
-
r.labels.length > 0 ||
|
|
101
|
-
r.error))
|
|
102
|
-
return true;
|
|
103
|
-
return false;
|
|
38
|
+
return input.settings?.repos.some(hasRepoSettingsChanges) ?? false;
|
|
104
39
|
}
|
|
105
|
-
// =============================================================================
|
|
106
|
-
// Diff line builders
|
|
107
|
-
// =============================================================================
|
|
108
40
|
function renderLifecycleLines(lcAction, diffLines) {
|
|
109
41
|
if (lcAction.action === "existed")
|
|
110
42
|
return;
|
|
@@ -133,29 +65,29 @@ function renderLifecycleLines(lcAction, diffLines) {
|
|
|
133
65
|
}
|
|
134
66
|
}
|
|
135
67
|
}
|
|
136
|
-
// =============================================================================
|
|
137
|
-
// Markdown Formatter
|
|
138
|
-
// =============================================================================
|
|
139
68
|
export function formatUnifiedSummaryMarkdown(input) {
|
|
140
69
|
if (!hasAnyChanges(input)) {
|
|
141
70
|
return "";
|
|
142
71
|
}
|
|
143
72
|
const lines = [];
|
|
144
|
-
// Title: "xfg Plan" for dry-run, "xfg Apply" otherwise
|
|
145
73
|
const title = input.dryRun ? "## xfg Plan" : "## xfg Apply";
|
|
146
74
|
lines.push(title);
|
|
147
75
|
lines.push("");
|
|
148
|
-
// Dry-run warning
|
|
149
76
|
if (input.dryRun) {
|
|
150
77
|
lines.push("> [!WARNING]");
|
|
151
78
|
lines.push("> This was a dry run — no changes were applied");
|
|
152
79
|
lines.push("");
|
|
153
80
|
}
|
|
154
|
-
// Build lookup maps
|
|
155
81
|
const lifecycleByRepo = new Map((input.lifecycle?.actions ?? []).map((a) => [a.repoName, a]));
|
|
156
82
|
const syncByRepo = new Map((input.sync?.repos ?? []).map((r) => [r.repoName, r]));
|
|
157
|
-
|
|
158
|
-
|
|
83
|
+
// The same repo can appear more than once (e.g. listed twice in config); keep every entry.
|
|
84
|
+
const settingsByRepo = new Map();
|
|
85
|
+
for (const r of input.settings?.repos ?? []) {
|
|
86
|
+
settingsByRepo.set(r.repoName, [
|
|
87
|
+
...(settingsByRepo.get(r.repoName) ?? []),
|
|
88
|
+
r,
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
159
91
|
const allRepos = [];
|
|
160
92
|
const addRepo = (name) => {
|
|
161
93
|
if (!allRepos.includes(name))
|
|
@@ -167,35 +99,31 @@ export function formatUnifiedSummaryMarkdown(input) {
|
|
|
167
99
|
addRepo(r.repoName);
|
|
168
100
|
for (const r of input.settings?.repos ?? [])
|
|
169
101
|
addRepo(r.repoName);
|
|
170
|
-
// Per-repo sections: heading + diff block
|
|
171
102
|
for (const repoName of allRepos) {
|
|
172
103
|
const lcAction = lifecycleByRepo.get(repoName);
|
|
173
104
|
const syncRepo = syncByRepo.get(repoName);
|
|
174
|
-
const
|
|
105
|
+
const settingsRepos = (settingsByRepo.get(repoName) ?? []).filter(hasRepoSettingsChanges);
|
|
175
106
|
const hasLcChange = lcAction && lcAction.action !== "existed";
|
|
176
107
|
const hasSyncChanges = syncRepo && (syncRepo.files.length > 0 || syncRepo.error);
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
settingsRepo.rulesets.length > 0 ||
|
|
180
|
-
settingsRepo.labels.length > 0 ||
|
|
181
|
-
settingsRepo.error);
|
|
182
|
-
if (!hasLcChange && !hasSyncChanges && !hasSettingsChanges)
|
|
108
|
+
const repoHasSettingsChanges = settingsRepos.length > 0;
|
|
109
|
+
if (!hasLcChange && !hasSyncChanges && !repoHasSettingsChanges)
|
|
183
110
|
continue;
|
|
184
111
|
lines.push(`### ${repoName}`);
|
|
185
112
|
lines.push("");
|
|
186
113
|
const diffLines = [];
|
|
187
114
|
if (lcAction)
|
|
188
115
|
renderLifecycleLines(lcAction, diffLines);
|
|
189
|
-
// Blank line between lifecycle and sync sections
|
|
190
116
|
if (hasLcChange && hasSyncChanges)
|
|
191
117
|
diffLines.push("");
|
|
192
118
|
if (syncRepo)
|
|
193
119
|
diffLines.push(...renderSyncLines(syncRepo));
|
|
194
|
-
|
|
195
|
-
if (hasSyncChanges && hasSettingsChanges)
|
|
120
|
+
if (hasSyncChanges && repoHasSettingsChanges)
|
|
196
121
|
diffLines.push("");
|
|
197
|
-
|
|
122
|
+
settingsRepos.forEach((settingsRepo, i) => {
|
|
123
|
+
if (i > 0)
|
|
124
|
+
diffLines.push("");
|
|
198
125
|
renderRepoSettingsDiffLines(settingsRepo, diffLines);
|
|
126
|
+
});
|
|
199
127
|
if (diffLines.length > 0) {
|
|
200
128
|
lines.push("```diff");
|
|
201
129
|
lines.push(...diffLines);
|
|
@@ -203,13 +131,9 @@ export function formatUnifiedSummaryMarkdown(input) {
|
|
|
203
131
|
lines.push("");
|
|
204
132
|
}
|
|
205
133
|
}
|
|
206
|
-
// Combined summary
|
|
207
134
|
lines.push(`**${formatCombinedSummary(input)}**`);
|
|
208
135
|
return lines.join("\n");
|
|
209
136
|
}
|
|
210
|
-
// =============================================================================
|
|
211
|
-
// File Writer
|
|
212
|
-
// =============================================================================
|
|
213
137
|
export function writeUnifiedSummary(input) {
|
|
214
138
|
const markdown = formatUnifiedSummaryMarkdown(input);
|
|
215
139
|
if (!markdown)
|
package/dist/output/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { writeGitHubStepSummary } from "./github-summary.js";
|
|
2
2
|
export { hasLifecycleChanges, formatLifecycleReportCLI, formatLifecycleReportMarkdown, writeLifecycleReportSummary, type LifecycleReport, type LifecycleAction, } from "./lifecycle-report.js";
|
|
3
|
-
export { formatCountEntry
|
|
3
|
+
export { formatCountEntry } from "../shared/count-format.js";
|
|
4
|
+
export { formatSettingsCountEntries, formatSettingsReportCLI, hasRepoSettingsChanges, renderRepoSettingsDiffLines, formatSettingsReportMarkdown, writeSettingsReportSummary, type SettingsReport, type RepoChanges, type SettingChange, type RulesetChange, type LabelChange, } from "./settings-report.js";
|
|
4
5
|
export { formatSyncReportCLI, formatSyncReportMarkdown, renderSyncLines, writeSyncReportSummary, type SyncReport, type RepoFileChanges, type ReportFileChange, } from "./sync-report.js";
|
package/dist/output/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { writeGitHubStepSummary } from "./github-summary.js";
|
|
2
2
|
export { hasLifecycleChanges, formatLifecycleReportCLI, formatLifecycleReportMarkdown, writeLifecycleReportSummary, } from "./lifecycle-report.js";
|
|
3
|
-
export { formatCountEntry
|
|
3
|
+
export { formatCountEntry } from "../shared/count-format.js";
|
|
4
|
+
export { formatSettingsCountEntries, formatSettingsReportCLI, hasRepoSettingsChanges, renderRepoSettingsDiffLines, formatSettingsReportMarkdown, writeSettingsReportSummary, } from "./settings-report.js";
|
|
4
5
|
export { formatSyncReportCLI, formatSyncReportMarkdown, renderSyncLines, writeSyncReportSummary, } from "./sync-report.js";
|
|
@@ -19,9 +19,6 @@ export interface LifecycleAction {
|
|
|
19
19
|
description?: string;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Returns true if the report has any non-"existed" actions worth displaying.
|
|
24
|
-
*/
|
|
25
22
|
export declare function hasLifecycleChanges(report: LifecycleReport): boolean;
|
|
26
23
|
export declare function formatLifecycleReportCLI(report: LifecycleReport): string[];
|
|
27
24
|
export declare function formatLifecycleReportMarkdown(report: LifecycleReport, dryRun: boolean): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { writeGitHubStepSummary } from "./github-summary.js";
|
|
3
|
-
import { formatCountEntry } from "
|
|
3
|
+
import { formatCountEntry } from "../shared/count-format.js";
|
|
4
4
|
function formatLifecycleSummary(totals) {
|
|
5
5
|
const entry = formatCountEntry("repo", "repos", [
|
|
6
6
|
{ label: "to create", value: totals.created },
|
|
@@ -9,15 +9,9 @@ function formatLifecycleSummary(totals) {
|
|
|
9
9
|
]);
|
|
10
10
|
return entry ? `Plan: ${entry}` : "No changes";
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
13
|
-
* Returns true if the report has any non-"existed" actions worth displaying.
|
|
14
|
-
*/
|
|
15
12
|
export function hasLifecycleChanges(report) {
|
|
16
13
|
return report.actions.some((a) => a.action !== "existed");
|
|
17
14
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Render action diff lines from lifecycle actions (shared between CLI and Markdown).
|
|
20
|
-
*/
|
|
21
15
|
function renderActionDiffLines(actions) {
|
|
22
16
|
const lines = [];
|
|
23
17
|
for (const action of actions) {
|
|
@@ -64,17 +58,14 @@ export function formatLifecycleReportMarkdown(report, dryRun) {
|
|
|
64
58
|
return "";
|
|
65
59
|
}
|
|
66
60
|
const lines = [];
|
|
67
|
-
// Title
|
|
68
61
|
const titleSuffix = dryRun ? " (Dry Run)" : "";
|
|
69
62
|
lines.push(`## Lifecycle Summary${titleSuffix}`);
|
|
70
63
|
lines.push("");
|
|
71
|
-
// Dry-run warning
|
|
72
64
|
if (dryRun) {
|
|
73
65
|
lines.push("> [!WARNING]");
|
|
74
66
|
lines.push("> This was a dry run — no changes were applied");
|
|
75
67
|
lines.push("");
|
|
76
68
|
}
|
|
77
|
-
// Diff block
|
|
78
69
|
const diffLines = renderActionDiffLines(report.actions);
|
|
79
70
|
if (diffLines.length > 0) {
|
|
80
71
|
lines.push("```diff");
|
|
@@ -82,7 +73,6 @@ export function formatLifecycleReportMarkdown(report, dryRun) {
|
|
|
82
73
|
lines.push("```");
|
|
83
74
|
lines.push("");
|
|
84
75
|
}
|
|
85
|
-
// Summary
|
|
86
76
|
lines.push(`**${formatLifecycleSummary(report.totals)}**`);
|
|
87
77
|
return lines.join("\n");
|
|
88
78
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PropertyDiff, ActiveAction } from "../settings/index.js";
|
|
1
|
+
import type { PropertyDiff, ActiveAction, SecretsPlanEntry } from "../settings/index.js";
|
|
2
2
|
import type { Ruleset, Label } from "../config/index.js";
|
|
3
3
|
export interface SettingsReport {
|
|
4
4
|
repos: RepoChanges[];
|
|
@@ -22,6 +22,11 @@ export interface SettingsReport {
|
|
|
22
22
|
update: number;
|
|
23
23
|
delete: number;
|
|
24
24
|
};
|
|
25
|
+
secrets?: {
|
|
26
|
+
create: number;
|
|
27
|
+
update: number;
|
|
28
|
+
delete: number;
|
|
29
|
+
};
|
|
25
30
|
};
|
|
26
31
|
}
|
|
27
32
|
export interface RepoChanges {
|
|
@@ -35,8 +40,10 @@ export interface RepoChanges {
|
|
|
35
40
|
oldValue?: string;
|
|
36
41
|
newValue?: string;
|
|
37
42
|
}[];
|
|
43
|
+
secrets?: SecretsPlanEntry[];
|
|
38
44
|
error?: string;
|
|
39
45
|
}
|
|
46
|
+
export declare function hasRepoSettingsChanges(repo: RepoChanges): boolean;
|
|
40
47
|
export interface SettingChange {
|
|
41
48
|
name: string;
|
|
42
49
|
action: Exclude<ActiveAction, "delete">;
|
|
@@ -60,19 +67,8 @@ export interface LabelChange {
|
|
|
60
67
|
}[];
|
|
61
68
|
config?: Label;
|
|
62
69
|
}
|
|
63
|
-
|
|
64
|
-
* Formats a summary entry like "3 files (1 to create, 2 to update)".
|
|
65
|
-
* Returns null if total is 0.
|
|
66
|
-
*/
|
|
67
|
-
export declare function formatCountEntry(noun: string, pluralNoun: string, counts: {
|
|
68
|
-
label: string;
|
|
69
|
-
value: number;
|
|
70
|
-
}[]): string | null;
|
|
70
|
+
export declare function formatSettingsCountEntries(totals: SettingsReport["totals"], dryRun: boolean): string[];
|
|
71
71
|
export declare function formatSettingsReportCLI(report: SettingsReport): string[];
|
|
72
|
-
/**
|
|
73
|
-
* Renders a single repo's settings/rulesets/labels changes as plain-text diff lines.
|
|
74
|
-
* Shared between formatSettingsReportMarkdown and unified-summary's renderSettingsLines.
|
|
75
|
-
*/
|
|
76
72
|
export declare function renderRepoSettingsDiffLines(repo: RepoChanges, diffLines: string[]): void;
|
|
77
73
|
export declare function formatSettingsReportMarkdown(report: SettingsReport, dryRun: boolean): string;
|
|
78
74
|
export declare function writeSettingsReportSummary(report: SettingsReport, dryRun: boolean, summaryPath: string | undefined): void;
|