@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.
Files changed (91) hide show
  1. package/PR.md +2 -0
  2. package/dist/ai/anthropic-client.d.ts +16 -0
  3. package/dist/ai/anthropic-client.js +35 -0
  4. package/dist/ai/change-describer.d.ts +16 -0
  5. package/dist/ai/change-describer.js +170 -0
  6. package/dist/ai/client-factory.d.ts +2 -0
  7. package/dist/ai/client-factory.js +33 -0
  8. package/dist/ai/http.d.ts +3 -0
  9. package/dist/ai/http.js +33 -0
  10. package/dist/ai/index.d.ts +5 -0
  11. package/dist/ai/index.js +4 -0
  12. package/dist/ai/openai-compatible-client.d.ts +16 -0
  13. package/dist/ai/openai-compatible-client.js +36 -0
  14. package/dist/ai/types.d.ts +22 -0
  15. package/dist/ai/types.js +1 -0
  16. package/dist/cli/program.d.ts +7 -0
  17. package/dist/cli/program.js +15 -11
  18. package/dist/cli/repo-sync-runner.js +1 -0
  19. package/dist/cli/secrets-command.js +1 -0
  20. package/dist/cli/settings-factories.d.ts +2 -1
  21. package/dist/cli/settings-factories.js +7 -1
  22. package/dist/cli/settings-report-builder.d.ts +6 -1
  23. package/dist/cli/settings-report-builder.js +15 -0
  24. package/dist/cli/settings-runner.js +12 -0
  25. package/dist/cli/sync-command.js +2 -0
  26. package/dist/cli/types.d.ts +5 -2
  27. package/dist/cli/unified-summary.d.ts +3 -1
  28. package/dist/cli/unified-summary.js +14 -26
  29. package/dist/config/index.d.ts +1 -1
  30. package/dist/config/index.js +0 -2
  31. package/dist/config/normalizer.js +49 -27
  32. package/dist/config/types.d.ts +30 -1
  33. package/dist/config/validator.js +11 -4
  34. package/dist/config/validators/ai-validator.d.ts +1 -0
  35. package/dist/config/validators/ai-validator.js +39 -0
  36. package/dist/config/validators/group-validator.js +3 -0
  37. package/dist/config/validators/repo-entry-validator.js +2 -0
  38. package/dist/config/validators/shared.js +33 -0
  39. package/dist/lifecycle/formatter.d.ts +0 -4
  40. package/dist/lifecycle/formatter.js +2 -6
  41. package/dist/lifecycle/github-lifecycle-provider.d.ts +1 -0
  42. package/dist/lifecycle/github-lifecycle-provider.js +30 -14
  43. package/dist/output/github-summary.d.ts +4 -3
  44. package/dist/output/github-summary.js +22 -5
  45. package/dist/output/lifecycle-report.d.ts +3 -2
  46. package/dist/output/lifecycle-report.js +20 -26
  47. package/dist/output/settings-report.d.ts +12 -2
  48. package/dist/output/settings-report.js +49 -47
  49. package/dist/output/summary-budget.d.ts +12 -0
  50. package/dist/output/summary-budget.js +125 -0
  51. package/dist/output/sync-report.d.ts +6 -3
  52. package/dist/output/sync-report.js +33 -34
  53. package/dist/settings/collaborators/diff.d.ts +17 -0
  54. package/dist/settings/collaborators/diff.js +64 -0
  55. package/dist/settings/collaborators/formatter.d.ts +14 -0
  56. package/dist/settings/collaborators/formatter.js +41 -0
  57. package/dist/settings/collaborators/github-collaborators-strategy.d.ts +18 -0
  58. package/dist/settings/collaborators/github-collaborators-strategy.js +43 -0
  59. package/dist/settings/collaborators/index.d.ts +4 -0
  60. package/dist/settings/collaborators/index.js +2 -0
  61. package/dist/settings/collaborators/processor.d.ts +21 -0
  62. package/dist/settings/collaborators/processor.js +77 -0
  63. package/dist/settings/collaborators/types.d.ts +19 -0
  64. package/dist/settings/collaborators/types.js +1 -0
  65. package/dist/settings/index.d.ts +1 -0
  66. package/dist/settings/index.js +1 -0
  67. package/dist/settings/labels/formatter.d.ts +0 -3
  68. package/dist/settings/labels/formatter.js +10 -17
  69. package/dist/settings/rulesets/formatter.d.ts +0 -6
  70. package/dist/settings/rulesets/formatter.js +4 -32
  71. package/dist/settings/secrets/formatter.js +4 -3
  72. package/dist/settings/variables/formatter.js +6 -5
  73. package/dist/shared/markdown-fence.d.ts +3 -0
  74. package/dist/shared/markdown-fence.js +32 -0
  75. package/dist/shared/string-utils.d.ts +1 -3
  76. package/dist/shared/string-utils.js +5 -4
  77. package/dist/sync/commit-push-manager.js +2 -2
  78. package/dist/sync/index.d.ts +1 -1
  79. package/dist/sync/pr-merge-handler.js +3 -1
  80. package/dist/sync/repository-processor.d.ts +5 -0
  81. package/dist/sync/repository-processor.js +4 -1
  82. package/dist/sync/sync-workflow.d.ts +4 -1
  83. package/dist/sync/sync-workflow.js +29 -2
  84. package/dist/sync/types.d.ts +14 -3
  85. package/dist/vcs/ado-pr-strategy.js +43 -1
  86. package/dist/vcs/git-commit-strategy.js +3 -5
  87. package/dist/vcs/graphql-commit-strategy.js +3 -6
  88. package/dist/vcs/pr-creator.d.ts +5 -10
  89. package/dist/vcs/pr-creator.js +34 -20
  90. package/dist/vcs/types.d.ts +1 -0
  91. package/package.json +4 -2
@@ -73,7 +73,7 @@ export class GraphQLCommitStrategy {
73
73
  * @throws GraphQLApiError if the API call fails
74
74
  */
75
75
  async commit(options) {
76
- const { repoInfo, branchName, message, fileChanges, workDir, retries = 3, token, } = options;
76
+ const { repoInfo, branchName, message, body, fileChanges, workDir, retries = 3, token, } = options;
77
77
  if (!isGitHubRepo(repoInfo)) {
78
78
  throw new ValidationError(`GraphQL commit strategy requires GitHub repositories. Got: ${repoInfo.type}`);
79
79
  }
@@ -108,7 +108,7 @@ export class GraphQLCommitStrategy {
108
108
  }
109
109
  await gitOps.fetchBranch(branchName);
110
110
  const headSha = await this.executor.exec("git", ["rev-parse", `origin/${branchName}`], workDir);
111
- const result = await this.executeGraphQLMutation(repoInfo, branchName, message, headSha.trim(), additions, deletions, workDir, token);
111
+ const result = await this.executeGraphQLMutation(repoInfo, branchName, { headline: message, ...(body ? { body } : {}) }, headSha.trim(), additions, deletions, workDir, token);
112
112
  return result;
113
113
  }
114
114
  catch (error) {
@@ -150,9 +150,7 @@ export class GraphQLCommitStrategy {
150
150
  branchName,
151
151
  },
152
152
  expectedHeadOid,
153
- message: {
154
- headline: message,
155
- },
153
+ message,
156
154
  fileChanges,
157
155
  },
158
156
  };
@@ -236,7 +234,6 @@ export class GraphQLCommitStrategy {
236
234
  const originalMessage = toErrorMessage(error);
237
235
  let cleanMessage;
238
236
  if (originalMessage.startsWith("Command failed:")) {
239
- // Extract stderr: everything after the first newline
240
237
  const newlineIndex = originalMessage.indexOf("\n");
241
238
  cleanMessage =
242
239
  newlineIndex >= 0
@@ -12,18 +12,17 @@ interface PROptions {
12
12
  dryRun?: boolean;
13
13
  /** Number of retries for API operations (default: 3) */
14
14
  retries?: number;
15
- /** Custom PR body template */
16
15
  prTemplate?: string;
17
- /** Command executor for shell commands */
18
16
  executor: ICommandExecutor;
19
- /** GitHub App installation token for authentication */
20
17
  token?: string;
21
- /** Labels to apply to the created PR */
22
18
  labels?: string[];
23
19
  /** Optional logger for PR strategy debug/warn/info messages */
24
20
  log?: IPRStrategyLogger;
25
21
  /** Pre-constructed PR strategy to reuse (avoids redundant instantiation) */
26
22
  strategy?: IPRStrategy;
23
+ /** Overrides the default "chore: sync ..." title */
24
+ title?: string;
25
+ aiSummary?: string;
27
26
  }
28
27
  export type { PRResult } from "./types.js";
29
28
  /**
@@ -33,13 +32,11 @@ export type { PRResult } from "./types.js";
33
32
  * - ${xfg:pr.fileChanges} - formatted list of changed files
34
33
  * - ${xfg:pr.fileCount} - number of changed files
35
34
  * - ${xfg:pr.title} - the PR title
35
+ * - ${xfg:pr.aiSummary} - AI-generated summary (empty when AI is off)
36
36
  *
37
37
  * Plus all standard repo variables (repo.name, repo.owner, etc.)
38
38
  */
39
- export declare function formatPRBody(files: FileAction[], repoInfo: RepoInfo, customTemplate?: string): string;
40
- /**
41
- * Generate PR title based on files changed (excludes skipped files)
42
- */
39
+ export declare function formatPRBody(files: FileAction[], repoInfo: RepoInfo, customTemplate?: string, aiSummary?: string, title?: string): string;
43
40
  export declare function formatPRTitle(files: FileAction[]): string;
44
41
  export declare function createPR(options: PROptions): Promise<PRResult>;
45
42
  interface MergePROptions {
@@ -49,9 +46,7 @@ interface MergePROptions {
49
46
  workDir: string;
50
47
  dryRun?: boolean;
51
48
  retries?: number;
52
- /** Command executor for shell commands */
53
49
  executor: ICommandExecutor;
54
- /** GitHub App installation token for authentication */
55
50
  token?: string;
56
51
  /** Optional logger for PR strategy debug/warn/info messages */
57
52
  log?: IPRStrategyLogger;
@@ -4,19 +4,20 @@ import { fileURLToPath } from "node:url";
4
4
  import { createPRStrategy } from "./pr-strategy-factory.js";
5
5
  import { PRWorkflowExecutor } from "./pr-strategy.js";
6
6
  import { interpolateXfgContent } from "../shared/xfg-template.js";
7
+ import { inlineCode } from "../shared/markdown-fence.js";
7
8
  function loadDefaultTemplate() {
8
- // Try to find PR.md in the project root
9
9
  const __filename = fileURLToPath(import.meta.url);
10
10
  const __dirname = dirname(__filename);
11
11
  const templatePath = join(__dirname, "..", "PR.md");
12
12
  if (existsSync(templatePath)) {
13
13
  return readFileSync(templatePath, "utf-8");
14
14
  }
15
- // Fallback template
16
15
  return `## Summary
17
16
 
18
17
  Automated sync of configuration files to \${xfg:repo.fullName}.
19
18
 
19
+ \${xfg:pr.aiSummary}
20
+
20
21
  ## Changes
21
22
 
22
23
  \${xfg:pr.fileChanges}
@@ -29,9 +30,21 @@ Configuration synced using [xfg](https://github.com/anthony-spruyt/xfg).
29
30
 
30
31
  _This PR was automatically generated by [xfg](https://github.com/anthony-spruyt/xfg)_`;
31
32
  }
32
- /**
33
- * Format file changes list, excluding skipped files
34
- */
33
+ const AI_SUMMARY_VAR = "${xfg:pr.aiSummary}";
34
+ const UNESCAPED_AI_SUMMARY_VAR = /(?<!\$)\$\{xfg:pr\.aiSummary\}/;
35
+ const AI_SUMMARY_LINE = /^[ \t]*\$\{xfg:pr\.aiSummary\}[ \t]*(?:\n|$)/m;
36
+ function dropAiSummaryLine(template) {
37
+ const match = AI_SUMMARY_LINE.exec(template);
38
+ if (!match)
39
+ return template;
40
+ const before = template.slice(0, match.index);
41
+ let after = template.slice(match.index + match[0].length);
42
+ // A placeholder between blank lines would otherwise leave a double blank.
43
+ if ((before === "" || before.endsWith("\n\n")) && after.startsWith("\n")) {
44
+ after = after.slice(1);
45
+ }
46
+ return before + after;
47
+ }
35
48
  function formatFileChanges(files) {
36
49
  const changedFiles = files.filter((f) => f.action !== "skip");
37
50
  return changedFiles
@@ -47,7 +60,7 @@ function formatFileChanges(files) {
47
60
  case "delete":
48
61
  actionText = "Deleted";
49
62
  break;
50
- /* c8 ignore next 3 -- filtered out by line 77 */
63
+ /* c8 ignore next 3 -- skipped files are filtered out above */
51
64
  case "skip":
52
65
  actionText = "Skipped";
53
66
  break;
@@ -57,7 +70,7 @@ function formatFileChanges(files) {
57
70
  throw new Error(`Unexpected action: ${_exhaustive}`);
58
71
  }
59
72
  }
60
- return `- ${actionText} \`${f.fileName}\``;
73
+ return `- ${actionText} ${inlineCode(f.fileName)}`;
61
74
  })
62
75
  .join("\n");
63
76
  }
@@ -68,29 +81,32 @@ function formatFileChanges(files) {
68
81
  * - ${xfg:pr.fileChanges} - formatted list of changed files
69
82
  * - ${xfg:pr.fileCount} - number of changed files
70
83
  * - ${xfg:pr.title} - the PR title
84
+ * - ${xfg:pr.aiSummary} - AI-generated summary (empty when AI is off)
71
85
  *
72
86
  * Plus all standard repo variables (repo.name, repo.owner, etc.)
73
87
  */
74
- export function formatPRBody(files, repoInfo, customTemplate) {
75
- const template = customTemplate ?? loadDefaultTemplate();
88
+ export function formatPRBody(files, repoInfo, customTemplate, aiSummary, title) {
89
+ let template = customTemplate ?? loadDefaultTemplate();
90
+ if (!aiSummary) {
91
+ template = dropAiSummaryLine(template);
92
+ }
93
+ else if (!UNESCAPED_AI_SUMMARY_VAR.test(template)) {
94
+ template = `${template.trimEnd()}\n\n## AI Summary\n\n${AI_SUMMARY_VAR}\n`;
95
+ }
76
96
  const fileChanges = formatFileChanges(files);
77
97
  const changedFiles = files.filter((f) => f.action !== "skip");
78
- const title = formatPRTitle(files);
79
- // Create context with PR-specific variables
80
98
  const result = interpolateXfgContent(template, {
81
99
  repoInfo,
82
100
  fileName: "PR.md",
83
101
  vars: {
84
102
  "pr.fileChanges": fileChanges,
85
103
  "pr.fileCount": String(changedFiles.length),
86
- "pr.title": title,
104
+ "pr.title": title ?? formatPRTitle(files),
105
+ "pr.aiSummary": aiSummary ?? "",
87
106
  },
88
107
  });
89
108
  return result;
90
109
  }
91
- /**
92
- * Generate PR title based on files changed (excludes skipped files)
93
- */
94
110
  export function formatPRTitle(files) {
95
111
  const changedFiles = files.filter((f) => f.action !== "skip");
96
112
  if (changedFiles.length === 1) {
@@ -103,16 +119,15 @@ export function formatPRTitle(files) {
103
119
  return `chore: sync ${changedFiles.length} config files`;
104
120
  }
105
121
  export function createPR(options) {
106
- const { repoInfo, branchName, baseBranch, files, workDir, dryRun, retries, prTemplate, executor, token, labels, log, } = options;
107
- const title = formatPRTitle(files);
108
- const body = formatPRBody(files, repoInfo, prTemplate);
122
+ const { repoInfo, branchName, baseBranch, files, workDir, dryRun, retries, prTemplate, executor, token, labels, log, aiSummary, } = options;
123
+ const title = options.title ?? formatPRTitle(files);
124
+ const body = formatPRBody(files, repoInfo, prTemplate, aiSummary, title);
109
125
  if (dryRun) {
110
126
  return Promise.resolve({
111
127
  success: true,
112
128
  message: `[DRY RUN] Would create PR: "${title}"`,
113
129
  });
114
130
  }
115
- // Get the appropriate strategy and execute via workflow executor
116
131
  const resolvedStrategy = options.strategy ?? createPRStrategy(repoInfo, executor, log);
117
132
  const workflow = new PRWorkflowExecutor(resolvedStrategy, log);
118
133
  return workflow.execute({
@@ -141,7 +156,6 @@ export function mergePR(options) {
141
156
  merged: false,
142
157
  });
143
158
  }
144
- // Get the appropriate strategy and execute merge
145
159
  const resolvedStrategy = options.strategy ?? createPRStrategy(repoInfo, executor, log);
146
160
  return resolvedStrategy.merge({
147
161
  prUrl,
@@ -165,6 +165,7 @@ export interface CommitOptions {
165
165
  branchName: string;
166
166
  baseBranch?: string;
167
167
  message: string;
168
+ body?: string;
168
169
  fileChanges: FileChange[];
169
170
  workDir: string;
170
171
  retries?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspruyt/xfg",
3
- "version": "7.2.1",
3
+ "version": "7.4.0",
4
4
  "description": "Manage files, settings, and repositories across GitHub, Azure DevOps, and GitLab — declaratively, from a single YAML config",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,14 +38,16 @@
38
38
  "docs:generate": "tsx scripts/docs/generate-docs.ts",
39
39
  "docs:check": "tsx scripts/docs/generate-docs.ts --check",
40
40
  "test": "node --import tsx scripts/run-tests.js",
41
- "test:coverage": "c8 --check-coverage --lines 95 --reporter=text --reporter=lcov --all --src=src --exclude='test/**/*.test.ts' --exclude='scripts/**' --exclude='src/vcs/types.ts' --exclude='src/settings/rulesets/types.ts' --exclude='src/settings/repo-settings/types.ts' --exclude='src/settings/labels/types.ts' --exclude='src/**/index.ts' --exclude='test/mocks/**' --exclude='src/sync/types.ts' --exclude='src/lifecycle/types.ts' --exclude='src/cli/program.ts' --exclude='src/cli/types.ts' --exclude='src/cli.ts' --exclude='src/index.ts' npm test",
41
+ "test:coverage": "c8 --check-coverage --lines 95 --reporter=text --reporter=lcov --all --src=src --exclude='test/**/*.test.ts' --exclude='scripts/**' --exclude='src/vcs/types.ts' --exclude='src/settings/rulesets/types.ts' --exclude='src/settings/repo-settings/types.ts' --exclude='src/settings/labels/types.ts' --exclude='src/**/index.ts' --exclude='test/mocks/**' --exclude='src/sync/types.ts' --exclude='src/lifecycle/types.ts' --exclude='src/cli/program.ts' --exclude='src/repo/types.ts' --exclude='src/settings/secrets/types.ts' --exclude='src/settings/code-scanning/types.ts' --exclude='src/settings/variables/types.ts' --exclude='src/settings/collaborators/types.ts' --exclude='src/ai/types.ts' --exclude='src/cli/types.ts' --exclude='src/cli.ts' --exclude='src/index.ts' npm test",
42
42
  "test:integration:github": "npm run build && node --import tsx --test test/integration/github.test.ts",
43
43
  "test:integration:ado": "npm run build && node --import tsx --test test/integration/ado.test.ts",
44
44
  "test:integration:gitlab": "npm run build && node --import tsx --test test/integration/gitlab.test.ts",
45
+ "test:integration:github-ai": "npm run build && node --import tsx --test test/integration/github-ai.test.ts",
45
46
  "test:integration:github-app": "npm run build && node --import tsx --test test/integration/github-app.test.ts",
46
47
  "test:integration:github-rulesets": "npm run build && node --import tsx --test test/integration/github-rulesets.test.ts",
47
48
  "test:integration:github-secrets": "npm run build && node --import tsx --test test/integration/github-secrets.test.ts",
48
49
  "test:integration:github-variables": "npm run build && node --import tsx --test test/integration/github-variables.test.ts",
50
+ "test:integration:github-collaborators": "npm run build && node --import tsx --test test/integration/github-collaborators.test.ts",
49
51
  "test:integration:github-repo-settings": "npm run build && node --import tsx --test test/integration/github-repo-settings.test.ts",
50
52
  "test:integration:github-labels": "npm run build && node --import tsx --test test/integration/github-labels.test.ts",
51
53
  "test:integration:github-code-scanning": "npm run build && node --import tsx --test test/integration/github-code-scanning.test.ts",