@aspruyt/xfg 8.5.1 → 8.5.3

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.
@@ -24,7 +24,7 @@ async function runLifecyclePhase(repo, ctx) {
24
24
  token: repo.token,
25
25
  repoIndex: repo.index,
26
26
  lifecycleManager: ctx.lifecycleManager,
27
- repoSettings: ctx.config.settings?.repo,
27
+ repoSettings: repo.repoConfig.settings?.repo,
28
28
  });
29
29
  for (const line of outputLines) {
30
30
  ctx.logger.info(line);
@@ -1,16 +1,5 @@
1
- /**
2
- * Deep merge utilities for JSON configuration objects.
3
- * Supports per-field array merge strategies via $arrayMerge + $values (+ $matchBy) directives.
4
- */
5
- /**
6
- * Candidate keys for matching array items by identity rather than index.
7
- * Order matters — first key found across all items wins.
8
- */
9
- export declare const MATCH_KEY_CANDIDATES: readonly ["type", "actor_id"];
10
- /**
11
- * Finds a key that uniquely identifies items in both arrays.
12
- * Returns the first candidate key present in every item of both arrays, or undefined.
13
- */
1
+ /** Order matters: the first key present in every item of both arrays wins. */
2
+ export declare const MATCH_KEY_CANDIDATES: readonly ["type", "actorId", "actor_id"];
14
3
  export declare function findMatchKey(base: unknown[], overlay: unknown[]): string | undefined;
15
4
  export type ArrayMergeStrategy = "replace" | "append" | "prepend" | "merge";
16
5
  export interface MergeContext {
@@ -18,32 +7,13 @@ export interface MergeContext {
18
7
  /** Prefixes merge errors, e.g. the file name being merged. */
19
8
  location?: string;
20
9
  }
21
- /**
22
- * Deep merge two objects with configurable array handling.
23
- *
24
- * @param base - The base object
25
- * @param overlay - The overlay object (values override base)
26
- * @param ctx - Merge context with array strategies
27
- */
28
10
  export declare function deepMerge(base: Record<string, unknown>, overlay: Record<string, unknown>, ctx: MergeContext): Record<string, unknown>;
29
11
  /**
30
- * Strip xfg merge directive keys ($arrayMerge, $values, $matchBy) from an object.
31
- * Works recursively on nested objects and arrays.
32
- * Standard $-prefixed keys ($schema, $id, $ref, etc.) are preserved.
33
- *
34
12
  * A valid directive-only object that is the value of a key had no base array
35
13
  * to merge with, and is replaced with its $values array. A directive-only object
36
14
  * that is invalid, an array item, or the root is a ValidationError.
37
- *
38
- * @param location - Prefixes errors, e.g. the file name being stripped
39
15
  */
40
16
  export declare function stripMergeDirectives(obj: Record<string, unknown>, location?: string): Record<string, unknown>;
41
17
  export declare function createMergeContext(defaultStrategy?: ArrayMergeStrategy, location?: string): MergeContext;
42
18
  export declare function isTextContent(content: unknown): content is string | string[];
43
- /**
44
- * Merge two text content values.
45
- * For strings: overlay replaces base entirely.
46
- * For string arrays: applies merge strategy.
47
- * For mixed types: overlay replaces base.
48
- */
49
19
  export declare function mergeTextContent(base: string | string[], overlay: string | string[], strategy?: ArrayMergeStrategy): string | string[];
@@ -1,18 +1,7 @@
1
- /**
2
- * Deep merge utilities for JSON configuration objects.
3
- * Supports per-field array merge strategies via $arrayMerge + $values (+ $matchBy) directives.
4
- */
5
1
  import { isPlainObject } from "../shared/type-guards.js";
6
2
  import { ValidationError } from "../shared/errors.js";
7
- /**
8
- * Candidate keys for matching array items by identity rather than index.
9
- * Order matters — first key found across all items wins.
10
- */
11
- export const MATCH_KEY_CANDIDATES = ["type", "actor_id"];
12
- /**
13
- * Finds a key that uniquely identifies items in both arrays.
14
- * Returns the first candidate key present in every item of both arrays, or undefined.
15
- */
3
+ /** Order matters: the first key present in every item of both arrays wins. */
4
+ export const MATCH_KEY_CANDIDATES = ["type", "actorId", "actor_id"];
16
5
  export function findMatchKey(base, overlay) {
17
6
  if (base.length === 0 && overlay.length === 0)
18
7
  return undefined;
@@ -25,11 +14,7 @@ export function findMatchKey(base, overlay) {
25
14
  }
26
15
  return undefined;
27
16
  }
28
- /**
29
- * Keys reserved for xfg merge directives.
30
- * Only these are stripped during merge — standard $-prefixed keys
31
- * like $schema, $id, $ref, $generated are preserved.
32
- */
17
+ // Only these are stripped; other $-prefixed keys ($schema, $id, $ref) are content
33
18
  const XFG_DIRECTIVES = new Set(["$arrayMerge", "$values", "$matchBy"]);
34
19
  function childPath(path, key) {
35
20
  return path ? `${path}.${key}` : key;
@@ -46,10 +31,6 @@ function describeValue(value) {
46
31
  return `'${value}'`;
47
32
  return JSON.stringify(value);
48
33
  }
49
- /**
50
- * Returns the directive's $matchBy key, or undefined when it has none.
51
- * Throws unless $matchBy is a non-empty string paired with $arrayMerge: merge.
52
- */
53
34
  function readMatchBy(directive, ctx, path) {
54
35
  if (!("$matchBy" in directive))
55
36
  return undefined;
@@ -67,10 +48,7 @@ function isDirectiveOnly(value) {
67
48
  const keys = Object.keys(value);
68
49
  return keys.length > 0 && keys.every((k) => XFG_DIRECTIVES.has(k));
69
50
  }
70
- /**
71
- * Validates a value's directive keys and returns its $matchBy.
72
- * An object of only directive keys must be a complete directive, or it would resolve to nothing.
73
- */
51
+ /** An object of only directive keys must be a complete directive, or it would resolve to nothing. */
74
52
  function readDirective(value, ctx, path) {
75
53
  if (!isPlainObject(value))
76
54
  return undefined;
@@ -86,7 +64,7 @@ function readDirective(value, ctx, path) {
86
64
  }
87
65
  return matchBy;
88
66
  }
89
- /** Rejects directive-only objects; mixed-key objects keep their directive keys stripped silently. */
67
+ /** Mixed-key objects pass: their directive keys are stripped silently. */
90
68
  function assertNotDirective(value, ctx, path, position) {
91
69
  if (isPlainObject(value) && isDirectiveOnly(value)) {
92
70
  throw mergeError(ctx, path, `a directive must be the value of a key whose base is an array, not ${position}`);
@@ -167,10 +145,6 @@ const arrayMergeStrategies = new Map([
167
145
  },
168
146
  ],
169
147
  ]);
170
- /**
171
- * Checks if a value is an unresolved $arrayMerge directive object
172
- * (only directive keys, with a valid strategy and array values).
173
- */
174
148
  function isUnresolvedDirective(value) {
175
149
  if (!isPlainObject(value))
176
150
  return false;
@@ -185,13 +159,6 @@ function mergeArrays(base, overlay, strategy, ctx, path) {
185
159
  }
186
160
  return overlay;
187
161
  }
188
- /**
189
- * Deep merge two objects with configurable array handling.
190
- *
191
- * @param base - The base object
192
- * @param overlay - The overlay object (values override base)
193
- * @param ctx - Merge context with array strategies
194
- */
195
162
  export function deepMerge(base, overlay, ctx) {
196
163
  assertNotDirective(base, ctx, "", "the content root");
197
164
  assertNotDirective(overlay, ctx, "", "the content root");
@@ -242,10 +209,7 @@ function isArrayMergeStrategy(value) {
242
209
  return (typeof value === "string" &&
243
210
  arrayMergeStrategies.has(value));
244
211
  }
245
- /**
246
- * Applies an overlay directive to the base array.
247
- * Returns undefined when it doesn't apply, so the caller falls back to a plain merge.
248
- */
212
+ /** Returns undefined when the directive doesn't apply, so the caller falls back to a plain merge. */
249
213
  function applyArrayDirective(base, directive, matchBy, ctx, path) {
250
214
  const strategy = directive.$arrayMerge;
251
215
  const values = directive.$values;
@@ -264,15 +228,9 @@ function applyArrayDirective(base, directive, matchBy, ctx, path) {
264
228
  return mergeByKey(base, values, matchBy, ctx, path);
265
229
  }
266
230
  /**
267
- * Strip xfg merge directive keys ($arrayMerge, $values, $matchBy) from an object.
268
- * Works recursively on nested objects and arrays.
269
- * Standard $-prefixed keys ($schema, $id, $ref, etc.) are preserved.
270
- *
271
231
  * A valid directive-only object that is the value of a key had no base array
272
232
  * to merge with, and is replaced with its $values array. A directive-only object
273
233
  * that is invalid, an array item, or the root is a ValidationError.
274
- *
275
- * @param location - Prefixes errors, e.g. the file name being stripped
276
234
  */
277
235
  export function stripMergeDirectives(obj, location) {
278
236
  const errCtx = { location };
@@ -319,20 +277,11 @@ export function createMergeContext(defaultStrategy = "replace", location) {
319
277
  ? { defaultArrayStrategy: defaultStrategy }
320
278
  : { defaultArrayStrategy: defaultStrategy, location };
321
279
  }
322
- // =============================================================================
323
- // Text Content Utilities
324
- // =============================================================================
325
280
  export function isTextContent(content) {
326
281
  return (typeof content === "string" ||
327
282
  (Array.isArray(content) &&
328
283
  content.every((item) => typeof item === "string")));
329
284
  }
330
- /**
331
- * Merge two text content values.
332
- * For strings: overlay replaces base entirely.
333
- * For string arrays: applies merge strategy.
334
- * For mixed types: overlay replaces base.
335
- */
336
285
  export function mergeTextContent(base, overlay, strategy = "replace") {
337
286
  if (typeof overlay === "string") {
338
287
  return overlay;
@@ -50,14 +50,10 @@ function mergeContentPair(fileName, base, overlay, strategy) {
50
50
  }
51
51
  /**
52
52
  * Checks whether an object's `inherit` property is not explicitly set to false.
53
- * Replaces the repeated `(x )?.inherit !== false` pattern.
54
53
  */
55
54
  function shouldInherit(obj) {
56
55
  return obj?.inherit !== false;
57
56
  }
58
- /**
59
- * Normalizes header to array format.
60
- */
61
57
  function normalizeHeader(header) {
62
58
  if (header === undefined)
63
59
  return undefined;
@@ -347,10 +343,7 @@ export function mergeSettings(root, perRepo) {
347
343
  if (deleteOrphaned !== undefined) {
348
344
  result.deleteOrphaned = deleteOrphaned;
349
345
  }
350
- if (perRepo?.repo === false) {
351
- // Opt-out: don't include any repo settings
352
- }
353
- else {
346
+ if (perRepo?.repo !== false) {
354
347
  const rootRepo = root?.repo;
355
348
  const perRepoRepo = perRepo?.repo;
356
349
  if (rootRepo || perRepoRepo) {
@@ -364,21 +357,10 @@ export function mergeSettings(root, perRepo) {
364
357
  if (mergedLabels) {
365
358
  result.labels = mergedLabels;
366
359
  }
367
- // Merge code scanning: per-repo fully replaces root (not shallow merge).
368
- // Unlike `repo` settings (which shallow-merge via spread), code scanning
369
- // uses full replacement because its 3 fields (state, querySuite, languages)
370
- // are tightly coupled — partial inheritance (e.g., inheriting languages
371
- // from root while changing querySuite) would be confusing.
372
- // codeScanning: false means opt out of all root code scanning settings
373
- if (perRepo?.codeScanning === false) {
374
- // Opt-out: don't include any code scanning settings
375
- }
376
- else {
360
+ // Per-repo replaces root whole: state, querySuite and languages are coupled, so partial inheritance would confuse.
361
+ if (perRepo?.codeScanning !== false) {
377
362
  const mergedCodeScanning = perRepo?.codeScanning ?? root?.codeScanning;
378
363
  if (mergedCodeScanning) {
379
- // At this point mergedCodeScanning is CodeScanningSettings (not false),
380
- // because root uses RawRootSettings where false is filtered by the
381
- // outer check on perRepo?.codeScanning === false
382
364
  if (typeof mergedCodeScanning === "object") {
383
365
  result.codeScanning = mergedCodeScanning;
384
366
  }
@@ -408,9 +390,12 @@ export function mergeSettings(root, perRepo) {
408
390
  }
409
391
  return Object.keys(result).length > 0 ? result : undefined;
410
392
  }
393
+ function mergeVars(base, overlay) {
394
+ return base || overlay ? { ...base, ...overlay } : undefined;
395
+ }
411
396
  /**
412
397
  * Applies a single file-layer onto an accumulated file map: inherit:false clears,
413
- * file:false removes entries, otherwise deep-merges content.
398
+ * file:false removes entries, otherwise deep-merges content and merges vars per key.
414
399
  */
415
400
  function applyFileLayer(accumulated, layerFiles) {
416
401
  const inheritFiles = shouldInherit(layerFiles);
@@ -441,6 +426,7 @@ function applyFileLayer(accumulated, layerFiles) {
441
426
  ...existing,
442
427
  ...restFileConfig,
443
428
  content: mergedContent,
429
+ vars: mergeVars(existing.vars, overlay.vars),
444
430
  };
445
431
  }
446
432
  else {
@@ -451,8 +437,6 @@ function applyFileLayer(accumulated, layerFiles) {
451
437
  }
452
438
  /**
453
439
  * Merges group file layers onto root files, producing an effective root file map.
454
- * Each group layer is processed in order: inherit:false clears accumulated,
455
- * file:false removes a file, otherwise deep-merge content.
456
440
  */
457
441
  function mergeGroupFiles(rootFiles, groupNames, groupDefs) {
458
442
  let accumulated = structuredClone(rootFiles);
@@ -464,9 +448,6 @@ function mergeGroupFiles(rootFiles, groupNames, groupDefs) {
464
448
  }
465
449
  return accumulated;
466
450
  }
467
- /**
468
- * Merges group PR options layers onto root PR options.
469
- */
470
451
  function mergeGroupPROptions(rootPR, groupNames, groupDefs) {
471
452
  let accumulated = rootPR;
472
453
  for (const name of groupNames) {
@@ -503,7 +484,6 @@ function mergeNamedEntries(base, overlay, merge) {
503
484
  * Merges two raw settings layers (root/group into accumulated).
504
485
  * Unlike mergeSettings(), this operates on raw types and returns raw types,
505
486
  * preserving false values and inherit keys for downstream processing.
506
- * The final accumulated result feeds into the existing mergeSettings(accumulated, repoSettings).
507
487
  */
508
488
  function mergeRawSettings(base, overlay) {
509
489
  if (!base && !overlay)
@@ -558,9 +538,6 @@ function mergeRawSettings(base, overlay) {
558
538
  }
559
539
  return result;
560
540
  }
561
- /**
562
- * Merges group settings layers onto root settings.
563
- */
564
541
  function mergeGroupSettings(rootSettings, groupNames, groupDefs) {
565
542
  let accumulated = rootSettings;
566
543
  for (const name of groupNames) {
@@ -633,9 +610,7 @@ function resolveFileEntry(fileName, fileConfig, repoOverride, inheritFiles, glob
633
610
  header: normalizeHeader(repoOverride?.header ?? fileConfig.header),
634
611
  schemaUrl: repoOverride?.schemaUrl ?? fileConfig.schemaUrl,
635
612
  template: repoOverride?.template ?? fileConfig.template,
636
- vars: fileConfig.vars || repoOverride?.vars
637
- ? { ...fileConfig.vars, ...repoOverride?.vars }
638
- : undefined,
613
+ vars: mergeVars(fileConfig.vars, repoOverride?.vars),
639
614
  deleteOrphaned: repoOverride?.deleteOrphaned ??
640
615
  fileConfig.deleteOrphaned ??
641
616
  globalDeleteOrphaned,
@@ -722,10 +697,7 @@ export function normalizeConfig(raw, env) {
722
697
  }));
723
698
  }
724
699
  }
725
- // Normalize root settings by reusing mergeSettings with no per-repo overlay.
726
- // This filters out inherit/false entries from rulesets/labels, normalizes
727
- // label colors, and handles deleteOrphaned — the same logic that per-repo
728
- // merging already applies.
700
+ // No per-repo overlay: mergeSettings strips inherit/false entries and normalizes label colors, as it does per repo.
729
701
  const normalizedRootSettings = mergeSettings(raw.settings, undefined);
730
702
  return {
731
703
  id: raw.id,
@@ -3,9 +3,6 @@ import { type RepoInfo } from "../../repo/index.js";
3
3
  import { type GhApiOptions } from "../../shared/gh-api-utils.js";
4
4
  import type { Ruleset } from "../../config/index.js";
5
5
  import type { IRulesetStrategy, GitHubRuleset, GitHubBypassActor, GitHubRulesetConditions, GitHubRule, RulesetCreateParams, RulesetUpdateParams } from "./types.js";
6
- /**
7
- * Converts camelCase config ruleset to snake_case GitHub API format.
8
- */
9
6
  export declare function configToGitHub(name: string, ruleset: Ruleset): GitHubRulesetPayload;
10
7
  interface GitHubRulesetPayload {
11
8
  name: string;
@@ -2,9 +2,6 @@ import { assertGitHubRepo } from "../../repo/index.js";
2
2
  import { camelToSnake } from "../../shared/string-utils.js";
3
3
  import { GhApiClient } from "../../shared/gh-api-utils.js";
4
4
  import { parseApiJson } from "../../shared/json-utils.js";
5
- /**
6
- * Converts camelCase config ruleset to snake_case GitHub API format.
7
- */
8
5
  export function configToGitHub(name, ruleset) {
9
6
  const payload = {
10
7
  name,
@@ -41,11 +38,6 @@ const PULL_REQUEST_DEFAULTS = {
41
38
  required_review_thread_resolution: false,
42
39
  allowed_merge_methods: ["merge", "squash", "rebase"],
43
40
  };
44
- /**
45
- * Converts a single rule from config format to GitHub API format.
46
- * Handles parameter name conversions (camelCase → snake_case).
47
- * Fills in required defaults for rule types that need them.
48
- */
49
41
  function convertRule(rule) {
50
42
  const result = { type: rule.type };
51
43
  if ("parameters" in rule && rule.parameters) {
@@ -59,14 +51,10 @@ function convertRule(rule) {
59
51
  }
60
52
  }
61
53
  else if (rule.type === "pull_request") {
62
- // If no parameters provided, use defaults
63
54
  result.parameters = { ...PULL_REQUEST_DEFAULTS };
64
55
  }
65
56
  return result;
66
57
  }
67
- /**
68
- * Converts rule parameters from camelCase to snake_case.
69
- */
70
58
  function convertParameters(params) {
71
59
  const converted = {};
72
60
  for (const [key, value] of Object.entries(params)) {
@@ -75,12 +63,8 @@ function convertParameters(params) {
75
63
  }
76
64
  return converted;
77
65
  }
78
- /**
79
- * Converts nested values within parameters.
80
- */
81
66
  function convertValue(value) {
82
67
  if (Array.isArray(value)) {
83
- // Handle arrays of objects (e.g., requiredStatusChecks, codeScanningTools)
84
68
  return value.map((item) => {
85
69
  if (typeof item === "object" && item !== null) {
86
70
  const converted = {};
@@ -101,8 +85,11 @@ export class GitHubRulesetStrategy {
101
85
  }
102
86
  async list(repoInfo, options) {
103
87
  assertGitHubRepo(repoInfo, "GitHub Ruleset strategy");
104
- const endpoint = `/repos/${repoInfo.owner}/${repoInfo.repo}/rulesets`;
105
- const result = await this.api.call("GET", endpoint, { options });
88
+ const endpoint = `/repos/${repoInfo.owner}/${repoInfo.repo}/rulesets?includes_parents=false&per_page=100`;
89
+ const result = await this.api.call("GET", endpoint, {
90
+ options,
91
+ paginate: true,
92
+ });
106
93
  return parseApiJson(result, "rulesets response");
107
94
  }
108
95
  async get(repoInfo, rulesetId, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspruyt/xfg",
3
- "version": "8.5.1",
3
+ "version": "8.5.3",
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",