@aspruyt/xfg 7.2.1 → 7.4.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/settings-factories.d.ts +2 -1
- package/dist/cli/settings-factories.js +7 -1
- package/dist/cli/settings-report-builder.d.ts +6 -1
- package/dist/cli/settings-report-builder.js +15 -0
- package/dist/cli/settings-runner.js +12 -0
- package/dist/cli/sync-command.js +2 -0
- package/dist/cli/types.d.ts +5 -2
- 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 +49 -27
- package/dist/config/types.d.ts +30 -1
- package/dist/config/validator.js +11 -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/config/validators/shared.js +33 -0
- package/dist/lifecycle/formatter.d.ts +0 -4
- package/dist/lifecycle/formatter.js +2 -6
- package/dist/lifecycle/github-lifecycle-provider.d.ts +1 -0
- package/dist/lifecycle/github-lifecycle-provider.js +30 -14
- 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 +12 -2
- package/dist/output/settings-report.js +49 -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/collaborators/diff.d.ts +17 -0
- package/dist/settings/collaborators/diff.js +64 -0
- package/dist/settings/collaborators/formatter.d.ts +14 -0
- package/dist/settings/collaborators/formatter.js +41 -0
- package/dist/settings/collaborators/github-collaborators-strategy.d.ts +18 -0
- package/dist/settings/collaborators/github-collaborators-strategy.js +43 -0
- package/dist/settings/collaborators/index.d.ts +4 -0
- package/dist/settings/collaborators/index.js +2 -0
- package/dist/settings/collaborators/processor.d.ts +21 -0
- package/dist/settings/collaborators/processor.js +77 -0
- package/dist/settings/collaborators/types.d.ts +19 -0
- package/dist/settings/collaborators/types.js +1 -0
- package/dist/settings/index.d.ts +1 -0
- package/dist/settings/index.js +1 -0
- 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 +4 -2
|
@@ -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;
|
|
@@ -30,6 +30,7 @@ export declare class GitHubLifecycleProvider implements IRepoLifecycleProvider {
|
|
|
30
30
|
*/
|
|
31
31
|
private isOrganization;
|
|
32
32
|
private assertGitHub;
|
|
33
|
+
private assertTokenCanCreateRepo;
|
|
33
34
|
private buildGhApiPrefix;
|
|
34
35
|
exists(params: LifecycleExistsParams): Promise<boolean>;
|
|
35
36
|
create(params: LifecycleCreateParams): Promise<void>;
|
|
@@ -41,6 +41,14 @@ const POST_CREATE_PERMANENT_PATTERNS = [
|
|
|
41
41
|
* Interval between fork readiness checks (2 seconds).
|
|
42
42
|
*/
|
|
43
43
|
const FORK_POLL_INTERVAL_MS = 2_000;
|
|
44
|
+
function isInstallationToken(token) {
|
|
45
|
+
return token?.startsWith("ghs_") ?? false;
|
|
46
|
+
}
|
|
47
|
+
function personalAccountInstallationTokenError(repoInfo) {
|
|
48
|
+
return new LifecycleError(`An installation token (GitHub App or Actions GITHUB_TOKEN) cannot create repositories for personal account '${repoInfo.owner}'. ` +
|
|
49
|
+
`Create ${repoInfo.owner}/${repoInfo.repo} first, or run lifecycle with a personal access token. ` +
|
|
50
|
+
`Installation tokens can only create repositories in organizations.`);
|
|
51
|
+
}
|
|
44
52
|
function buildRepoCreateArgs(args, settings) {
|
|
45
53
|
if (settings?.visibility === "public") {
|
|
46
54
|
args.push("--public");
|
|
@@ -102,11 +110,10 @@ export class GitHubLifecycleProvider {
|
|
|
102
110
|
if (isPermanentError(error)) {
|
|
103
111
|
throw error;
|
|
104
112
|
}
|
|
105
|
-
// This may cause fork to fail with a misleading error for personal accounts.
|
|
106
113
|
const errMsg = toErrorMessage(error);
|
|
107
114
|
this.log?.debug(`Could not determine if '${owner}' is an organization, defaulting to org behavior: ${errMsg}`);
|
|
108
115
|
this.log?.warn(`Could not verify if '${owner}' is an organization or user account. ` +
|
|
109
|
-
`If
|
|
116
|
+
`If the operation fails, check your authentication (gh auth status) and ensure the ` +
|
|
110
117
|
`target owner is correct.`);
|
|
111
118
|
return true;
|
|
112
119
|
}
|
|
@@ -114,6 +121,22 @@ export class GitHubLifecycleProvider {
|
|
|
114
121
|
assertGitHub(repoInfo) {
|
|
115
122
|
assertGitHubRepo(repoInfo, "GitHubLifecycleProvider");
|
|
116
123
|
}
|
|
124
|
+
// GitHub refuses installation tokens on POST /user/repos with a misleading
|
|
125
|
+
// "403 Rate Limit Exceeded", which withRetry treats as transient.
|
|
126
|
+
async assertTokenCanCreateRepo(repoInfo, token) {
|
|
127
|
+
if (!isInstallationToken(token))
|
|
128
|
+
return;
|
|
129
|
+
let isOrg;
|
|
130
|
+
try {
|
|
131
|
+
isOrg = await this.isOrganization(repoInfo.owner, repoInfo, token);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
this.log?.debug(`Skipping installation token owner check for '${repoInfo.owner}': ${toErrorMessage(error)}`);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!isOrg)
|
|
138
|
+
throw personalAccountInstallationTokenError(repoInfo);
|
|
139
|
+
}
|
|
117
140
|
buildGhApiPrefix(repoInfo, token) {
|
|
118
141
|
const tokenEnv = buildTokenEnv(token);
|
|
119
142
|
const hostnameArgs = buildHostnameArgs(repoInfo);
|
|
@@ -135,17 +158,16 @@ export class GitHubLifecycleProvider {
|
|
|
135
158
|
return true;
|
|
136
159
|
}
|
|
137
160
|
catch (error) {
|
|
138
|
-
// Distinguish "repo not found" from actual errors
|
|
139
161
|
if (isRepoNotFoundError(error)) {
|
|
140
162
|
return false;
|
|
141
163
|
}
|
|
142
|
-
// Re-throw network/auth errors
|
|
143
164
|
throw error;
|
|
144
165
|
}
|
|
145
166
|
}
|
|
146
167
|
async create(params) {
|
|
147
168
|
const { repo: repoInfo, settings, token } = params;
|
|
148
169
|
this.assertGitHub(repoInfo);
|
|
170
|
+
await this.assertTokenCanCreateRepo(repoInfo, token);
|
|
149
171
|
const tokenEnv = buildTokenEnv(token);
|
|
150
172
|
const args = [
|
|
151
173
|
"repo",
|
|
@@ -159,10 +181,8 @@ export class GitHubLifecycleProvider {
|
|
|
159
181
|
await withRetry(() => this.executor.exec("gh", args, this.cwd, { env: tokenEnv }), {
|
|
160
182
|
retries: this.retries,
|
|
161
183
|
});
|
|
162
|
-
// Rename default branch if requested and it differs from what GitHub created.
|
|
163
184
|
if (settings?.defaultBranch) {
|
|
164
185
|
const { tokenEnv: branchTokenEnv, baseArgs, apiPath, } = this.buildGhApiPrefix(repoInfo, token);
|
|
165
|
-
// Detect the actual default branch name
|
|
166
186
|
const actualBranch = (await withRetry(() => this.executor.exec("gh", [...baseArgs, apiPath, "--jq", ".default_branch"], this.cwd, { env: branchTokenEnv }), {
|
|
167
187
|
retries: this.retries,
|
|
168
188
|
permanentErrorPatterns: POST_CREATE_PERMANENT_PATTERNS,
|
|
@@ -183,17 +203,15 @@ export class GitHubLifecycleProvider {
|
|
|
183
203
|
const { upstream, target, settings, token } = params;
|
|
184
204
|
this.assertGitHub(upstream);
|
|
185
205
|
this.assertGitHub(target);
|
|
186
|
-
// Guard: cannot fork a repo to the same owner
|
|
187
206
|
if (upstream.owner.toLowerCase() === target.owner.toLowerCase()) {
|
|
188
207
|
throw new LifecycleError(`Cannot fork ${upstream.owner}/${upstream.repo} to the same owner '${target.owner}'. ` +
|
|
189
208
|
`The upstream and target owners must be different.`);
|
|
190
209
|
}
|
|
191
|
-
// Determine if target owner is an organization or user
|
|
192
210
|
const isOrg = await this.isOrganization(target.owner, target, token);
|
|
211
|
+
if (!isOrg && isInstallationToken(token)) {
|
|
212
|
+
throw personalAccountInstallationTokenError(target);
|
|
213
|
+
}
|
|
193
214
|
const tokenEnv = buildTokenEnv(token);
|
|
194
|
-
// Build fork command
|
|
195
|
-
// For orgs: gh repo fork <upstream> --org <target-org> --fork-name <name> --clone=false
|
|
196
|
-
// For users: gh repo fork <upstream> --fork-name <name> --clone=false
|
|
197
215
|
const forkArgs = ["repo", "fork", `${upstream.owner}/${upstream.repo}`];
|
|
198
216
|
if (isOrg) {
|
|
199
217
|
forkArgs.push("--org", target.owner);
|
|
@@ -208,7 +226,6 @@ export class GitHubLifecycleProvider {
|
|
|
208
226
|
pollMs: this.forkPollIntervalMs,
|
|
209
227
|
token,
|
|
210
228
|
});
|
|
211
|
-
// Apply settings after fork (visibility, description, etc.)
|
|
212
229
|
if (settings?.visibility || settings?.description) {
|
|
213
230
|
await this.applyRepoSettings(target, settings, token);
|
|
214
231
|
}
|
|
@@ -263,6 +280,7 @@ export class GitHubLifecycleProvider {
|
|
|
263
280
|
async receiveMigration(params) {
|
|
264
281
|
const { repo: repoInfo, sourceDir, settings, token } = params;
|
|
265
282
|
this.assertGitHub(repoInfo);
|
|
283
|
+
await this.assertTokenCanCreateRepo(repoInfo, token);
|
|
266
284
|
await this.removeOriginRemote(sourceDir);
|
|
267
285
|
await this.cleanNonStandardRefs(sourceDir);
|
|
268
286
|
await this.renameMirrorDefaultBranch(sourceDir, settings?.defaultBranch);
|
|
@@ -378,13 +396,11 @@ export class GitHubLifecycleProvider {
|
|
|
378
396
|
*/
|
|
379
397
|
async deleteReadme(repoInfo, token) {
|
|
380
398
|
const { tokenEnv, baseArgs, apiPath } = this.buildGhApiPrefix(repoInfo, token);
|
|
381
|
-
// Get the SHA of the README.md created by --add-readme
|
|
382
399
|
const fileInfo = await withRetry(() => this.executor.exec("gh", [...baseArgs, `${apiPath}/contents/README.md`, "--jq", ".sha"], this.cwd, { env: tokenEnv }), {
|
|
383
400
|
retries: this.retries,
|
|
384
401
|
permanentErrorPatterns: POST_CREATE_PERMANENT_PATTERNS,
|
|
385
402
|
});
|
|
386
403
|
const sha = fileInfo.trim();
|
|
387
|
-
// Delete the README.md to leave the repo clean
|
|
388
404
|
await withRetry(() => this.executor.exec("gh", [
|
|
389
405
|
...baseArgs,
|
|
390
406
|
`${apiPath}/contents/README.md`,
|
|
@@ -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: {
|
|
@@ -27,6 +28,11 @@ export interface SettingsReport {
|
|
|
27
28
|
update: number;
|
|
28
29
|
delete: number;
|
|
29
30
|
};
|
|
31
|
+
collaborators?: {
|
|
32
|
+
create: number;
|
|
33
|
+
update: number;
|
|
34
|
+
delete: number;
|
|
35
|
+
};
|
|
30
36
|
};
|
|
31
37
|
}
|
|
32
38
|
export interface RepoChanges {
|
|
@@ -41,6 +47,10 @@ export interface RepoChanges {
|
|
|
41
47
|
newValue?: string;
|
|
42
48
|
}[];
|
|
43
49
|
secrets?: SecretsPlanEntry[];
|
|
50
|
+
collaborators?: {
|
|
51
|
+
name: string;
|
|
52
|
+
action: "create" | "delete";
|
|
53
|
+
}[];
|
|
44
54
|
error?: string;
|
|
45
55
|
}
|
|
46
56
|
export declare function hasRepoSettingsChanges(repo: RepoChanges): boolean;
|
|
@@ -70,5 +80,5 @@ export interface LabelChange {
|
|
|
70
80
|
export declare function formatSettingsCountEntries(totals: SettingsReport["totals"], dryRun: boolean): string[];
|
|
71
81
|
export declare function formatSettingsReportCLI(report: SettingsReport): string[];
|
|
72
82
|
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;
|
|
83
|
+
export declare function formatSettingsReportMarkdown(report: SettingsReport, dryRun: boolean, maxBytes?: number): string;
|
|
84
|
+
export declare function writeSettingsReportSummary(report: SettingsReport, dryRun: boolean, summaryPath: string | undefined, log?: DebugLog): void;
|
|
@@ -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 ||
|
|
@@ -8,6 +9,7 @@ export function hasRepoSettingsChanges(repo) {
|
|
|
8
9
|
repo.labels.length > 0 ||
|
|
9
10
|
(repo.variables ?? []).length > 0 ||
|
|
10
11
|
(repo.secrets ?? []).length > 0 ||
|
|
12
|
+
(repo.collaborators ?? []).length > 0 ||
|
|
11
13
|
!!repo.error);
|
|
12
14
|
}
|
|
13
15
|
function renderRulesetConfig(config, startDepth, formatLine) {
|
|
@@ -25,7 +27,7 @@ function renderRulesetConfig(config, startDepth, formatLine) {
|
|
|
25
27
|
lines.push(formatLine(depth, `+ ${key}: []`));
|
|
26
28
|
}
|
|
27
29
|
else if (value.every((v) => typeof v !== "object")) {
|
|
28
|
-
lines.push(formatLine(depth, `+ ${key}: [${value.map(
|
|
30
|
+
lines.push(formatLine(depth, `+ ${key}: [${value.map(formatValuePlain).join(", ")}]`));
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
31
33
|
lines.push(formatLine(depth, `+ ${key}:`));
|
|
@@ -64,6 +66,11 @@ const SETTINGS_CATEGORIES = [
|
|
|
64
66
|
{ noun: "label", plural: "labels", totals: (t) => t.labels },
|
|
65
67
|
{ noun: "variable", plural: "variables", totals: (t) => t.variables },
|
|
66
68
|
{ noun: "secret", plural: "secrets", totals: (t) => t.secrets },
|
|
69
|
+
{
|
|
70
|
+
noun: "collaborator",
|
|
71
|
+
plural: "collaborators",
|
|
72
|
+
totals: (t) => t.collaborators,
|
|
73
|
+
},
|
|
67
74
|
];
|
|
68
75
|
export function formatSettingsCountEntries(totals, dryRun) {
|
|
69
76
|
return SETTINGS_CATEGORIES.flatMap(({ noun, plural, totals: pick }) => {
|
|
@@ -138,13 +145,13 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
138
145
|
if (i > 0)
|
|
139
146
|
diffLines.push("");
|
|
140
147
|
if (ruleset.action === "create") {
|
|
141
|
-
diffLines.push(`+ ruleset
|
|
148
|
+
diffLines.push(`+ ruleset ${quoted(ruleset.name)}`);
|
|
142
149
|
if (ruleset.config) {
|
|
143
150
|
diffLines.push(...formatRulesetConfigPlain(ruleset.config));
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
else if (ruleset.action === "update") {
|
|
147
|
-
diffLines.push(`! ruleset
|
|
154
|
+
diffLines.push(`! ruleset ${quoted(ruleset.name)}`);
|
|
148
155
|
if (ruleset.propertyDiffs && ruleset.propertyDiffs.length > 0) {
|
|
149
156
|
for (const diff of ruleset.propertyDiffs) {
|
|
150
157
|
const path = diff.path.join(".");
|
|
@@ -163,7 +170,7 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
163
170
|
}
|
|
164
171
|
}
|
|
165
172
|
else if (ruleset.action === "delete") {
|
|
166
|
-
diffLines.push(`- ruleset
|
|
173
|
+
diffLines.push(`- ruleset ${quoted(ruleset.name)}`);
|
|
167
174
|
}
|
|
168
175
|
}
|
|
169
176
|
if (repo.labels.length > 0 && diffLines.length > startLength) {
|
|
@@ -171,36 +178,36 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
171
178
|
}
|
|
172
179
|
for (const label of repo.labels) {
|
|
173
180
|
if (label.action === "create") {
|
|
174
|
-
diffLines.push(`+ label
|
|
181
|
+
diffLines.push(`+ label ${quoted(label.name)}`);
|
|
175
182
|
if (label.config) {
|
|
176
|
-
diffLines.push(`+ color:
|
|
183
|
+
diffLines.push(`+ color: ${quoted(label.config.color)}`);
|
|
177
184
|
if (label.config.description !== undefined) {
|
|
178
|
-
diffLines.push(`+ description:
|
|
185
|
+
diffLines.push(`+ description: ${quoted(label.config.description)}`);
|
|
179
186
|
}
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
189
|
else if (label.action === "update") {
|
|
183
190
|
if (label.newName) {
|
|
184
|
-
diffLines.push(`! label
|
|
191
|
+
diffLines.push(`! label ${quoted(label.name)} \u2192 ${quoted(label.newName)}`);
|
|
185
192
|
}
|
|
186
193
|
else {
|
|
187
|
-
diffLines.push(`! label
|
|
194
|
+
diffLines.push(`! label ${quoted(label.name)}`);
|
|
188
195
|
}
|
|
189
196
|
if (label.propertyChanges) {
|
|
190
197
|
for (const prop of label.propertyChanges) {
|
|
191
198
|
if (prop.property === "new_name")
|
|
192
199
|
continue;
|
|
193
200
|
if (prop.oldValue !== undefined) {
|
|
194
|
-
diffLines.push(`! ${prop.property}:
|
|
201
|
+
diffLines.push(`! ${prop.property}: ${formatValuePlain(prop.oldValue)} \u2192 ${formatValuePlain(prop.newValue)}`);
|
|
195
202
|
}
|
|
196
203
|
else {
|
|
197
|
-
diffLines.push(`! ${prop.property}:
|
|
204
|
+
diffLines.push(`! ${prop.property}: ${formatValuePlain(prop.newValue)}`);
|
|
198
205
|
}
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
}
|
|
202
209
|
else if (label.action === "delete") {
|
|
203
|
-
diffLines.push(`- label
|
|
210
|
+
diffLines.push(`- label ${quoted(label.name)}`);
|
|
204
211
|
}
|
|
205
212
|
}
|
|
206
213
|
if ((repo.variables ?? []).length > 0 && diffLines.length > startLength) {
|
|
@@ -208,13 +215,13 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
208
215
|
}
|
|
209
216
|
for (const variable of repo.variables ?? []) {
|
|
210
217
|
if (variable.action === "create") {
|
|
211
|
-
diffLines.push(`+ variable
|
|
218
|
+
diffLines.push(`+ variable ${quoted(variable.name)}: ${formatValuePlain(variable.newValue)}`);
|
|
212
219
|
}
|
|
213
220
|
else if (variable.action === "update") {
|
|
214
|
-
diffLines.push(`! variable
|
|
221
|
+
diffLines.push(`! variable ${quoted(variable.name)}: ${formatValuePlain(variable.oldValue)} → ${formatValuePlain(variable.newValue)}`);
|
|
215
222
|
}
|
|
216
223
|
else if (variable.action === "delete") {
|
|
217
|
-
diffLines.push(`- variable
|
|
224
|
+
diffLines.push(`- variable ${quoted(variable.name)}`);
|
|
218
225
|
}
|
|
219
226
|
}
|
|
220
227
|
if ((repo.secrets ?? []).length > 0 && diffLines.length > startLength) {
|
|
@@ -223,47 +230,42 @@ export function renderRepoSettingsDiffLines(repo, diffLines) {
|
|
|
223
230
|
// Names only: secret values are write-only and must never reach output.
|
|
224
231
|
for (const secret of repo.secrets ?? []) {
|
|
225
232
|
if (secret.action === "create") {
|
|
226
|
-
diffLines.push(`+ secret
|
|
233
|
+
diffLines.push(`+ secret ${quoted(secret.name)}`);
|
|
227
234
|
}
|
|
228
235
|
else if (secret.action === "update") {
|
|
229
|
-
diffLines.push(`! secret
|
|
236
|
+
diffLines.push(`! secret ${quoted(secret.name)} (update, value write-only)`);
|
|
230
237
|
}
|
|
231
238
|
else {
|
|
232
|
-
diffLines.push(`- secret
|
|
239
|
+
diffLines.push(`- secret ${quoted(secret.name)}`);
|
|
233
240
|
}
|
|
234
241
|
}
|
|
242
|
+
if ((repo.collaborators ?? []).length > 0 && diffLines.length > startLength) {
|
|
243
|
+
diffLines.push("");
|
|
244
|
+
}
|
|
245
|
+
for (const collaborator of repo.collaborators ?? []) {
|
|
246
|
+
const sign = collaborator.action === "create" ? "+" : "-";
|
|
247
|
+
diffLines.push(`${sign} collaborator ${quoted(collaborator.name)}`);
|
|
248
|
+
}
|
|
235
249
|
if (repo.error) {
|
|
236
250
|
diffLines.push(`- Error: ${repo.error}`);
|
|
237
251
|
}
|
|
238
252
|
}
|
|
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("");
|
|
253
|
+
export function formatSettingsReportMarkdown(report, dryRun, maxBytes = STEP_SUMMARY_MAX_BYTES) {
|
|
254
|
+
const blocks = report.repos.filter(hasRepoSettingsChanges).map((repo) => {
|
|
254
255
|
const diffLines = [];
|
|
255
256
|
renderRepoSettingsDiffLines(repo, diffLines);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
257
|
+
return {
|
|
258
|
+
heading: `### ${repo.repoName}`,
|
|
259
|
+
diffLines,
|
|
260
|
+
repos: [repo.repoName],
|
|
261
|
+
};
|
|
262
|
+
});
|
|
263
|
+
return fitSummary({
|
|
264
|
+
header: summaryHeader(dryRun),
|
|
265
|
+
blocks,
|
|
266
|
+
footer: `**${formatSettingsSummary(report.totals)}**`,
|
|
267
|
+
}, maxBytes);
|
|
265
268
|
}
|
|
266
|
-
export function writeSettingsReportSummary(report, dryRun, summaryPath) {
|
|
267
|
-
|
|
268
|
-
writeGitHubStepSummary(markdown, summaryPath);
|
|
269
|
+
export function writeSettingsReportSummary(report, dryRun, summaryPath, log) {
|
|
270
|
+
writeGitHubStepSummary((maxBytes) => formatSettingsReportMarkdown(report, dryRun, maxBytes), summaryPath, log);
|
|
269
271
|
}
|
|
@@ -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;
|