@aspruyt/xfg 7.2.0 → 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
|
@@ -18,21 +18,17 @@ function cloneContent(content) {
|
|
|
18
18
|
* or root file with no content and no repo override).
|
|
19
19
|
*/
|
|
20
20
|
function resolveFileContent(rootContent, repoOverride, mergeStrategy) {
|
|
21
|
-
// Override mode: use only repo content
|
|
22
21
|
if (repoOverride?.override) {
|
|
23
22
|
return repoOverride.content !== undefined
|
|
24
23
|
? cloneContent(repoOverride.content)
|
|
25
24
|
: null;
|
|
26
25
|
}
|
|
27
|
-
// Root has no content — use repo content if provided, otherwise empty
|
|
28
26
|
if (rootContent === undefined) {
|
|
29
27
|
return repoOverride?.content ? cloneContent(repoOverride.content) : null;
|
|
30
28
|
}
|
|
31
|
-
// No repo override — use root content as-is
|
|
32
29
|
if (!repoOverride?.content) {
|
|
33
30
|
return structuredClone(rootContent);
|
|
34
31
|
}
|
|
35
|
-
// Both exist — merge
|
|
36
32
|
return mergeContentPair(rootContent, repoOverride.content, mergeStrategy);
|
|
37
33
|
}
|
|
38
34
|
/**
|
|
@@ -48,7 +44,6 @@ function mergeContentPair(base, overlay, strategy) {
|
|
|
48
44
|
const merged = deepMerge(structuredClone(base), overlay, ctx);
|
|
49
45
|
return stripMergeDirectives(merged);
|
|
50
46
|
}
|
|
51
|
-
// Type mismatch — overlay wins
|
|
52
47
|
return overlay;
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
@@ -79,10 +74,25 @@ function mergePROptions(global, perRepo) {
|
|
|
79
74
|
return perRepo;
|
|
80
75
|
if (!perRepo)
|
|
81
76
|
return global;
|
|
82
|
-
const
|
|
77
|
+
const lastAi = typeof global.ai === "object" ? global.ai : global.lastAi;
|
|
78
|
+
const merged = { ...global, ...perRepo, lastAi: undefined };
|
|
79
|
+
if (merged.ai === true && lastAi)
|
|
80
|
+
merged.ai = lastAi;
|
|
81
|
+
if (merged.ai === false)
|
|
82
|
+
merged.lastAi = lastAi;
|
|
83
83
|
const result = Object.fromEntries(Object.entries(merged).filter(([, v]) => v !== undefined));
|
|
84
84
|
return Object.keys(result).length > 0 ? result : undefined;
|
|
85
85
|
}
|
|
86
|
+
function normalizeAiOption(prOptions) {
|
|
87
|
+
if (prOptions === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
const { ai, lastAi: _lastAi, ...rest } = prOptions;
|
|
90
|
+
if (ai === true)
|
|
91
|
+
return { ...rest, ai: { provider: "anthropic" } };
|
|
92
|
+
if (ai)
|
|
93
|
+
return { ...rest, ai: { ...ai, provider: ai.provider ?? "anthropic" } };
|
|
94
|
+
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
95
|
+
}
|
|
86
96
|
/**
|
|
87
97
|
* Deep merges two rulesets: per-repo values override root values.
|
|
88
98
|
*/
|
|
@@ -193,7 +203,6 @@ export function mergeSettings(root, perRepo) {
|
|
|
193
203
|
if (!root && !perRepo)
|
|
194
204
|
return undefined;
|
|
195
205
|
const result = {};
|
|
196
|
-
// Merge rulesets by name - each ruleset is deep merged
|
|
197
206
|
const rootRulesets = root?.rulesets ?? {};
|
|
198
207
|
const repoRulesets = perRepo?.rulesets ?? {};
|
|
199
208
|
const inheritRulesets = shouldInherit(repoRulesets);
|
|
@@ -206,23 +215,19 @@ export function mergeSettings(root, perRepo) {
|
|
|
206
215
|
for (const name of allRulesetNames) {
|
|
207
216
|
const rootRuleset = rootRulesets[name];
|
|
208
217
|
const repoRuleset = repoRulesets[name];
|
|
209
|
-
// Skip if repo explicitly opts out of this ruleset
|
|
210
218
|
if (repoRuleset === false) {
|
|
211
219
|
continue;
|
|
212
220
|
}
|
|
213
|
-
// Skip root rulesets if inherit: false (unless repo has override)
|
|
214
221
|
if (!inheritRulesets && !repoRuleset && rootRuleset) {
|
|
215
222
|
continue;
|
|
216
223
|
}
|
|
217
224
|
const merged = mergeRuleset(rootRuleset, repoRuleset);
|
|
218
225
|
result.rulesets[name] = stripMergeDirectives(merged);
|
|
219
226
|
}
|
|
220
|
-
// Clean up empty rulesets object
|
|
221
227
|
if (Object.keys(result.rulesets).length === 0) {
|
|
222
228
|
delete result.rulesets;
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
|
-
// deleteOrphaned: per-repo overrides root
|
|
226
231
|
const deleteOrphaned = perRepo?.deleteOrphaned !== undefined
|
|
227
232
|
? perRepo.deleteOrphaned
|
|
228
233
|
: root?.deleteOrphaned;
|
|
@@ -244,7 +249,6 @@ export function mergeSettings(root, perRepo) {
|
|
|
244
249
|
};
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
|
-
// Merge labels by name
|
|
248
252
|
const mergedLabels = mergeLabels(root?.labels, perRepo?.labels);
|
|
249
253
|
if (mergedLabels) {
|
|
250
254
|
result.labels = mergedLabels;
|
|
@@ -386,13 +390,11 @@ function mergeRawSettings(base, overlay) {
|
|
|
386
390
|
if (!overlay)
|
|
387
391
|
return structuredClone(base);
|
|
388
392
|
const result = base ? structuredClone(base) : {};
|
|
389
|
-
// Merge rulesets
|
|
390
393
|
if (overlay.rulesets) {
|
|
391
394
|
result.rulesets = mergeNamedEntries(result.rulesets, overlay.rulesets, (existing, entry) => existing && typeof existing === "object"
|
|
392
395
|
? mergeRuleset(existing, entry)
|
|
393
396
|
: structuredClone(entry));
|
|
394
397
|
}
|
|
395
|
-
// Merge repo settings: overlay replaces base (shallow merge, same as mergeSettings)
|
|
396
398
|
if (overlay.repo !== undefined) {
|
|
397
399
|
if (overlay.repo === false) {
|
|
398
400
|
result.repo = false;
|
|
@@ -404,7 +406,6 @@ function mergeRawSettings(base, overlay) {
|
|
|
404
406
|
};
|
|
405
407
|
}
|
|
406
408
|
}
|
|
407
|
-
// Merge labels
|
|
408
409
|
if (overlay.labels) {
|
|
409
410
|
result.labels = mergeNamedEntries(result.labels, overlay.labels, (existing, entry) => ({
|
|
410
411
|
...(existing && typeof existing === "object" ? existing : {}),
|
|
@@ -426,7 +427,6 @@ function mergeRawSettings(base, overlay) {
|
|
|
426
427
|
if (overlay.secrets) {
|
|
427
428
|
result.secrets = mergeEntryMapLayer(result.secrets, overlay.secrets);
|
|
428
429
|
}
|
|
429
|
-
// deleteOrphaned: overlay wins
|
|
430
430
|
if (overlay.deleteOrphaned !== undefined) {
|
|
431
431
|
result.deleteOrphaned = overlay.deleteOrphaned;
|
|
432
432
|
}
|
|
@@ -452,7 +452,6 @@ function mergeGroupSettings(rootSettings, groupNames, groupDefs) {
|
|
|
452
452
|
* Absent conditions are treated as satisfied.
|
|
453
453
|
*/
|
|
454
454
|
function evaluateWhenClause(when, effectiveGroups) {
|
|
455
|
-
// Defensive: if no condition is specified, don't match
|
|
456
455
|
if (!when.allOf && !when.anyOf && !when.noneOf)
|
|
457
456
|
return false;
|
|
458
457
|
const allOfSatisfied = !when.allOf || when.allOf.every((g) => effectiveGroups.has(g));
|
|
@@ -477,11 +476,9 @@ function mergeConditionalGroups(accumulatedFiles, accumulatedPROptions, accumula
|
|
|
477
476
|
if (cg.files) {
|
|
478
477
|
files = applyFileLayer(files, cg.files);
|
|
479
478
|
}
|
|
480
|
-
// Merge prOptions
|
|
481
479
|
if (cg.prOptions) {
|
|
482
480
|
prOptions = mergePROptions(prOptions, cg.prOptions);
|
|
483
481
|
}
|
|
484
|
-
// Merge settings
|
|
485
482
|
if (cg.settings) {
|
|
486
483
|
settings = mergeRawSettings(settings, cg.settings);
|
|
487
484
|
}
|
|
@@ -536,7 +533,7 @@ function normalizeRepoEntry(ctx) {
|
|
|
536
533
|
if (entry)
|
|
537
534
|
files.push(entry);
|
|
538
535
|
}
|
|
539
|
-
const prOptions = mergePROptions(ctx.effectivePROptions, ctx.rawRepo.prOptions);
|
|
536
|
+
const prOptions = normalizeAiOption(mergePROptions(ctx.effectivePROptions, ctx.rawRepo.prOptions));
|
|
540
537
|
const settings = mergeSettings(ctx.effectiveSettings, ctx.rawRepo.settings);
|
|
541
538
|
return {
|
|
542
539
|
git: ctx.gitUrl,
|
|
@@ -555,11 +552,9 @@ export function normalizeConfig(raw, env) {
|
|
|
555
552
|
const expandedRepos = [];
|
|
556
553
|
for (const rawRepo of raw.repos) {
|
|
557
554
|
const gitUrls = Array.isArray(rawRepo.git) ? rawRepo.git : [rawRepo.git];
|
|
558
|
-
// Phase 0: Expand extends chains
|
|
559
555
|
const expandedGroups = rawRepo.groups?.length
|
|
560
556
|
? expandRepoGroups(rawRepo.groups, raw.groups ?? {})
|
|
561
557
|
: [];
|
|
562
|
-
// Phase 1: Resolve groups - build effective root files/prOptions/settings by merging group layers
|
|
563
558
|
let effectiveRootFiles = expandedGroups.length
|
|
564
559
|
? mergeGroupFiles(raw.files ?? {}, expandedGroups, raw.groups ?? {})
|
|
565
560
|
: (raw.files ?? {});
|
|
@@ -569,7 +564,6 @@ export function normalizeConfig(raw, env) {
|
|
|
569
564
|
let effectiveSettings = expandedGroups.length
|
|
570
565
|
? mergeGroupSettings(raw.settings, expandedGroups, raw.groups ?? {})
|
|
571
566
|
: raw.settings;
|
|
572
|
-
// Phase 2 + 3: Evaluate and merge conditional groups
|
|
573
567
|
if (raw.conditionalGroups?.length) {
|
|
574
568
|
const effectiveGroups = new Set(expandedGroups);
|
|
575
569
|
const merged = mergeConditionalGroups(effectiveRootFiles, effectivePROptions, effectiveSettings, effectiveGroups, raw.conditionalGroups);
|
|
@@ -578,7 +572,6 @@ export function normalizeConfig(raw, env) {
|
|
|
578
572
|
effectiveSettings = merged.settings;
|
|
579
573
|
}
|
|
580
574
|
const fileNames = Object.keys(effectiveRootFiles);
|
|
581
|
-
// Collect repo-only file names (defined at repo level but not in root/groups)
|
|
582
575
|
const repoOnlyFileNames = [];
|
|
583
576
|
if (rawRepo.files) {
|
|
584
577
|
for (const name of Object.keys(rawRepo.files)) {
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { ArrayMergeStrategy } from "./merge.js";
|
|
2
2
|
export type MergeMode = "manual" | "auto" | "force" | "direct";
|
|
3
3
|
export type MergeStrategy = "merge" | "squash" | "rebase";
|
|
4
|
+
export type AiProvider = "anthropic" | "openai";
|
|
5
|
+
export interface AiConfig {
|
|
6
|
+
provider?: AiProvider;
|
|
7
|
+
model?: string;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
apiKeyEnv?: string;
|
|
10
|
+
prompt?: string;
|
|
11
|
+
maxDiffChars?: number;
|
|
12
|
+
}
|
|
13
|
+
export type ResolvedAiConfig = AiConfig & {
|
|
14
|
+
provider: AiProvider;
|
|
15
|
+
};
|
|
4
16
|
export interface PRMergeOptions {
|
|
5
17
|
merge?: MergeMode;
|
|
6
18
|
mergeStrategy?: MergeStrategy;
|
|
@@ -8,7 +20,11 @@ export interface PRMergeOptions {
|
|
|
8
20
|
bypassReason?: string;
|
|
9
21
|
labels?: string[];
|
|
10
22
|
branch?: string;
|
|
23
|
+
ai?: boolean | AiConfig;
|
|
11
24
|
}
|
|
25
|
+
export type RepoPROptions = Omit<PRMergeOptions, "ai"> & {
|
|
26
|
+
ai?: ResolvedAiConfig;
|
|
27
|
+
};
|
|
12
28
|
export type RulesetTarget = "branch" | "tag";
|
|
13
29
|
export type RulesetEnforcement = "active" | "disabled" | "evaluate";
|
|
14
30
|
export type BypassActorType = "Team" | "User" | "Integration";
|
|
@@ -415,7 +431,7 @@ export interface FileContent {
|
|
|
415
431
|
export interface RepoConfig {
|
|
416
432
|
git: string;
|
|
417
433
|
files: FileContent[];
|
|
418
|
-
prOptions?:
|
|
434
|
+
prOptions?: RepoPROptions;
|
|
419
435
|
settings?: RepoSettings;
|
|
420
436
|
/** Fork upstream repo if target doesn't exist */
|
|
421
437
|
upstream?: string;
|
package/dist/config/validator.js
CHANGED
|
@@ -2,6 +2,7 @@ import { validateFileName } from "./validators/file-validator.js";
|
|
|
2
2
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
3
3
|
import { ValidationError } from "../shared/errors.js";
|
|
4
4
|
import { validateBranchName } from "../shared/branch-validation.js";
|
|
5
|
+
import { validateAiOption } from "./validators/ai-validator.js";
|
|
5
6
|
import { validateFileConfigFields, validateSettings, } from "./validators/shared.js";
|
|
6
7
|
import { validateGroups, validateConditionalGroups, } from "./validators/group-validator.js";
|
|
7
8
|
import { validateRepoEntry } from "./validators/repo-entry-validator.js";
|
|
@@ -92,6 +93,7 @@ function validatePrOptions(config) {
|
|
|
92
93
|
if (config.prOptions?.branch !== undefined) {
|
|
93
94
|
validateBranchName(config.prOptions.branch);
|
|
94
95
|
}
|
|
96
|
+
validateAiOption(config.prOptions?.ai);
|
|
95
97
|
if (config.prOptions?.labels === undefined)
|
|
96
98
|
return;
|
|
97
99
|
if (!Array.isArray(config.prOptions.labels)) {
|
|
@@ -200,7 +202,6 @@ export function validateForSync(config) {
|
|
|
200
202
|
"Use 'files' to sync configuration files, or 'settings' to manage repository settings. " +
|
|
201
203
|
"For secrets, use 'xfg secrets sync'.");
|
|
202
204
|
}
|
|
203
|
-
// Validate variable names across all settings
|
|
204
205
|
for (const settings of collectAllSettings(config)) {
|
|
205
206
|
if (!settings?.variables)
|
|
206
207
|
continue;
|
|
@@ -220,7 +221,6 @@ export function validateForSync(config) {
|
|
|
220
221
|
throw new ValidationError(`Variable '${name}' must have a string value (got ${typeof value}). Quote numeric values in YAML: "${String(value)}".`);
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
|
-
// Reject duplicate case-insensitive variable names
|
|
224
224
|
const seenVarNames = new Map();
|
|
225
225
|
for (const name of Object.keys(settings.variables)) {
|
|
226
226
|
if (VARIABLE_RESERVED_KEYS.has(name))
|
|
@@ -233,7 +233,6 @@ export function validateForSync(config) {
|
|
|
233
233
|
seenVarNames.set(upper, name);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
// Validate secret names and configs
|
|
237
236
|
validateSecretsConfig(config);
|
|
238
237
|
}
|
|
239
238
|
const ENTRY_MAP_META_KEYS = new Set(["deleteOrphaned", "inherit"]);
|
|
@@ -321,7 +320,6 @@ function validateSecretsLayer(secrets) {
|
|
|
321
320
|
if (inherit !== undefined && typeof inherit !== "boolean") {
|
|
322
321
|
throw new ValidationError("'inherit' is a reserved key in secrets config and cannot be used as a secret name.");
|
|
323
322
|
}
|
|
324
|
-
// Reject duplicate case-insensitive secret names
|
|
325
323
|
const seen = new Map();
|
|
326
324
|
for (const name of Object.keys(secrets)) {
|
|
327
325
|
if (SECRET_RESERVED_KEYS.has(name))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateAiOption(ai: unknown): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isPlainObject } from "../../shared/type-guards.js";
|
|
2
|
+
import { ValidationError } from "../../shared/errors.js";
|
|
3
|
+
const VALID_PROVIDERS = ["anthropic", "openai"];
|
|
4
|
+
const STRING_FIELDS = ["model", "baseUrl", "apiKeyEnv", "prompt"];
|
|
5
|
+
const KNOWN_KEYS = new Set([
|
|
6
|
+
"provider",
|
|
7
|
+
"maxDiffChars",
|
|
8
|
+
...STRING_FIELDS,
|
|
9
|
+
]);
|
|
10
|
+
export function validateAiOption(ai) {
|
|
11
|
+
if (ai === undefined || typeof ai === "boolean")
|
|
12
|
+
return;
|
|
13
|
+
if (!isPlainObject(ai)) {
|
|
14
|
+
throw new ValidationError("prOptions.ai must be a boolean or an object");
|
|
15
|
+
}
|
|
16
|
+
const unknown = Object.keys(ai).find((key) => !KNOWN_KEYS.has(key));
|
|
17
|
+
if (unknown !== undefined) {
|
|
18
|
+
throw new ValidationError(`prOptions.ai has unknown key '${unknown}'`);
|
|
19
|
+
}
|
|
20
|
+
const provider = ai.provider;
|
|
21
|
+
if (provider !== undefined &&
|
|
22
|
+
!VALID_PROVIDERS.includes(provider)) {
|
|
23
|
+
throw new ValidationError(`prOptions.ai.provider must be one of: ${VALID_PROVIDERS.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
for (const field of STRING_FIELDS) {
|
|
26
|
+
const value = ai[field];
|
|
27
|
+
if (value !== undefined && (typeof value !== "string" || value === "")) {
|
|
28
|
+
throw new ValidationError(`prOptions.ai.${field} must be a non-empty string`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (provider === "openai" && ai.model === undefined) {
|
|
32
|
+
throw new ValidationError("prOptions.ai.model is required when provider is 'openai'");
|
|
33
|
+
}
|
|
34
|
+
const max = ai.maxDiffChars;
|
|
35
|
+
if (max !== undefined &&
|
|
36
|
+
(typeof max !== "number" || !Number.isInteger(max) || max <= 0)) {
|
|
37
|
+
throw new ValidationError("prOptions.ai.maxDiffChars must be a positive integer");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -2,6 +2,7 @@ import { resolveExtendsChain } from "../extends-resolver.js";
|
|
|
2
2
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
3
3
|
import { ValidationError } from "../../shared/errors.js";
|
|
4
4
|
import { validateBranchName } from "../../shared/branch-validation.js";
|
|
5
|
+
import { validateAiOption } from "./ai-validator.js";
|
|
5
6
|
import { validateFileConfigFields, validateSettings, buildRootSettingsContext, } from "./shared.js";
|
|
6
7
|
function validateGroupExtends(groupName, extends_, groupNames) {
|
|
7
8
|
if (typeof extends_ === "string") {
|
|
@@ -106,6 +107,7 @@ export function validateGroups(config) {
|
|
|
106
107
|
if (group.prOptions?.branch !== undefined) {
|
|
107
108
|
validateBranchName(group.prOptions.branch);
|
|
108
109
|
}
|
|
110
|
+
validateAiOption(group.prOptions?.ai);
|
|
109
111
|
}
|
|
110
112
|
validateNoCircularExtends(config.groups);
|
|
111
113
|
}
|
|
@@ -170,5 +172,6 @@ export function validateConditionalGroups(config) {
|
|
|
170
172
|
if (entry.prOptions?.branch !== undefined) {
|
|
171
173
|
validateBranchName(entry.prOptions.branch);
|
|
172
174
|
}
|
|
175
|
+
validateAiOption(entry.prOptions?.ai);
|
|
173
176
|
}
|
|
174
177
|
}
|
|
@@ -4,6 +4,7 @@ import { isPlainObject } from "../../shared/type-guards.js";
|
|
|
4
4
|
import { escapeRegExp } from "../../shared/regex-utils.js";
|
|
5
5
|
import { ValidationError } from "../../shared/errors.js";
|
|
6
6
|
import { validateBranchName } from "../../shared/branch-validation.js";
|
|
7
|
+
import { validateAiOption } from "./ai-validator.js";
|
|
7
8
|
import { validateFileConfigFields, validateSettings, buildRootSettingsContext, enrichSettingsContext, } from "./shared.js";
|
|
8
9
|
function isValidGitUrl(url) {
|
|
9
10
|
return /^git@[^:]+:.+$/.test(url) || /^https?:\/\/[^/]+\/.+$/.test(url);
|
|
@@ -161,6 +162,7 @@ function validateRepoPrOptions(repo) {
|
|
|
161
162
|
if (repo.prOptions?.branch !== undefined) {
|
|
162
163
|
validateBranchName(repo.prOptions.branch);
|
|
163
164
|
}
|
|
165
|
+
validateAiOption(repo.prOptions?.ai);
|
|
164
166
|
}
|
|
165
167
|
export function validateRepoEntry(config, repo, index) {
|
|
166
168
|
const repoLabel = validateRepoGitField(repo, index);
|
|
@@ -8,9 +8,5 @@ interface FormatOptions {
|
|
|
8
8
|
description?: string;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Format lifecycle action for output (used in both dry-run and real execution).
|
|
13
|
-
* Returns empty array if action is "existed" (no output needed).
|
|
14
|
-
*/
|
|
15
11
|
export declare function formatLifecycleAction(result: LifecycleResult, options?: FormatOptions): string[];
|
|
16
12
|
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { getRepoDisplayName } from "../repo/index.js";
|
|
3
3
|
import { SyncError } from "../shared/errors.js";
|
|
4
|
-
|
|
5
|
-
* Format lifecycle action for output (used in both dry-run and real execution).
|
|
6
|
-
* Returns empty array if action is "existed" (no output needed).
|
|
7
|
-
*/
|
|
4
|
+
import { quoted } from "../shared/string-utils.js";
|
|
8
5
|
export function formatLifecycleAction(result, options) {
|
|
9
6
|
if (result.action === "existed") {
|
|
10
7
|
return [];
|
|
@@ -26,13 +23,12 @@ export function formatLifecycleAction(result, options) {
|
|
|
26
23
|
throw new SyncError(`Unknown lifecycle action: ${_exhaustive}`);
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
// Add settings details if provided
|
|
30
26
|
if (options?.settings) {
|
|
31
27
|
if (options.settings.visibility) {
|
|
32
28
|
lines.push(` visibility: ${options.settings.visibility}`);
|
|
33
29
|
}
|
|
34
30
|
if (options.settings.description) {
|
|
35
|
-
lines.push(` description:
|
|
31
|
+
lines.push(` description: ${quoted(options.settings.description)}`);
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
34
|
return lines;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DebugLog } from "../shared/logger.js";
|
|
2
|
+
export declare const STEP_SUMMARY_MAX_BYTES: number;
|
|
2
3
|
/**
|
|
3
|
-
* Append markdown
|
|
4
|
-
*
|
|
4
|
+
* Append markdown to GITHUB_STEP_SUMMARY. Never throws: the summary is best effort.
|
|
5
|
+
* render gets the bytes left: the 1 MiB limit covers everything already in this step's file.
|
|
5
6
|
*/
|
|
6
|
-
export declare function writeGitHubStepSummary(
|
|
7
|
+
export declare function writeGitHubStepSummary(render: (maxBytes: number) => string, summaryPath: string | undefined, log?: DebugLog): void;
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import { appendFileSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, closeSync, fstatSync, openSync } from "node:fs";
|
|
2
2
|
import { toErrorMessage } from "../shared/type-guards.js";
|
|
3
|
+
export const STEP_SUMMARY_MAX_BYTES = 1024 * 1024;
|
|
3
4
|
/**
|
|
4
|
-
* Append markdown
|
|
5
|
-
*
|
|
5
|
+
* Append markdown to GITHUB_STEP_SUMMARY. Never throws: the summary is best effort.
|
|
6
|
+
* render gets the bytes left: the 1 MiB limit covers everything already in this step's file.
|
|
6
7
|
*/
|
|
7
|
-
export function writeGitHubStepSummary(
|
|
8
|
+
export function writeGitHubStepSummary(render, summaryPath, log) {
|
|
8
9
|
if (!summaryPath)
|
|
9
10
|
return;
|
|
11
|
+
let fd;
|
|
10
12
|
try {
|
|
11
|
-
|
|
13
|
+
fd = openSync(summaryPath, "a");
|
|
14
|
+
const maxBytes = STEP_SUMMARY_MAX_BYTES - fstatSync(fd).size - 2;
|
|
15
|
+
const markdown = render(maxBytes);
|
|
16
|
+
if (markdown && Buffer.byteLength(markdown) <= maxBytes) {
|
|
17
|
+
appendFileSync(fd, "\n" + markdown + "\n");
|
|
18
|
+
}
|
|
19
|
+
closeSync(fd);
|
|
20
|
+
fd = undefined;
|
|
12
21
|
}
|
|
13
22
|
catch (error) {
|
|
14
23
|
log?.debug(`Failed to write GitHub step summary: ${toErrorMessage(error)}`);
|
|
24
|
+
if (fd !== undefined) {
|
|
25
|
+
try {
|
|
26
|
+
closeSync(fd);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Already reporting the first error.
|
|
30
|
+
}
|
|
31
|
+
}
|
|
15
32
|
}
|
|
16
33
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DebugLog } from "../shared/logger.js";
|
|
1
2
|
import type { LifecycleActionKind } from "../lifecycle/index.js";
|
|
2
3
|
import type { RepoVisibility } from "../config/index.js";
|
|
3
4
|
export interface LifecycleReport {
|
|
@@ -21,5 +22,5 @@ export interface LifecycleAction {
|
|
|
21
22
|
}
|
|
22
23
|
export declare function hasLifecycleChanges(report: LifecycleReport): boolean;
|
|
23
24
|
export declare function formatLifecycleReportCLI(report: LifecycleReport): string[];
|
|
24
|
-
export declare function formatLifecycleReportMarkdown(report: LifecycleReport, dryRun: boolean): string;
|
|
25
|
-
export declare function writeLifecycleReportSummary(report: LifecycleReport, dryRun: boolean, summaryPath: string | undefined): void;
|
|
25
|
+
export declare function formatLifecycleReportMarkdown(report: LifecycleReport, dryRun: boolean, maxBytes?: number): string;
|
|
26
|
+
export declare function writeLifecycleReportSummary(report: LifecycleReport, dryRun: boolean, summaryPath: string | undefined, log?: DebugLog): void;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import { writeGitHubStepSummary } from "./github-summary.js";
|
|
2
|
+
import { STEP_SUMMARY_MAX_BYTES, writeGitHubStepSummary, } from "./github-summary.js";
|
|
3
|
+
import { fitSummary, summaryHeader } from "./summary-budget.js";
|
|
3
4
|
import { formatCountEntry } from "../shared/count-format.js";
|
|
5
|
+
import { quoted } from "../shared/string-utils.js";
|
|
4
6
|
function formatLifecycleSummary(totals) {
|
|
5
7
|
const entry = formatCountEntry("repo", "repos", [
|
|
6
8
|
{ label: "to create", value: totals.created },
|
|
@@ -38,7 +40,7 @@ function renderActionDiffLines(actions) {
|
|
|
38
40
|
lines.push(` visibility: ${action.settings.visibility}`);
|
|
39
41
|
}
|
|
40
42
|
if (action.settings.description) {
|
|
41
|
-
lines.push(` description:
|
|
43
|
+
lines.push(` description: ${quoted(action.settings.description)}`);
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -53,32 +55,24 @@ export function formatLifecycleReportCLI(report) {
|
|
|
53
55
|
lines.push(formatLifecycleSummary(report.totals));
|
|
54
56
|
return lines;
|
|
55
57
|
}
|
|
56
|
-
export function formatLifecycleReportMarkdown(report, dryRun) {
|
|
58
|
+
export function formatLifecycleReportMarkdown(report, dryRun, maxBytes = STEP_SUMMARY_MAX_BYTES) {
|
|
57
59
|
if (!hasLifecycleChanges(report)) {
|
|
58
60
|
return "";
|
|
59
61
|
}
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
lines.push("```");
|
|
74
|
-
lines.push("");
|
|
75
|
-
}
|
|
76
|
-
lines.push(`**${formatLifecycleSummary(report.totals)}**`);
|
|
77
|
-
return lines.join("\n");
|
|
62
|
+
const title = `## Lifecycle Summary${dryRun ? " (Dry Run)" : ""}`;
|
|
63
|
+
return fitSummary({
|
|
64
|
+
header: summaryHeader(dryRun, title),
|
|
65
|
+
blocks: [
|
|
66
|
+
{
|
|
67
|
+
diffLines: renderActionDiffLines(report.actions),
|
|
68
|
+
repos: report.actions
|
|
69
|
+
.filter((a) => a.action !== "existed")
|
|
70
|
+
.map((a) => a.repoName),
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
footer: `**${formatLifecycleSummary(report.totals)}**`,
|
|
74
|
+
}, maxBytes);
|
|
78
75
|
}
|
|
79
|
-
export function writeLifecycleReportSummary(report, dryRun, summaryPath) {
|
|
80
|
-
|
|
81
|
-
if (!markdown)
|
|
82
|
-
return;
|
|
83
|
-
writeGitHubStepSummary(markdown, summaryPath);
|
|
76
|
+
export function writeLifecycleReportSummary(report, dryRun, summaryPath, log) {
|
|
77
|
+
writeGitHubStepSummary((maxBytes) => formatLifecycleReportMarkdown(report, dryRun, maxBytes), summaryPath, log);
|
|
84
78
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PropertyDiff, ActiveAction, SecretsPlanEntry } from "../settings/index.js";
|
|
2
2
|
import type { Ruleset, Label } from "../config/index.js";
|
|
3
|
+
import type { DebugLog } from "../shared/logger.js";
|
|
3
4
|
export interface SettingsReport {
|
|
4
5
|
repos: RepoChanges[];
|
|
5
6
|
totals: {
|
|
@@ -70,5 +71,5 @@ export interface LabelChange {
|
|
|
70
71
|
export declare function formatSettingsCountEntries(totals: SettingsReport["totals"], dryRun: boolean): string[];
|
|
71
72
|
export declare function formatSettingsReportCLI(report: SettingsReport): string[];
|
|
72
73
|
export declare function renderRepoSettingsDiffLines(repo: RepoChanges, diffLines: string[]): void;
|
|
73
|
-
export declare function formatSettingsReportMarkdown(report: SettingsReport, dryRun: boolean): string;
|
|
74
|
-
export declare function writeSettingsReportSummary(report: SettingsReport, dryRun: boolean, summaryPath: string | undefined): void;
|
|
74
|
+
export declare function formatSettingsReportMarkdown(report: SettingsReport, dryRun: boolean, maxBytes?: number): string;
|
|
75
|
+
export declare function writeSettingsReportSummary(report: SettingsReport, dryRun: boolean, summaryPath: string | undefined, log?: DebugLog): void;
|