@aspruyt/xfg 7.2.1 → 7.3.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.
- package/PR.md +2 -0
- package/dist/ai/anthropic-client.d.ts +16 -0
- package/dist/ai/anthropic-client.js +35 -0
- package/dist/ai/change-describer.d.ts +16 -0
- package/dist/ai/change-describer.js +170 -0
- package/dist/ai/client-factory.d.ts +2 -0
- package/dist/ai/client-factory.js +33 -0
- package/dist/ai/http.d.ts +3 -0
- package/dist/ai/http.js +33 -0
- package/dist/ai/index.d.ts +5 -0
- package/dist/ai/index.js +4 -0
- package/dist/ai/openai-compatible-client.d.ts +16 -0
- package/dist/ai/openai-compatible-client.js +36 -0
- package/dist/ai/types.d.ts +22 -0
- package/dist/ai/types.js +1 -0
- package/dist/cli/program.d.ts +7 -0
- package/dist/cli/program.js +15 -11
- package/dist/cli/repo-sync-runner.js +1 -0
- package/dist/cli/secrets-command.js +1 -0
- package/dist/cli/sync-command.js +2 -0
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli/unified-summary.d.ts +3 -1
- package/dist/cli/unified-summary.js +14 -26
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +0 -2
- package/dist/config/normalizer.js +17 -24
- package/dist/config/types.d.ts +17 -1
- package/dist/config/validator.js +2 -4
- package/dist/config/validators/ai-validator.d.ts +1 -0
- package/dist/config/validators/ai-validator.js +39 -0
- package/dist/config/validators/group-validator.js +3 -0
- package/dist/config/validators/repo-entry-validator.js +2 -0
- package/dist/lifecycle/formatter.d.ts +0 -4
- package/dist/lifecycle/formatter.js +2 -6
- package/dist/output/github-summary.d.ts +4 -3
- package/dist/output/github-summary.js +22 -5
- package/dist/output/lifecycle-report.d.ts +3 -2
- package/dist/output/lifecycle-report.js +20 -26
- package/dist/output/settings-report.d.ts +3 -2
- package/dist/output/settings-report.js +36 -47
- package/dist/output/summary-budget.d.ts +12 -0
- package/dist/output/summary-budget.js +125 -0
- package/dist/output/sync-report.d.ts +6 -3
- package/dist/output/sync-report.js +33 -34
- package/dist/settings/labels/formatter.d.ts +0 -3
- package/dist/settings/labels/formatter.js +10 -17
- package/dist/settings/rulesets/formatter.d.ts +0 -6
- package/dist/settings/rulesets/formatter.js +4 -32
- package/dist/settings/secrets/formatter.js +4 -3
- package/dist/settings/variables/formatter.js +6 -5
- package/dist/shared/markdown-fence.d.ts +3 -0
- package/dist/shared/markdown-fence.js +32 -0
- package/dist/shared/string-utils.d.ts +1 -3
- package/dist/shared/string-utils.js +5 -4
- package/dist/sync/commit-push-manager.js +2 -2
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/pr-merge-handler.js +3 -1
- package/dist/sync/repository-processor.d.ts +5 -0
- package/dist/sync/repository-processor.js +4 -1
- package/dist/sync/sync-workflow.d.ts +4 -1
- package/dist/sync/sync-workflow.js +29 -2
- package/dist/sync/types.d.ts +14 -3
- package/dist/vcs/ado-pr-strategy.js +43 -1
- package/dist/vcs/git-commit-strategy.js +3 -5
- package/dist/vcs/graphql-commit-strategy.js +3 -6
- package/dist/vcs/pr-creator.d.ts +5 -10
- package/dist/vcs/pr-creator.js +34 -20
- package/dist/vcs/types.d.ts +1 -0
- package/package.json +3 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { writeGitHubStepSummary } from "./github-summary.js";
|
|
3
|
-
import {
|
|
2
|
+
import { STEP_SUMMARY_MAX_BYTES, writeGitHubStepSummary, } from "./github-summary.js";
|
|
3
|
+
import { fitSummary, summaryHeader } from "./summary-budget.js";
|
|
4
|
+
import { formatScalarValue, quoted } from "../shared/string-utils.js";
|
|
4
5
|
import { formatActionCountEntry, } from "../shared/count-format.js";
|
|
5
6
|
export function hasRepoSettingsChanges(repo) {
|
|
6
7
|
return (repo.settings.length > 0 ||
|
|
@@ -25,7 +26,7 @@ function renderRulesetConfig(config, startDepth, formatLine) {
|
|
|
25
26
|
lines.push(formatLine(depth, `+ ${key}: []`));
|
|
26
27
|
}
|
|
27
28
|
else if (value.every((v) => typeof v !== "object")) {
|
|
28
|
-
lines.push(formatLine(depth, `+ ${key}: [${value.map(
|
|
29
|
+
lines.push(formatLine(depth, `+ ${key}: [${value.map(formatValuePlain).join(", ")}]`));
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
32
|
lines.push(formatLine(depth, `+ ${key}:`));
|
|
@@ -138,13 +139,13 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
138
139
|
if (i > 0)
|
|
139
140
|
diffLines.push("");
|
|
140
141
|
if (ruleset.action === "create") {
|
|
141
|
-
diffLines.push(`+ ruleset
|
|
142
|
+
diffLines.push(`+ ruleset ${quoted(ruleset.name)}`);
|
|
142
143
|
if (ruleset.config) {
|
|
143
144
|
diffLines.push(...formatRulesetConfigPlain(ruleset.config));
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
else if (ruleset.action === "update") {
|
|
147
|
-
diffLines.push(`! ruleset
|
|
148
|
+
diffLines.push(`! ruleset ${quoted(ruleset.name)}`);
|
|
148
149
|
if (ruleset.propertyDiffs && ruleset.propertyDiffs.length > 0) {
|
|
149
150
|
for (const diff of ruleset.propertyDiffs) {
|
|
150
151
|
const path = diff.path.join(".");
|
|
@@ -163,7 +164,7 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
else if (ruleset.action === "delete") {
|
|
166
|
-
diffLines.push(`- ruleset
|
|
167
|
+
diffLines.push(`- ruleset ${quoted(ruleset.name)}`);
|
|
167
168
|
}
|
|
168
169
|
}
|
|
169
170
|
if (repo.labels.length > 0 && diffLines.length > startLength) {
|
|
@@ -171,36 +172,36 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
171
172
|
}
|
|
172
173
|
for (const label of repo.labels) {
|
|
173
174
|
if (label.action === "create") {
|
|
174
|
-
diffLines.push(`+ label
|
|
175
|
+
diffLines.push(`+ label ${quoted(label.name)}`);
|
|
175
176
|
if (label.config) {
|
|
176
|
-
diffLines.push(`+ color:
|
|
177
|
+
diffLines.push(`+ color: ${quoted(label.config.color)}`);
|
|
177
178
|
if (label.config.description !== undefined) {
|
|
178
|
-
diffLines.push(`+ description:
|
|
179
|
+
diffLines.push(`+ description: ${quoted(label.config.description)}`);
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
else if (label.action === "update") {
|
|
183
184
|
if (label.newName) {
|
|
184
|
-
diffLines.push(`! label
|
|
185
|
+
diffLines.push(`! label ${quoted(label.name)} \u2192 ${quoted(label.newName)}`);
|
|
185
186
|
}
|
|
186
187
|
else {
|
|
187
|
-
diffLines.push(`! label
|
|
188
|
+
diffLines.push(`! label ${quoted(label.name)}`);
|
|
188
189
|
}
|
|
189
190
|
if (label.propertyChanges) {
|
|
190
191
|
for (const prop of label.propertyChanges) {
|
|
191
192
|
if (prop.property === "new_name")
|
|
192
193
|
continue;
|
|
193
194
|
if (prop.oldValue !== undefined) {
|
|
194
|
-
diffLines.push(`! ${prop.property}:
|
|
195
|
+
diffLines.push(`! ${prop.property}: ${formatValuePlain(prop.oldValue)} \u2192 ${formatValuePlain(prop.newValue)}`);
|
|
195
196
|
}
|
|
196
197
|
else {
|
|
197
|
-
diffLines.push(`! ${prop.property}:
|
|
198
|
+
diffLines.push(`! ${prop.property}: ${formatValuePlain(prop.newValue)}`);
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
else if (label.action === "delete") {
|
|
203
|
-
diffLines.push(`- label
|
|
204
|
+
diffLines.push(`- label ${quoted(label.name)}`);
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
if ((repo.variables ?? []).length > 0 && diffLines.length > startLength) {
|
|
@@ -208,13 +209,13 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
208
209
|
}
|
|
209
210
|
for (const variable of repo.variables ?? []) {
|
|
210
211
|
if (variable.action === "create") {
|
|
211
|
-
diffLines.push(`+ variable
|
|
212
|
+
diffLines.push(`+ variable ${quoted(variable.name)}: ${formatValuePlain(variable.newValue)}`);
|
|
212
213
|
}
|
|
213
214
|
else if (variable.action === "update") {
|
|
214
|
-
diffLines.push(`! variable
|
|
215
|
+
diffLines.push(`! variable ${quoted(variable.name)}: ${formatValuePlain(variable.oldValue)} → ${formatValuePlain(variable.newValue)}`);
|
|
215
216
|
}
|
|
216
217
|
else if (variable.action === "delete") {
|
|
217
|
-
diffLines.push(`- variable
|
|
218
|
+
diffLines.push(`- variable ${quoted(variable.name)}`);
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
if ((repo.secrets ?? []).length > 0 && diffLines.length > startLength) {
|
|
@@ -223,47 +224,35 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
223
224
|
// Names only: secret values are write-only and must never reach output.
|
|
224
225
|
for (const secret of repo.secrets ?? []) {
|
|
225
226
|
if (secret.action === "create") {
|
|
226
|
-
diffLines.push(`+ secret
|
|
227
|
+
diffLines.push(`+ secret ${quoted(secret.name)}`);
|
|
227
228
|
}
|
|
228
229
|
else if (secret.action === "update") {
|
|
229
|
-
diffLines.push(`! secret
|
|
230
|
+
diffLines.push(`! secret ${quoted(secret.name)} (update, value write-only)`);
|
|
230
231
|
}
|
|
231
232
|
else {
|
|
232
|
-
diffLines.push(`- secret
|
|
233
|
+
diffLines.push(`- secret ${quoted(secret.name)}`);
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
236
|
if (repo.error) {
|
|
236
237
|
diffLines.push(`- Error: ${repo.error}`);
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
|
-
export function formatSettingsReportMarkdown(report, dryRun) {
|
|
240
|
-
const
|
|
241
|
-
const title = dryRun ? "## xfg Plan" : "## xfg Apply";
|
|
242
|
-
lines.push(title);
|
|
243
|
-
lines.push("");
|
|
244
|
-
if (dryRun) {
|
|
245
|
-
lines.push("> [!WARNING]");
|
|
246
|
-
lines.push("> This was a dry run — no changes were applied");
|
|
247
|
-
lines.push("");
|
|
248
|
-
}
|
|
249
|
-
for (const repo of report.repos) {
|
|
250
|
-
if (!hasRepoSettingsChanges(repo))
|
|
251
|
-
continue;
|
|
252
|
-
lines.push(`### ${repo.repoName}`);
|
|
253
|
-
lines.push("");
|
|
240
|
+
export function formatSettingsReportMarkdown(report, dryRun, maxBytes = STEP_SUMMARY_MAX_BYTES) {
|
|
241
|
+
const blocks = report.repos.filter(hasRepoSettingsChanges).map((repo) => {
|
|
254
242
|
const diffLines = [];
|
|
255
243
|
renderRepoSettingsDiffLines(repo, diffLines);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
244
|
+
return {
|
|
245
|
+
heading: `### ${repo.repoName}`,
|
|
246
|
+
diffLines,
|
|
247
|
+
repos: [repo.repoName],
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
return fitSummary({
|
|
251
|
+
header: summaryHeader(dryRun),
|
|
252
|
+
blocks,
|
|
253
|
+
footer: `**${formatSettingsSummary(report.totals)}**`,
|
|
254
|
+
}, maxBytes);
|
|
265
255
|
}
|
|
266
|
-
export function writeSettingsReportSummary(report, dryRun, summaryPath) {
|
|
267
|
-
|
|
268
|
-
writeGitHubStepSummary(markdown, summaryPath);
|
|
256
|
+
export function writeSettingsReportSummary(report, dryRun, summaryPath, log) {
|
|
257
|
+
writeGitHubStepSummary((maxBytes) => formatSettingsReportMarkdown(report, dryRun, maxBytes), summaryPath, log);
|
|
269
258
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SummaryBlock {
|
|
2
|
+
heading?: string;
|
|
3
|
+
diffLines: string[];
|
|
4
|
+
repos: string[];
|
|
5
|
+
}
|
|
6
|
+
export interface SummaryParts {
|
|
7
|
+
header: string[];
|
|
8
|
+
blocks: SummaryBlock[];
|
|
9
|
+
footer: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function summaryHeader(dryRun: boolean, title?: string): string[];
|
|
12
|
+
export declare function fitSummary(parts: SummaryParts, maxBytes: number): string;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { appendDiffBlock, diffFence, inlineCode, } from "../shared/markdown-fence.js";
|
|
2
|
+
const CUT_NOTE = "... cut to fit GitHub's 1 MiB summary limit";
|
|
3
|
+
// Room kept for the "more repos not shown" line when something is cut.
|
|
4
|
+
const NOTE_RESERVE_BYTES = 1000;
|
|
5
|
+
// Shorter leftovers of a cut line are not worth showing.
|
|
6
|
+
const MIN_CUT_LINE_BYTES = 40;
|
|
7
|
+
export function summaryHeader(dryRun, title = dryRun ? "## xfg Plan" : "## xfg Apply") {
|
|
8
|
+
const lines = [title, ""];
|
|
9
|
+
if (dryRun) {
|
|
10
|
+
lines.push("> [!WARNING]", "> This was a dry run — no changes were applied", "");
|
|
11
|
+
}
|
|
12
|
+
return lines;
|
|
13
|
+
}
|
|
14
|
+
function lineBytes(line) {
|
|
15
|
+
return Buffer.byteLength(line) + 1;
|
|
16
|
+
}
|
|
17
|
+
function linesBytes(lines) {
|
|
18
|
+
let total = 0;
|
|
19
|
+
for (const line of lines)
|
|
20
|
+
total += lineBytes(line);
|
|
21
|
+
return total;
|
|
22
|
+
}
|
|
23
|
+
function blockOverhead(block) {
|
|
24
|
+
const heading = block.heading === undefined ? 0 : lineBytes(block.heading) + 1;
|
|
25
|
+
if (block.diffLines.length === 0)
|
|
26
|
+
return heading;
|
|
27
|
+
const fence = diffFence(block.diffLines).length;
|
|
28
|
+
return heading + fence + 5 + fence + 1 + 1;
|
|
29
|
+
}
|
|
30
|
+
function truncateBytes(text, maxBytes) {
|
|
31
|
+
const buf = Buffer.from(text);
|
|
32
|
+
if (buf.length <= maxBytes)
|
|
33
|
+
return text;
|
|
34
|
+
let end = Math.max(0, maxBytes);
|
|
35
|
+
while (end > 0 && (buf[end] & 0xc0) === 0x80)
|
|
36
|
+
end--;
|
|
37
|
+
return buf.subarray(0, end).toString();
|
|
38
|
+
}
|
|
39
|
+
function cutToFit(diffLines, room) {
|
|
40
|
+
const kept = [];
|
|
41
|
+
let used = lineBytes(CUT_NOTE);
|
|
42
|
+
for (const line of diffLines) {
|
|
43
|
+
const left = room - used;
|
|
44
|
+
if (lineBytes(line) > left) {
|
|
45
|
+
const part = truncateBytes(line, left - 1 - Buffer.byteLength("…"));
|
|
46
|
+
if (Buffer.byteLength(part) >= MIN_CUT_LINE_BYTES)
|
|
47
|
+
kept.push(part + "…");
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
kept.push(line);
|
|
51
|
+
used += lineBytes(line);
|
|
52
|
+
}
|
|
53
|
+
if (kept.length > 0)
|
|
54
|
+
kept.push(CUT_NOTE);
|
|
55
|
+
return kept;
|
|
56
|
+
}
|
|
57
|
+
function hiddenNote(repos, maxBytes) {
|
|
58
|
+
const prefix = `_${repos.length} more ${repos.length === 1 ? "repo" : "repos"} not shown, see the job log:_`;
|
|
59
|
+
const more = ", …";
|
|
60
|
+
let note = prefix;
|
|
61
|
+
for (let i = 0; i < repos.length; i++) {
|
|
62
|
+
const name = `${i === 0 ? " " : ", "}${inlineCode(repos[i])}`;
|
|
63
|
+
const tail = i < repos.length - 1 ? Buffer.byteLength(more) : 0;
|
|
64
|
+
if (Buffer.byteLength(note + name) + tail > maxBytes) {
|
|
65
|
+
return i === 0 ? prefix : note + more;
|
|
66
|
+
}
|
|
67
|
+
note += name;
|
|
68
|
+
}
|
|
69
|
+
return note;
|
|
70
|
+
}
|
|
71
|
+
// Priority: footer, then header, then whole blocks, then cut blocks with what is left.
|
|
72
|
+
export function fitSummary(parts, maxBytes) {
|
|
73
|
+
let used = Buffer.byteLength(parts.footer);
|
|
74
|
+
if (used > maxBytes)
|
|
75
|
+
return "";
|
|
76
|
+
const lines = [];
|
|
77
|
+
const headerBytes = linesBytes(parts.header);
|
|
78
|
+
if (used + headerBytes <= maxBytes) {
|
|
79
|
+
for (const line of parts.header)
|
|
80
|
+
lines.push(line);
|
|
81
|
+
used += headerBytes;
|
|
82
|
+
}
|
|
83
|
+
const overheads = parts.blocks.map(blockOverhead);
|
|
84
|
+
const sizes = parts.blocks.map((block, i) => overheads[i] + linesBytes(block.diffLines));
|
|
85
|
+
const allFit = used + sizes.reduce((a, b) => a + b, 0) <= maxBytes;
|
|
86
|
+
const reserve = allFit
|
|
87
|
+
? 0
|
|
88
|
+
: Math.min(NOTE_RESERVE_BYTES, Math.floor((maxBytes - used) / 2));
|
|
89
|
+
const room = () => maxBytes - used - reserve;
|
|
90
|
+
const shown = [];
|
|
91
|
+
parts.blocks.forEach((block, i) => {
|
|
92
|
+
if (sizes[i] <= room()) {
|
|
93
|
+
shown[i] = block.diffLines;
|
|
94
|
+
used += sizes[i];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
parts.blocks.forEach((block, i) => {
|
|
98
|
+
if (shown[i])
|
|
99
|
+
return;
|
|
100
|
+
const kept = cutToFit(block.diffLines, room() - overheads[i]);
|
|
101
|
+
if (kept.length === 0)
|
|
102
|
+
return;
|
|
103
|
+
shown[i] = kept;
|
|
104
|
+
used += overheads[i] + linesBytes(kept);
|
|
105
|
+
});
|
|
106
|
+
const hidden = [];
|
|
107
|
+
parts.blocks.forEach((block, i) => {
|
|
108
|
+
const diffLines = shown[i];
|
|
109
|
+
if (!diffLines) {
|
|
110
|
+
for (const repo of block.repos)
|
|
111
|
+
hidden.push(repo);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (block.heading !== undefined)
|
|
115
|
+
lines.push(block.heading, "");
|
|
116
|
+
appendDiffBlock(lines, diffLines);
|
|
117
|
+
});
|
|
118
|
+
if (hidden.length > 0) {
|
|
119
|
+
const note = hiddenNote(hidden, maxBytes - used - 2);
|
|
120
|
+
if (lineBytes(note) + 1 <= maxBytes - used)
|
|
121
|
+
lines.push(note, "");
|
|
122
|
+
}
|
|
123
|
+
lines.push(parts.footer);
|
|
124
|
+
return lines.join("\n");
|
|
125
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MergeMode } from "../config/index.js";
|
|
2
2
|
import type { ActiveAction } from "../settings/index.js";
|
|
3
|
+
import type { DebugLog } from "../shared/logger.js";
|
|
3
4
|
export interface ReportFileChange {
|
|
4
5
|
path: string;
|
|
5
6
|
action: ActiveAction;
|
|
@@ -23,6 +24,8 @@ export interface RepoFileChanges {
|
|
|
23
24
|
error?: string;
|
|
24
25
|
}
|
|
25
26
|
export declare function formatSyncReportCLI(report: SyncReport): string[];
|
|
26
|
-
export declare function formatSyncReportMarkdown(report: SyncReport, dryRun: boolean): string;
|
|
27
|
-
export declare
|
|
28
|
-
export declare
|
|
27
|
+
export declare function formatSyncReportMarkdown(report: SyncReport, dryRun: boolean, maxBytes?: number): string;
|
|
28
|
+
export declare const SUMMARY_DIFF_LINE_LIMIT = 500;
|
|
29
|
+
export declare const SUMMARY_LINE_MAX_CHARS = 1000;
|
|
30
|
+
export declare function renderSyncLines(syncRepo: RepoFileChanges, lines?: string[]): string[];
|
|
31
|
+
export declare function writeSyncReportSummary(report: SyncReport, dryRun: boolean, summaryPath: string | undefined, log?: DebugLog): void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { writeGitHubStepSummary } from "./github-summary.js";
|
|
3
2
|
import { formatCountEntry } from "../shared/count-format.js";
|
|
4
3
|
import { formatDiffLine } from "../shared/diff-format.js";
|
|
4
|
+
import { STEP_SUMMARY_MAX_BYTES, writeGitHubStepSummary, } from "./github-summary.js";
|
|
5
|
+
import { fitSummary, summaryHeader } from "./summary-budget.js";
|
|
5
6
|
function formatSyncSummary(totals) {
|
|
6
7
|
const entry = formatCountEntry("file", "files", [
|
|
7
8
|
{ label: "to create", value: totals.files.create },
|
|
@@ -41,35 +42,30 @@ export function formatSyncReportCLI(report) {
|
|
|
41
42
|
lines.push(formatSyncSummary(report.totals));
|
|
42
43
|
return lines;
|
|
43
44
|
}
|
|
44
|
-
export function formatSyncReportMarkdown(report, dryRun) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
lines.push(`### ${repo.repoName}`);
|
|
59
|
-
lines.push("");
|
|
60
|
-
const diffLines = renderSyncLines(repo);
|
|
61
|
-
if (diffLines.length > 0) {
|
|
62
|
-
lines.push("```diff");
|
|
63
|
-
lines.push(...diffLines);
|
|
64
|
-
lines.push("```");
|
|
65
|
-
lines.push("");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
lines.push(`**${formatSyncSummary(report.totals)}**`);
|
|
69
|
-
return lines.join("\n");
|
|
45
|
+
export function formatSyncReportMarkdown(report, dryRun, maxBytes = STEP_SUMMARY_MAX_BYTES) {
|
|
46
|
+
const blocks = report.repos
|
|
47
|
+
.filter((repo) => repo.files.length > 0 || repo.error)
|
|
48
|
+
.map((repo) => ({
|
|
49
|
+
heading: `### ${repo.repoName}`,
|
|
50
|
+
diffLines: renderSyncLines(repo),
|
|
51
|
+
repos: [repo.repoName],
|
|
52
|
+
}));
|
|
53
|
+
return fitSummary({
|
|
54
|
+
header: summaryHeader(dryRun),
|
|
55
|
+
blocks,
|
|
56
|
+
footer: `**${formatSyncSummary(report.totals)}**`,
|
|
57
|
+
}, maxBytes);
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
// Stops one huge file from using up the summary space the other files need.
|
|
60
|
+
export const SUMMARY_DIFF_LINE_LIMIT = 500;
|
|
61
|
+
// Same idea for single long lines, e.g. minified JSON.
|
|
62
|
+
export const SUMMARY_LINE_MAX_CHARS = 1000;
|
|
63
|
+
function shortenLine(line) {
|
|
64
|
+
return line.length > SUMMARY_LINE_MAX_CHARS
|
|
65
|
+
? line.slice(0, SUMMARY_LINE_MAX_CHARS) + "…"
|
|
66
|
+
: line;
|
|
67
|
+
}
|
|
68
|
+
export function renderSyncLines(syncRepo, lines = []) {
|
|
73
69
|
for (let i = 0; i < syncRepo.files.length; i++) {
|
|
74
70
|
const file = syncRepo.files[i];
|
|
75
71
|
if (i > 0)
|
|
@@ -83,8 +79,12 @@ export function renderSyncLines(syncRepo) {
|
|
|
83
79
|
else if (file.action === "delete") {
|
|
84
80
|
lines.push(`- ${file.path}`);
|
|
85
81
|
}
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
const diffLines = file.diffLines ?? [];
|
|
83
|
+
const shown = Math.min(diffLines.length, SUMMARY_DIFF_LINE_LIMIT);
|
|
84
|
+
for (let j = 0; j < shown; j++)
|
|
85
|
+
lines.push(shortenLine(diffLines[j]));
|
|
86
|
+
if (diffLines.length > shown) {
|
|
87
|
+
lines.push(`... ${diffLines.length - shown} more lines not shown`);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
if (syncRepo.error) {
|
|
@@ -92,7 +92,6 @@ export function renderSyncLines(syncRepo) {
|
|
|
92
92
|
}
|
|
93
93
|
return lines;
|
|
94
94
|
}
|
|
95
|
-
export function writeSyncReportSummary(report, dryRun, summaryPath) {
|
|
96
|
-
|
|
97
|
-
writeGitHubStepSummary(markdown, summaryPath);
|
|
95
|
+
export function writeSyncReportSummary(report, dryRun, summaryPath, log) {
|
|
96
|
+
writeGitHubStepSummary((maxBytes) => formatSyncReportMarkdown(report, dryRun, maxBytes), summaryPath, log);
|
|
98
97
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { countActions } from "../base-processor.js";
|
|
3
|
-
|
|
4
|
-
* Format label changes as a Terraform-style plan.
|
|
5
|
-
*/
|
|
3
|
+
import { formatScalarValue, quoted } from "../../shared/string-utils.js";
|
|
6
4
|
export function formatLabelsPlan(changes) {
|
|
7
5
|
const lines = [];
|
|
8
6
|
const entries = [];
|
|
@@ -16,15 +14,14 @@ export function formatLabelsPlan(changes) {
|
|
|
16
14
|
for (const c of changes) {
|
|
17
15
|
grouped[c.action].push(c);
|
|
18
16
|
}
|
|
19
|
-
// Format creates
|
|
20
17
|
if (grouped.create.length > 0) {
|
|
21
18
|
lines.push(chalk.bold(" Create:"));
|
|
22
19
|
for (const change of grouped.create) {
|
|
23
|
-
lines.push(chalk.green(` + label
|
|
20
|
+
lines.push(chalk.green(` + label ${quoted(change.name)}`));
|
|
24
21
|
if (change.desired) {
|
|
25
|
-
lines.push(chalk.green(` color:
|
|
22
|
+
lines.push(chalk.green(` color: ${quoted(change.desired.color)}`));
|
|
26
23
|
if (change.desired.description !== undefined) {
|
|
27
|
-
lines.push(chalk.green(` description:
|
|
24
|
+
lines.push(chalk.green(` description: ${quoted(change.desired.description)}`));
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
entries.push({
|
|
@@ -35,25 +32,24 @@ export function formatLabelsPlan(changes) {
|
|
|
35
32
|
lines.push("");
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
// Format updates
|
|
39
35
|
if (grouped.update.length > 0) {
|
|
40
36
|
lines.push(chalk.bold(" Update:"));
|
|
41
37
|
for (const change of grouped.update) {
|
|
42
38
|
if (change.newName) {
|
|
43
|
-
lines.push(chalk.yellow(` ~ label
|
|
39
|
+
lines.push(chalk.yellow(` ~ label ${quoted(change.name)} \u2192 ${quoted(change.newName)}`));
|
|
44
40
|
}
|
|
45
41
|
else {
|
|
46
|
-
lines.push(chalk.yellow(` ~ label
|
|
42
|
+
lines.push(chalk.yellow(` ~ label ${quoted(change.name)}`));
|
|
47
43
|
}
|
|
48
44
|
if (change.propertyChanges) {
|
|
49
45
|
for (const prop of change.propertyChanges) {
|
|
50
46
|
if (prop.property === "new_name")
|
|
51
|
-
continue;
|
|
47
|
+
continue;
|
|
52
48
|
if (prop.oldValue !== undefined) {
|
|
53
|
-
lines.push(chalk.yellow(` ${prop.property}:
|
|
49
|
+
lines.push(chalk.yellow(` ${prop.property}: ${formatScalarValue(prop.oldValue)} \u2192 ${formatScalarValue(prop.newValue)}`));
|
|
54
50
|
}
|
|
55
51
|
else {
|
|
56
|
-
lines.push(chalk.yellow(` ${prop.property}:
|
|
52
|
+
lines.push(chalk.yellow(` ${prop.property}: ${formatScalarValue(prop.newValue)}`));
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
}
|
|
@@ -66,20 +62,17 @@ export function formatLabelsPlan(changes) {
|
|
|
66
62
|
lines.push("");
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
|
-
// Format deletes
|
|
70
65
|
if (grouped.delete.length > 0) {
|
|
71
66
|
lines.push(chalk.bold(" Delete:"));
|
|
72
67
|
for (const change of grouped.delete) {
|
|
73
|
-
lines.push(chalk.red(` - label
|
|
68
|
+
lines.push(chalk.red(` - label ${quoted(change.name)}`));
|
|
74
69
|
entries.push({ name: change.name, action: "delete" });
|
|
75
70
|
}
|
|
76
71
|
lines.push("");
|
|
77
72
|
}
|
|
78
|
-
// Unchanged (entries only, no output lines)
|
|
79
73
|
for (const change of grouped.unchanged) {
|
|
80
74
|
entries.push({ name: change.name, action: "unchanged" });
|
|
81
75
|
}
|
|
82
|
-
// Summary line
|
|
83
76
|
const total = creates + updates + deletes;
|
|
84
77
|
if (total > 0) {
|
|
85
78
|
const parts = [];
|
|
@@ -21,11 +21,5 @@ export interface RulesetPlanResult {
|
|
|
21
21
|
unchanged: number;
|
|
22
22
|
entries: RulesetPlanEntry[];
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Format property diffs as an indented tree structure.
|
|
26
|
-
*/
|
|
27
24
|
export declare function formatPropertyTree(diffs: PropertyDiff[]): string[];
|
|
28
|
-
/**
|
|
29
|
-
* Format ruleset changes as a Terraform-style plan.
|
|
30
|
-
*/
|
|
31
25
|
export declare function formatRulesetPlan(changes: RulesetChange[]): RulesetPlanResult;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { projectToDesiredShape, normalizeRuleset, } from "./diff.js";
|
|
3
|
-
import { formatScalarValue } from "../../shared/string-utils.js";
|
|
3
|
+
import { formatScalarValue, quoted } from "../../shared/string-utils.js";
|
|
4
4
|
import { computePropertyDiffs, } from "./diff-algorithm.js";
|
|
5
5
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
6
|
-
/**
|
|
7
|
-
* Build a tree structure from flat property diffs.
|
|
8
|
-
*/
|
|
9
6
|
function buildTree(diffs) {
|
|
10
7
|
const root = { name: "", children: new Map() };
|
|
11
8
|
for (const diff of diffs) {
|
|
@@ -26,7 +23,6 @@ function buildTree(diffs) {
|
|
|
26
23
|
child.newValue = diff.newValue;
|
|
27
24
|
}
|
|
28
25
|
else {
|
|
29
|
-
// Intermediate node - mark as change if any child changes
|
|
30
26
|
if (!child.action) {
|
|
31
27
|
child.action = "change";
|
|
32
28
|
}
|
|
@@ -36,9 +32,6 @@ function buildTree(diffs) {
|
|
|
36
32
|
}
|
|
37
33
|
return root;
|
|
38
34
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Format a value for inline display (scalars and simple arrays only).
|
|
41
|
-
*/
|
|
42
35
|
function formatValue(val) {
|
|
43
36
|
const scalar = formatScalarValue(val);
|
|
44
37
|
if (scalar !== undefined)
|
|
@@ -56,9 +49,6 @@ function formatValue(val) {
|
|
|
56
49
|
}
|
|
57
50
|
return String(val);
|
|
58
51
|
}
|
|
59
|
-
/**
|
|
60
|
-
* Render a nested value (object or array) as indented tree lines.
|
|
61
|
-
*/
|
|
62
52
|
function renderNestedValue(val, action, indent) {
|
|
63
53
|
const lines = [];
|
|
64
54
|
const style = getActionStyle(action);
|
|
@@ -103,9 +93,6 @@ function renderNestedObject(obj, action, indent) {
|
|
|
103
93
|
}
|
|
104
94
|
return lines;
|
|
105
95
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Get the symbol and color for an action.
|
|
108
|
-
*/
|
|
109
96
|
function getActionStyle(action) {
|
|
110
97
|
switch (action) {
|
|
111
98
|
case "add":
|
|
@@ -166,9 +153,6 @@ function renderLeafNode(child, style, indentStr, indent) {
|
|
|
166
153
|
}
|
|
167
154
|
return [renderSimpleLeaf(child, style, indentStr)];
|
|
168
155
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Recursively render tree nodes to formatted lines.
|
|
171
|
-
*/
|
|
172
156
|
function renderTree(node, indent = 0) {
|
|
173
157
|
const lines = [];
|
|
174
158
|
const indentStr = " ".repeat(indent);
|
|
@@ -178,7 +162,6 @@ function renderTree(node, indent = 0) {
|
|
|
178
162
|
: { symbol: " ", color: chalk.gray };
|
|
179
163
|
const hasChildren = child.children.size > 0;
|
|
180
164
|
if (hasChildren) {
|
|
181
|
-
// Intermediate node
|
|
182
165
|
lines.push(style.color(`${indentStr}${style.symbol} ${child.name}:`));
|
|
183
166
|
lines.push(...renderTree(child, indent + 1));
|
|
184
167
|
}
|
|
@@ -188,9 +171,6 @@ function renderTree(node, indent = 0) {
|
|
|
188
171
|
}
|
|
189
172
|
return lines;
|
|
190
173
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Format property diffs as an indented tree structure.
|
|
193
|
-
*/
|
|
194
174
|
export function formatPropertyTree(diffs) {
|
|
195
175
|
if (diffs.length === 0) {
|
|
196
176
|
return [];
|
|
@@ -198,22 +178,14 @@ export function formatPropertyTree(diffs) {
|
|
|
198
178
|
const tree = buildTree(diffs);
|
|
199
179
|
return renderTree(tree);
|
|
200
180
|
}
|
|
201
|
-
/**
|
|
202
|
-
* Format a full ruleset config as tree lines (for create action).
|
|
203
|
-
* Delegates to renderNestedObject which handles recursive rendering.
|
|
204
|
-
*/
|
|
205
181
|
function formatFullConfig(ruleset, indent = 2) {
|
|
206
182
|
// Object.entries works on any object; the cast avoids a double assertion
|
|
207
183
|
const entries = Object.entries(ruleset);
|
|
208
184
|
return renderNestedObject(Object.fromEntries(entries), "add", indent);
|
|
209
185
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Format ruleset changes as a Terraform-style plan.
|
|
212
|
-
*/
|
|
213
186
|
export function formatRulesetPlan(changes) {
|
|
214
187
|
const lines = [];
|
|
215
188
|
const entries = [];
|
|
216
|
-
// Group by action in a single pass
|
|
217
189
|
const grouped = {
|
|
218
190
|
create: [],
|
|
219
191
|
update: [],
|
|
@@ -227,7 +199,7 @@ export function formatRulesetPlan(changes) {
|
|
|
227
199
|
lines.push(chalk.bold(" Create:"));
|
|
228
200
|
}
|
|
229
201
|
for (const change of grouped.create) {
|
|
230
|
-
lines.push(chalk.green(` + ruleset
|
|
202
|
+
lines.push(chalk.green(` + ruleset ${quoted(change.name)}`));
|
|
231
203
|
if (change.desired) {
|
|
232
204
|
lines.push(...formatFullConfig(change.desired, 2));
|
|
233
205
|
}
|
|
@@ -246,7 +218,7 @@ export function formatRulesetPlan(changes) {
|
|
|
246
218
|
lines.push(chalk.bold(" Update:"));
|
|
247
219
|
}
|
|
248
220
|
for (const change of grouped.update) {
|
|
249
|
-
lines.push(chalk.yellow(` ~ ruleset
|
|
221
|
+
lines.push(chalk.yellow(` ~ ruleset ${quoted(change.name)}`));
|
|
250
222
|
if (change.current && change.desired) {
|
|
251
223
|
const currentNorm = normalizeRuleset(change.current);
|
|
252
224
|
const desiredNorm = normalizeRuleset(change.desired);
|
|
@@ -274,7 +246,7 @@ export function formatRulesetPlan(changes) {
|
|
|
274
246
|
if (grouped.delete.length > 0) {
|
|
275
247
|
lines.push(chalk.bold(" Delete:"));
|
|
276
248
|
for (const change of grouped.delete) {
|
|
277
|
-
lines.push(chalk.red(` - ruleset
|
|
249
|
+
lines.push(chalk.red(` - ruleset ${quoted(change.name)}`));
|
|
278
250
|
entries.push({ name: change.name, action: "delete" });
|
|
279
251
|
}
|
|
280
252
|
lines.push("");
|