@aspruyt/xfg 8.5.6 → 9.0.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 (58) hide show
  1. package/dist/cli/settings-factories.d.ts +2 -1
  2. package/dist/cli/settings-factories.js +6 -1
  3. package/dist/cli/settings-report-builder.d.ts +6 -1
  4. package/dist/cli/settings-report-builder.js +12 -0
  5. package/dist/cli/settings-runner.js +7 -0
  6. package/dist/cli/types.d.ts +4 -9
  7. package/dist/config/array-directive.d.ts +21 -0
  8. package/dist/config/array-directive.js +88 -0
  9. package/dist/config/drop-repeated-items.d.ts +2 -0
  10. package/dist/config/drop-repeated-items.js +19 -0
  11. package/dist/config/index.d.ts +2 -2
  12. package/dist/config/index.js +1 -3
  13. package/dist/config/merge.d.ts +6 -1
  14. package/dist/config/merge.js +13 -29
  15. package/dist/config/normalizer.d.ts +0 -8
  16. package/dist/config/normalizer.js +195 -238
  17. package/dist/config/types.d.ts +68 -37
  18. package/dist/config/types.js +6 -0
  19. package/dist/config/validator.d.ts +3 -9
  20. package/dist/config/validator.js +41 -45
  21. package/dist/config/validators/actions-validator.d.ts +7 -0
  22. package/dist/config/validators/actions-validator.js +139 -0
  23. package/dist/config/validators/ai-validator.d.ts +7 -1
  24. package/dist/config/validators/ai-validator.js +41 -14
  25. package/dist/config/validators/file-validator.js +2 -6
  26. package/dist/config/validators/group-validator.js +3 -10
  27. package/dist/config/validators/inherit-flag.d.ts +3 -0
  28. package/dist/config/validators/inherit-flag.js +14 -0
  29. package/dist/config/validators/pr-options-validator.d.ts +3 -0
  30. package/dist/config/validators/pr-options-validator.js +32 -0
  31. package/dist/config/validators/repo-entry-validator.js +2 -9
  32. package/dist/config/validators/ruleset-validator.d.ts +0 -3
  33. package/dist/config/validators/ruleset-validator.js +39 -58
  34. package/dist/config/validators/shared.d.ts +9 -0
  35. package/dist/config/validators/shared.js +98 -28
  36. package/dist/settings/actions/diff.d.ts +11 -0
  37. package/dist/settings/actions/diff.js +32 -0
  38. package/dist/settings/actions/endpoints.d.ts +21 -0
  39. package/dist/settings/actions/endpoints.js +89 -0
  40. package/dist/settings/actions/formatter.d.ts +10 -0
  41. package/dist/settings/actions/formatter.js +11 -0
  42. package/dist/settings/actions/github-actions-strategy.d.ts +16 -0
  43. package/dist/settings/actions/github-actions-strategy.js +23 -0
  44. package/dist/settings/actions/index.d.ts +3 -0
  45. package/dist/settings/actions/index.js +2 -0
  46. package/dist/settings/actions/processor.d.ts +19 -0
  47. package/dist/settings/actions/processor.js +88 -0
  48. package/dist/settings/actions/resolve.d.ts +15 -0
  49. package/dist/settings/actions/resolve.js +42 -0
  50. package/dist/settings/actions/types.d.ts +9 -0
  51. package/dist/settings/actions/types.js +1 -0
  52. package/dist/settings/environments/processor.js +1 -1
  53. package/dist/settings/index.d.ts +1 -0
  54. package/dist/settings/index.js +1 -0
  55. package/dist/settings/labels/diff.js +1 -2
  56. package/dist/shared/credential-env.d.ts +4 -3
  57. package/dist/shared/credential-env.js +12 -7
  58. package/package.json +4 -2
@@ -1,4 +1,4 @@
1
- import type { ArrayMergeStrategy } from "./merge.js";
1
+ import type { ArrayMergeStrategy } from "./array-directive.js";
2
2
  export type MergeMode = "manual" | "auto" | "force" | "direct";
3
3
  export type MergeStrategy = "merge" | "squash" | "rebase";
4
4
  export type AiProvider = "anthropic" | "openai";
@@ -18,6 +18,10 @@ export interface AiConfig extends AiProviderConfig {
18
18
  /** Tried when the primary provider fails; one level only */
19
19
  fallback?: AiProviderConfig;
20
20
  }
21
+ /** ai of a group or repo layer; `inherit: false` drops the inherited ai fields. */
22
+ export interface RawAiConfig extends AiConfig {
23
+ inherit?: boolean;
24
+ }
21
25
  export type ResolvedAiProviderConfig = AiProviderConfig & {
22
26
  provider: AiProvider;
23
27
  };
@@ -33,6 +37,11 @@ export interface PRMergeOptions {
33
37
  branch?: string;
34
38
  ai?: boolean | AiConfig;
35
39
  }
40
+ /** prOptions of a group or repo layer; `inherit: false` drops everything inherited. */
41
+ export interface RawPRMergeOptions extends Omit<PRMergeOptions, "ai"> {
42
+ inherit?: boolean;
43
+ ai?: boolean | RawAiConfig;
44
+ }
36
45
  export type RepoPROptions = Omit<PRMergeOptions, "ai"> & {
37
46
  ai?: ResolvedAiConfig;
38
47
  };
@@ -56,12 +65,10 @@ interface RefNameCondition {
56
65
  export interface RulesetConditions {
57
66
  refName?: RefNameCondition;
58
67
  }
59
- /** Status check in required_status_checks rule */
60
68
  export interface StatusCheckConfig {
61
69
  context: string;
62
70
  integrationId?: number;
63
71
  }
64
- /** Reviewer configuration for pull_request rule (beta) */
65
72
  export interface RequiredReviewer {
66
73
  filePatterns: string[];
67
74
  minimumApprovals: number;
@@ -70,13 +77,11 @@ export interface RequiredReviewer {
70
77
  type: "Team";
71
78
  };
72
79
  }
73
- /** Code scanning tool configuration */
74
80
  export interface CodeScanningTool {
75
81
  tool: string;
76
82
  alertsThreshold: AlertsThreshold;
77
83
  securityAlertsThreshold: SecurityAlertsThreshold;
78
84
  }
79
- /** Workflow configuration */
80
85
  interface WorkflowConfig {
81
86
  path: string;
82
87
  repositoryId: number;
@@ -216,15 +221,10 @@ export type RulesetRule = PullRequestRule | RequiredStatusChecksRule | RequiredS
216
221
  * @see https://docs.github.com/en/rest/repos/rules
217
222
  */
218
223
  export interface Ruleset {
219
- /** Target type: branch or tag */
220
224
  target?: RulesetTarget;
221
- /** Enforcement level */
222
225
  enforcement?: RulesetEnforcement;
223
- /** Actors who can bypass this ruleset */
224
226
  bypassActors?: BypassActor[];
225
- /** Conditions for when this ruleset applies */
226
227
  conditions?: RulesetConditions;
227
- /** Rules to enforce */
228
228
  rules?: RulesetRule[];
229
229
  }
230
230
  /**
@@ -232,15 +232,10 @@ export interface Ruleset {
232
232
  * Used as an allowlist — any API response field not in this set is ignored.
233
233
  */
234
234
  export declare const RULESET_COMPARABLE_FIELDS: Set<string>;
235
- /** Squash merge commit title format */
236
235
  export type SquashMergeCommitTitle = "PR_TITLE" | "COMMIT_OR_PR_TITLE";
237
- /** Squash merge commit message format */
238
236
  export type SquashMergeCommitMessage = "PR_BODY" | "COMMIT_MESSAGES" | "BLANK";
239
- /** Merge commit title format */
240
237
  export type MergeCommitTitle = "PR_TITLE" | "MERGE_MESSAGE";
241
- /** Merge commit message format */
242
238
  export type MergeCommitMessage = "PR_BODY" | "PR_TITLE" | "BLANK";
243
- /** Repository visibility */
244
239
  export type RepoVisibility = "public" | "private" | "internal";
245
240
  /**
246
241
  * GitHub repository settings configuration.
@@ -295,6 +290,35 @@ export interface CodeScanningSettings {
295
290
  querySuite?: CodeScanningQuerySuite;
296
291
  languages?: CodeScanningLanguage[];
297
292
  }
293
+ /** One layer of code scanning settings; another layer may supply `state`. */
294
+ export type RawCodeScanningSettings = Partial<CodeScanningSettings>;
295
+ export type ActionsAllowedActions = "all" | "local_only" | "selected";
296
+ export type ActionsDefaultWorkflowPermissions = "read" | "write";
297
+ export type ActionsForkPrApprovalPolicy = "first_time_contributors_new_to_github" | "first_time_contributors" | "all_external_contributors";
298
+ /**
299
+ * GitHub Actions repository settings.
300
+ * @see https://docs.github.com/en/rest/actions/permissions
301
+ */
302
+ export interface ActionsSettings {
303
+ enabled?: boolean;
304
+ allowedActions?: ActionsAllowedActions;
305
+ shaPinningRequired?: boolean;
306
+ /** Only applies when allowedActions is `selected` */
307
+ githubOwnedAllowed?: boolean;
308
+ /** Only applies when allowedActions is `selected` */
309
+ verifiedAllowed?: boolean;
310
+ /** Only applies when allowedActions is `selected`; `!` prefix blocks a pattern */
311
+ patternsAllowed?: string[];
312
+ defaultWorkflowPermissions?: ActionsDefaultWorkflowPermissions;
313
+ /** Covers creating pull requests as well as approving them */
314
+ canApprovePullRequestReviews?: boolean;
315
+ forkPrApprovalPolicy?: ActionsForkPrApprovalPolicy;
316
+ artifactAndLogRetentionDays?: number;
317
+ cacheRetentionDays?: number;
318
+ cacheSizeGb?: number;
319
+ }
320
+ /** Fields of the selected-actions endpoint; GitHub only accepts them when allowedActions is `selected`. */
321
+ export declare const ACTIONS_SELECTED_FIELDS: readonly ["githubOwnedAllowed", "verifiedAllowed", "patternsAllowed"];
298
322
  export interface SecretConfig {
299
323
  env: string;
300
324
  }
@@ -323,9 +347,16 @@ export interface EnvironmentConfig {
323
347
  deleteOrphaned?: boolean;
324
348
  };
325
349
  }
350
+ /** One layer of a deployment branch policy; the layers are merged field by field. */
351
+ export interface RawDeploymentBranchPolicy extends DeploymentBranchPolicy {
352
+ /** `false` drops the inherited policy, then this layer's fields apply */
353
+ inherit?: boolean;
354
+ }
326
355
  export interface RawEnvironmentConfig {
356
+ /** `false` drops this environment's inherited fields; not valid at root */
357
+ inherit?: boolean;
327
358
  /** `false` clears an inherited policy so any branch can deploy */
328
- deploymentBranchPolicy?: DeploymentBranchPolicy | false;
359
+ deploymentBranchPolicy?: RawDeploymentBranchPolicy | false;
329
360
  secrets?: Record<string, SecretConfig | false> & {
330
361
  deleteOrphaned?: boolean;
331
362
  };
@@ -344,25 +375,18 @@ export interface RawCollaboratorsConfig extends CollaboratorsConfig {
344
375
  inherit?: boolean;
345
376
  }
346
377
  export interface RepoSettings {
347
- /** GitHub rulesets keyed by name */
348
378
  rulesets?: Record<string, Ruleset>;
349
- /** GitHub repository settings */
350
379
  repo?: GitHubRepoSettings;
351
- /** GitHub labels keyed by name */
352
380
  labels?: Record<string, Label>;
353
- /** GitHub code scanning default setup */
354
381
  codeScanning?: CodeScanningSettings;
355
- /** GitHub Actions variables keyed by name */
382
+ actions?: ActionsSettings;
356
383
  variables?: Record<string, string> & {
357
384
  deleteOrphaned?: boolean;
358
385
  };
359
- /** GitHub Actions secrets keyed by name */
360
386
  secrets?: Record<string, SecretConfig> & {
361
387
  deleteOrphaned?: boolean;
362
388
  };
363
- /** Direct collaborators on personal (user-owned) repos */
364
389
  collaborators?: CollaboratorsConfig;
365
- /** GitHub deployment environments keyed by name */
366
390
  environments?: EnvironmentsConfig;
367
391
  deleteOrphaned?: boolean;
368
392
  }
@@ -394,10 +418,9 @@ export interface RawGroupConfig {
394
418
  files?: Record<string, RawFileConfig | RawRepoFileOverride | false> & {
395
419
  inherit?: boolean;
396
420
  };
397
- prOptions?: PRMergeOptions;
421
+ prOptions?: RawPRMergeOptions;
398
422
  settings?: RawRepoSettings;
399
423
  }
400
- /** Condition for conditional group activation */
401
424
  export interface RawConditionalGroupWhen {
402
425
  /** All listed groups must be present in the repo's effective group set */
403
426
  allOf?: string[];
@@ -406,24 +429,21 @@ export interface RawConditionalGroupWhen {
406
429
  /** None of the listed groups may be present */
407
430
  noneOf?: string[];
408
431
  }
409
- /** Conditional group: activates based on which groups a repo has */
410
432
  export interface RawConditionalGroupConfig {
411
- /** Condition that determines when this group activates */
412
433
  when: RawConditionalGroupWhen;
413
434
  /** File definitions or overrides (same capabilities as regular groups) */
414
435
  files?: Record<string, RawFileConfig | RawRepoFileOverride | false> & {
415
436
  inherit?: boolean;
416
437
  };
417
- /** PR merge options */
418
- prOptions?: PRMergeOptions;
419
- /** Repository settings (rulesets, labels, repo settings) */
438
+ prOptions?: RawPRMergeOptions;
420
439
  settings?: RawRepoSettings;
421
440
  }
422
441
  export interface RawRootSettings {
423
442
  rulesets?: Record<string, Ruleset | false>;
424
443
  repo?: GitHubRepoSettings | false;
425
444
  labels?: Record<string, Label | false>;
426
- codeScanning?: CodeScanningSettings | false;
445
+ codeScanning?: RawCodeScanningSettings | false;
446
+ actions?: ActionsSettings | false;
427
447
  variables?: Record<string, string | false> & {
428
448
  deleteOrphaned?: boolean;
429
449
  };
@@ -435,14 +455,25 @@ export interface RawRootSettings {
435
455
  deleteOrphaned?: boolean;
436
456
  }
437
457
  export interface RawRepoSettings {
438
- rulesets?: Record<string, Ruleset | false> & {
458
+ rulesets?: Record<string, (Ruleset & {
459
+ inherit?: boolean;
460
+ }) | false> & {
439
461
  inherit?: boolean;
440
462
  };
441
- repo?: GitHubRepoSettings | false;
442
- labels?: Record<string, Label | false> & {
463
+ repo?: (GitHubRepoSettings & {
464
+ inherit?: boolean;
465
+ }) | false;
466
+ labels?: Record<string, (Label & {
467
+ inherit?: boolean;
468
+ }) | false> & {
443
469
  inherit?: boolean;
444
470
  };
445
- codeScanning?: CodeScanningSettings | false;
471
+ codeScanning?: (RawCodeScanningSettings & {
472
+ inherit?: boolean;
473
+ }) | false;
474
+ actions?: (ActionsSettings & {
475
+ inherit?: boolean;
476
+ }) | false;
446
477
  variables?: Record<string, string | false> & {
447
478
  inherit?: boolean;
448
479
  deleteOrphaned?: boolean;
@@ -463,7 +494,7 @@ export interface RawRepoConfig {
463
494
  inherit?: boolean;
464
495
  };
465
496
  groups?: string[];
466
- prOptions?: PRMergeOptions;
497
+ prOptions?: RawPRMergeOptions;
467
498
  settings?: RawRepoSettings;
468
499
  /** Fork upstream repo if target doesn't exist */
469
500
  upstream?: string;
@@ -14,3 +14,9 @@ const RULESET_FIELD_MAP = {
14
14
  * Used as an allowlist — any API response field not in this set is ignored.
15
15
  */
16
16
  export const RULESET_COMPARABLE_FIELDS = new Set(Object.values(RULESET_FIELD_MAP));
17
+ /** Fields of the selected-actions endpoint; GitHub only accepts them when allowedActions is `selected`. */
18
+ export const ACTIONS_SELECTED_FIELDS = [
19
+ "githubOwnedAllowed",
20
+ "verifiedAllowed",
21
+ "patternsAllowed",
22
+ ];
@@ -1,17 +1,11 @@
1
1
  import type { Config, RawConfig, RawRootSettings, RawRepoSettings } from "./types.js";
2
- /**
3
- * Validates raw config structure before normalization.
4
- * @throws ValidationError if validation fails
5
- */
6
2
  export declare function validateRawConfig(config: RawConfig): void;
7
- /**
8
- * Validates that config is suitable for the sync command.
9
- * @throws ValidationError if neither files nor settings are present
10
- */
11
3
  export declare function validateForSync(config: RawConfig): void;
12
4
  /**
13
5
  * Cross-validates the MERGED settings of each repo: a variable and a secret with
14
- * the same name collide at GitHub. Must run post-normalize — a per-layer check
6
+ * the same name collide at GitHub, selected-actions fields need an
7
+ * allowedActions from some layer, and the fields of `prOptions.ai` must make a
8
+ * valid provider together. Must run post-normalize — a per-layer check
15
9
  * misses a root secret colliding with a repo variable.
16
10
  */
17
11
  export declare function validateNormalizedConfig(config: Config): void;
@@ -3,11 +3,14 @@ import { isPlainObject } from "../shared/type-guards.js";
3
3
  import { ValidationError } from "../shared/errors.js";
4
4
  import { isValidHostname } from "../shared/github-host-policy.js";
5
5
  import { isCredentialEnvName } from "../shared/credential-env.js";
6
- import { validateBranchName } from "../shared/branch-validation.js";
7
- import { validateAiOption } from "./validators/ai-validator.js";
8
- import { validateFileConfigFields, validateSettings, } from "./validators/shared.js";
6
+ import { validateMergedAi } from "./validators/ai-validator.js";
7
+ import { validatePrOptions } from "./validators/pr-options-validator.js";
8
+ import { assertNoRootInherit } from "./validators/inherit-flag.js";
9
+ import { arrayValues } from "./array-directive.js";
10
+ import { validateDeploymentBranchPolicy, validateFileConfigFields, validateMergedCodeScanningSettings, validateSettings, } from "./validators/shared.js";
9
11
  import { validateGroups, validateConditionalGroups, } from "./validators/group-validator.js";
10
12
  import { validateRepoEntry } from "./validators/repo-entry-validator.js";
13
+ import { validateMergedActionsSettings } from "./validators/actions-validator.js";
11
14
  const CONFIG_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
12
15
  const VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
13
16
  const VARIABLE_RESERVED_KEYS = new Set(["deleteOrphaned", "inherit"]);
@@ -59,26 +62,23 @@ function validateRootSettings(config) {
59
62
  if (config.settings === undefined)
60
63
  return;
61
64
  validateSettings(config.settings, "Root");
65
+ for (const block of [
66
+ "repo",
67
+ "actions",
68
+ "codeScanning",
69
+ "variables",
70
+ "secrets",
71
+ "collaborators",
72
+ "environments",
73
+ ]) {
74
+ assertNoRootInherit(config.settings[block], block);
75
+ }
62
76
  if (config.settings.rulesets && "inherit" in config.settings.rulesets) {
63
77
  throw new ValidationError("'inherit' is a reserved key and cannot be used as a ruleset name");
64
78
  }
65
79
  if (config.settings.labels && "inherit" in config.settings.labels) {
66
80
  throw new ValidationError("'inherit' is a reserved key and cannot be used as a label name");
67
81
  }
68
- if (config.settings.variables && "inherit" in config.settings.variables) {
69
- throw new ValidationError("'inherit' is not allowed in root-level variables (nothing to inherit from)");
70
- }
71
- if (config.settings.secrets && "inherit" in config.settings.secrets) {
72
- throw new ValidationError("'inherit' is not allowed in root-level secrets (nothing to inherit from)");
73
- }
74
- if (config.settings.collaborators &&
75
- "inherit" in config.settings.collaborators) {
76
- throw new ValidationError("'inherit' is not allowed in root-level collaborators (nothing to inherit from)");
77
- }
78
- if (config.settings.environments &&
79
- "inherit" in config.settings.environments) {
80
- throw new ValidationError("'inherit' is not allowed in root-level environments (nothing to inherit from)");
81
- }
82
82
  }
83
83
  function validateGithubHosts(config) {
84
84
  if (config.githubHosts === undefined)
@@ -102,22 +102,6 @@ function validateGithubHosts(config) {
102
102
  }
103
103
  }
104
104
  }
105
- function validatePrOptions(config) {
106
- if (config.prOptions?.branch !== undefined) {
107
- validateBranchName(config.prOptions.branch);
108
- }
109
- validateAiOption(config.prOptions?.ai);
110
- if (config.prOptions?.labels === undefined)
111
- return;
112
- if (!Array.isArray(config.prOptions.labels)) {
113
- throw new ValidationError("prOptions.labels must be an array of strings");
114
- }
115
- for (const label of config.prOptions.labels) {
116
- if (typeof label !== "string" || label.length === 0) {
117
- throw new ValidationError("prOptions.labels entries must be non-empty strings");
118
- }
119
- }
120
- }
121
105
  function hasGroupFiles(config) {
122
106
  return (isPlainObject(config.groups) &&
123
107
  Object.values(config.groups).some((g) => g.files &&
@@ -140,10 +124,6 @@ function hasConditionalGroupPR(config) {
140
124
  return (Array.isArray(config.conditionalGroups) &&
141
125
  config.conditionalGroups.some((cg) => cg.prOptions && isPlainObject(cg.prOptions)));
142
126
  }
143
- /**
144
- * Validates raw config structure before normalization.
145
- * @throws ValidationError if validation fails
146
- */
147
127
  export function validateRawConfig(config) {
148
128
  // Must run before the "nothing to do" check below, or an old secrets-only
149
129
  // config trips the generic error and never sees the migration message.
@@ -182,17 +162,13 @@ export function validateRawConfig(config) {
182
162
  }
183
163
  validateRootSettings(config);
184
164
  validateGithubHosts(config);
185
- validatePrOptions(config);
165
+ validatePrOptions(config.prOptions);
186
166
  validateGroups(config);
187
167
  validateConditionalGroups(config);
188
168
  for (let i = 0; i < config.repos.length; i++) {
189
169
  validateRepoEntry(config, config.repos[i], i);
190
170
  }
191
171
  }
192
- /**
193
- * Validates that config is suitable for the sync command.
194
- * @throws ValidationError if neither files nor settings are present
195
- */
196
172
  export function validateForSync(config) {
197
173
  const hasRootFiles = config.files && Object.keys(config.files).length > 0;
198
174
  const hasGrpFiles = hasGroupFiles(config);
@@ -266,7 +242,9 @@ function assertNoOverlap(settings, context) {
266
242
  }
267
243
  /**
268
244
  * Cross-validates the MERGED settings of each repo: a variable and a secret with
269
- * the same name collide at GitHub. Must run post-normalize — a per-layer check
245
+ * the same name collide at GitHub, selected-actions fields need an
246
+ * allowedActions from some layer, and the fields of `prOptions.ai` must make a
247
+ * valid provider together. Must run post-normalize — a per-layer check
270
248
  * misses a root secret colliding with a repo variable.
271
249
  */
272
250
  export function validateNormalizedConfig(config) {
@@ -274,8 +252,23 @@ export function validateNormalizedConfig(config) {
274
252
  assertNoOverlap(config.settings, "Root settings");
275
253
  for (const repo of config.repos) {
276
254
  assertNoOverlap(repo.settings, `Repo '${repo.git}'`);
255
+ validateMergedActionsSettings(repo.settings?.actions, `Repo '${repo.git}'`);
256
+ validateMergedCodeScanningSettings(repo.settings?.codeScanning, `Repo '${repo.git}'`);
257
+ validateMergedEnvironments(repo.settings, `Repo '${repo.git}'`);
258
+ validateMergedAi(repo.prOptions?.ai, `Repo '${repo.git}'`);
277
259
  }
278
260
  }
261
+ function validateMergedEnvironments(settings, context) {
262
+ for (const [name, environment] of Object.entries(settings?.environments ?? {})) {
263
+ if (!isPlainObject(environment) || !environment.deploymentBranchPolicy) {
264
+ continue;
265
+ }
266
+ validateDeploymentBranchPolicy(environment.deploymentBranchPolicy, `${context}: environment '${name}'`);
267
+ }
268
+ }
269
+ function hasKeys(value) {
270
+ return !!value && Object.keys(value).length > 0;
271
+ }
279
272
  export function hasActionableSettings(settings) {
280
273
  if (!settings)
281
274
  return false;
@@ -283,7 +276,7 @@ export function hasActionableSettings(settings) {
283
276
  Object.keys(settings.rulesets).filter((k) => k !== "inherit").length > 0) {
284
277
  return true;
285
278
  }
286
- if (settings.repo && Object.keys(settings.repo).length > 0) {
279
+ if (hasKeys(settings.repo)) {
287
280
  return true;
288
281
  }
289
282
  if (settings.labels &&
@@ -293,6 +286,9 @@ export function hasActionableSettings(settings) {
293
286
  if (settings.codeScanning) {
294
287
  return true;
295
288
  }
289
+ if (hasKeys(settings.actions)) {
290
+ return true;
291
+ }
296
292
  if (settings.variables) {
297
293
  const { deleteOrphaned, inherit: _i, ...entries } = settings.variables;
298
294
  if (Object.keys(entries).length > 0 || deleteOrphaned === true) {
@@ -300,7 +296,7 @@ export function hasActionableSettings(settings) {
300
296
  }
301
297
  }
302
298
  if (settings.collaborators &&
303
- ((settings.collaborators.users ?? []).length > 0 ||
299
+ ((arrayValues(settings.collaborators.users) ?? []).length > 0 ||
304
300
  settings.collaborators.deleteOrphaned === true)) {
305
301
  return true;
306
302
  }
@@ -0,0 +1,7 @@
1
+ import { type ActionsSettings } from "../types.js";
2
+ export declare function validateActionsSettings(actions: unknown, context: string): void;
3
+ /**
4
+ * Selected-actions fields need allowedActions: selected from some layer. A layer
5
+ * may omit it and inherit it, so only the merged block can be checked.
6
+ */
7
+ export declare function validateMergedActionsSettings(actions: ActionsSettings | undefined, context: string): void;
@@ -0,0 +1,139 @@
1
+ import { ValidationError } from "../../shared/errors.js";
2
+ import { isPlainObject } from "../../shared/type-guards.js";
3
+ import { arrayValues, explainNotArray } from "../array-directive.js";
4
+ import { ACTIONS_SELECTED_FIELDS, } from "../types.js";
5
+ import { validValues } from "./file-validator.js";
6
+ import { validateInheritFlag } from "./inherit-flag.js";
7
+ const ACTIONS_KEYS = new Set([
8
+ "inherit",
9
+ "enabled",
10
+ "allowedActions",
11
+ "shaPinningRequired",
12
+ "githubOwnedAllowed",
13
+ "verifiedAllowed",
14
+ "patternsAllowed",
15
+ "defaultWorkflowPermissions",
16
+ "canApprovePullRequestReviews",
17
+ "forkPrApprovalPolicy",
18
+ "artifactAndLogRetentionDays",
19
+ "cacheRetentionDays",
20
+ "cacheSizeGb",
21
+ ]);
22
+ const BOOLEAN_FIELDS = [
23
+ "enabled",
24
+ "shaPinningRequired",
25
+ "githubOwnedAllowed",
26
+ "verifiedAllowed",
27
+ "canApprovePullRequestReviews",
28
+ ];
29
+ // Upper bounds vary by visibility and plan, so the API enforces them.
30
+ const POSITIVE_INTEGER_FIELDS = [
31
+ "artifactAndLogRetentionDays",
32
+ "cacheRetentionDays",
33
+ "cacheSizeGb",
34
+ ];
35
+ const ENUM_FIELDS = [
36
+ [
37
+ "allowedActions",
38
+ validValues(["all", "local_only", "selected"]),
39
+ ],
40
+ [
41
+ "defaultWorkflowPermissions",
42
+ validValues(["read", "write"]),
43
+ ],
44
+ [
45
+ "forkPrApprovalPolicy",
46
+ validValues([
47
+ "first_time_contributors_new_to_github",
48
+ "first_time_contributors",
49
+ "all_external_contributors",
50
+ ]),
51
+ ],
52
+ ];
53
+ function validateBooleans(a, context) {
54
+ for (const field of BOOLEAN_FIELDS) {
55
+ if (a[field] !== undefined && typeof a[field] !== "boolean") {
56
+ throw new ValidationError(`${context}: ${field} must be a boolean`);
57
+ }
58
+ }
59
+ }
60
+ function validateEnums(a, context) {
61
+ for (const [field, allowed] of ENUM_FIELDS) {
62
+ if (a[field] !== undefined && !allowed.includes(a[field])) {
63
+ throw new ValidationError(`${context}: ${field} must be one of: ${allowed.join(", ")}`);
64
+ }
65
+ }
66
+ }
67
+ function validatePositiveIntegers(a, context) {
68
+ for (const field of POSITIVE_INTEGER_FIELDS) {
69
+ const value = a[field];
70
+ if (value !== undefined &&
71
+ !(Number.isInteger(value) && Number(value) > 0)) {
72
+ throw new ValidationError(`${context}: ${field} must be a positive integer`);
73
+ }
74
+ }
75
+ }
76
+ function validatePatternsAllowed(a, context) {
77
+ if (a.patternsAllowed === undefined)
78
+ return;
79
+ const patterns = arrayValues(a.patternsAllowed);
80
+ if (patterns === null) {
81
+ throw new ValidationError(explainNotArray(`${context}: patternsAllowed must be an array of strings or $arrayMerge directive`, a.patternsAllowed));
82
+ }
83
+ patterns.forEach((pattern, i) => {
84
+ if (typeof pattern !== "string" || pattern.trim() === "") {
85
+ throw new ValidationError(`${context}: patternsAllowed[${i}] must be a non-empty string`);
86
+ }
87
+ });
88
+ }
89
+ function validateValues(a, context) {
90
+ validateBooleans(a, context);
91
+ validateEnums(a, context);
92
+ validatePositiveIntegers(a, context);
93
+ validatePatternsAllowed(a, context);
94
+ }
95
+ function validateCoupling(a, context) {
96
+ const selectedField = ACTIONS_SELECTED_FIELDS.find((f) => a[f] !== undefined);
97
+ const { allowedActions } = a;
98
+ // validateValues has already limited a defined allowedActions to a string
99
+ if (selectedField &&
100
+ typeof allowedActions === "string" &&
101
+ allowedActions !== "selected") {
102
+ throw new ValidationError(`${context}: ${selectedField} requires allowedActions: selected, but this layer sets allowedActions: ${allowedActions}`);
103
+ }
104
+ if (a.enabled === false) {
105
+ const conflicting = [
106
+ "allowedActions",
107
+ "shaPinningRequired",
108
+ ...ACTIONS_SELECTED_FIELDS,
109
+ ].find((f) => a[f] !== undefined);
110
+ if (conflicting) {
111
+ throw new ValidationError(`${context}: ${conflicting} cannot be set with enabled: false`);
112
+ }
113
+ }
114
+ }
115
+ export function validateActionsSettings(actions, context) {
116
+ if (!isPlainObject(actions)) {
117
+ throw new ValidationError(`${context}: must be an object`);
118
+ }
119
+ for (const key of Object.keys(actions)) {
120
+ if (!ACTIONS_KEYS.has(key)) {
121
+ throw new ValidationError(`${context}: unknown key '${key}'`);
122
+ }
123
+ }
124
+ validateInheritFlag(actions, context);
125
+ validateValues(actions, context);
126
+ validateCoupling(actions, context);
127
+ }
128
+ /**
129
+ * Selected-actions fields need allowedActions: selected from some layer. A layer
130
+ * may omit it and inherit it, so only the merged block can be checked.
131
+ */
132
+ export function validateMergedActionsSettings(actions, context) {
133
+ if (!actions || actions.allowedActions !== undefined)
134
+ return;
135
+ const present = ACTIONS_SELECTED_FIELDS.filter((f) => actions[f] !== undefined);
136
+ if (present.length > 0) {
137
+ throw new ValidationError(`${context}: ${present.join(", ")} require allowedActions: selected, but no layer sets allowedActions`);
138
+ }
139
+ }
@@ -1 +1,7 @@
1
- export declare function validateAiOption(ai: unknown): void;
1
+ /**
2
+ * Checks one layer's field shapes; rules that relate fields wait for `validateMergedAi`.
3
+ * `context` names the layer, empty for the root; `inherit` is only valid in a layer.
4
+ */
5
+ export declare function validateAiLayer(ai: unknown, context?: string): void;
6
+ /** Checks the `ai` of one repo after every layer merged; `context` names the repo. */
7
+ export declare function validateMergedAi(ai: unknown, context: string): void;