@aspruyt/xfg 8.6.0 → 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.
- package/dist/config/array-directive.d.ts +21 -0
- package/dist/config/array-directive.js +88 -0
- package/dist/config/drop-repeated-items.d.ts +2 -0
- package/dist/config/drop-repeated-items.js +19 -0
- package/dist/config/merge.d.ts +6 -1
- package/dist/config/merge.js +13 -29
- package/dist/config/normalizer.js +195 -234
- package/dist/config/types.d.ts +39 -11
- package/dist/config/validator.d.ts +3 -2
- package/dist/config/validator.js +32 -37
- package/dist/config/validators/actions-validator.js +8 -3
- package/dist/config/validators/ai-validator.d.ts +7 -1
- package/dist/config/validators/ai-validator.js +41 -14
- package/dist/config/validators/file-validator.js +2 -6
- package/dist/config/validators/group-validator.js +3 -10
- package/dist/config/validators/inherit-flag.d.ts +3 -0
- package/dist/config/validators/inherit-flag.js +14 -0
- package/dist/config/validators/pr-options-validator.d.ts +3 -0
- package/dist/config/validators/pr-options-validator.js +32 -0
- package/dist/config/validators/repo-entry-validator.js +2 -9
- package/dist/config/validators/ruleset-validator.d.ts +0 -3
- package/dist/config/validators/ruleset-validator.js +39 -58
- package/dist/config/validators/shared.d.ts +8 -0
- package/dist/config/validators/shared.js +77 -28
- package/dist/shared/credential-env.d.ts +4 -3
- package/dist/shared/credential-env.js +12 -7
- package/package.json +2 -1
package/dist/config/validator.js
CHANGED
|
@@ -3,9 +3,11 @@ 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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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";
|
|
11
13
|
import { validateMergedActionsSettings } from "./validators/actions-validator.js";
|
|
@@ -60,26 +62,23 @@ function validateRootSettings(config) {
|
|
|
60
62
|
if (config.settings === undefined)
|
|
61
63
|
return;
|
|
62
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
|
+
}
|
|
63
76
|
if (config.settings.rulesets && "inherit" in config.settings.rulesets) {
|
|
64
77
|
throw new ValidationError("'inherit' is a reserved key and cannot be used as a ruleset name");
|
|
65
78
|
}
|
|
66
79
|
if (config.settings.labels && "inherit" in config.settings.labels) {
|
|
67
80
|
throw new ValidationError("'inherit' is a reserved key and cannot be used as a label name");
|
|
68
81
|
}
|
|
69
|
-
if (config.settings.variables && "inherit" in config.settings.variables) {
|
|
70
|
-
throw new ValidationError("'inherit' is not allowed in root-level variables (nothing to inherit from)");
|
|
71
|
-
}
|
|
72
|
-
if (config.settings.secrets && "inherit" in config.settings.secrets) {
|
|
73
|
-
throw new ValidationError("'inherit' is not allowed in root-level secrets (nothing to inherit from)");
|
|
74
|
-
}
|
|
75
|
-
if (config.settings.collaborators &&
|
|
76
|
-
"inherit" in config.settings.collaborators) {
|
|
77
|
-
throw new ValidationError("'inherit' is not allowed in root-level collaborators (nothing to inherit from)");
|
|
78
|
-
}
|
|
79
|
-
if (config.settings.environments &&
|
|
80
|
-
"inherit" in config.settings.environments) {
|
|
81
|
-
throw new ValidationError("'inherit' is not allowed in root-level environments (nothing to inherit from)");
|
|
82
|
-
}
|
|
83
82
|
}
|
|
84
83
|
function validateGithubHosts(config) {
|
|
85
84
|
if (config.githubHosts === undefined)
|
|
@@ -103,22 +102,6 @@ function validateGithubHosts(config) {
|
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
function validatePrOptions(config) {
|
|
107
|
-
if (config.prOptions?.branch !== undefined) {
|
|
108
|
-
validateBranchName(config.prOptions.branch);
|
|
109
|
-
}
|
|
110
|
-
validateAiOption(config.prOptions?.ai);
|
|
111
|
-
if (config.prOptions?.labels === undefined)
|
|
112
|
-
return;
|
|
113
|
-
if (!Array.isArray(config.prOptions.labels)) {
|
|
114
|
-
throw new ValidationError("prOptions.labels must be an array of strings");
|
|
115
|
-
}
|
|
116
|
-
for (const label of config.prOptions.labels) {
|
|
117
|
-
if (typeof label !== "string" || label.length === 0) {
|
|
118
|
-
throw new ValidationError("prOptions.labels entries must be non-empty strings");
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
105
|
function hasGroupFiles(config) {
|
|
123
106
|
return (isPlainObject(config.groups) &&
|
|
124
107
|
Object.values(config.groups).some((g) => g.files &&
|
|
@@ -179,7 +162,7 @@ export function validateRawConfig(config) {
|
|
|
179
162
|
}
|
|
180
163
|
validateRootSettings(config);
|
|
181
164
|
validateGithubHosts(config);
|
|
182
|
-
validatePrOptions(config);
|
|
165
|
+
validatePrOptions(config.prOptions);
|
|
183
166
|
validateGroups(config);
|
|
184
167
|
validateConditionalGroups(config);
|
|
185
168
|
for (let i = 0; i < config.repos.length; i++) {
|
|
@@ -259,8 +242,9 @@ function assertNoOverlap(settings, context) {
|
|
|
259
242
|
}
|
|
260
243
|
/**
|
|
261
244
|
* Cross-validates the MERGED settings of each repo: a variable and a secret with
|
|
262
|
-
* the same name collide at GitHub,
|
|
263
|
-
* allowedActions from some layer
|
|
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
|
|
264
248
|
* misses a root secret colliding with a repo variable.
|
|
265
249
|
*/
|
|
266
250
|
export function validateNormalizedConfig(config) {
|
|
@@ -269,6 +253,17 @@ export function validateNormalizedConfig(config) {
|
|
|
269
253
|
for (const repo of config.repos) {
|
|
270
254
|
assertNoOverlap(repo.settings, `Repo '${repo.git}'`);
|
|
271
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}'`);
|
|
259
|
+
}
|
|
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}'`);
|
|
272
267
|
}
|
|
273
268
|
}
|
|
274
269
|
function hasKeys(value) {
|
|
@@ -301,7 +296,7 @@ export function hasActionableSettings(settings) {
|
|
|
301
296
|
}
|
|
302
297
|
}
|
|
303
298
|
if (settings.collaborators &&
|
|
304
|
-
((settings.collaborators.users ?? []).length > 0 ||
|
|
299
|
+
((arrayValues(settings.collaborators.users) ?? []).length > 0 ||
|
|
305
300
|
settings.collaborators.deleteOrphaned === true)) {
|
|
306
301
|
return true;
|
|
307
302
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { ValidationError } from "../../shared/errors.js";
|
|
2
2
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
3
|
+
import { arrayValues, explainNotArray } from "../array-directive.js";
|
|
3
4
|
import { ACTIONS_SELECTED_FIELDS, } from "../types.js";
|
|
4
5
|
import { validValues } from "./file-validator.js";
|
|
6
|
+
import { validateInheritFlag } from "./inherit-flag.js";
|
|
5
7
|
const ACTIONS_KEYS = new Set([
|
|
8
|
+
"inherit",
|
|
6
9
|
"enabled",
|
|
7
10
|
"allowedActions",
|
|
8
11
|
"shaPinningRequired",
|
|
@@ -73,10 +76,11 @@ function validatePositiveIntegers(a, context) {
|
|
|
73
76
|
function validatePatternsAllowed(a, context) {
|
|
74
77
|
if (a.patternsAllowed === undefined)
|
|
75
78
|
return;
|
|
76
|
-
|
|
77
|
-
|
|
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));
|
|
78
82
|
}
|
|
79
|
-
|
|
83
|
+
patterns.forEach((pattern, i) => {
|
|
80
84
|
if (typeof pattern !== "string" || pattern.trim() === "") {
|
|
81
85
|
throw new ValidationError(`${context}: patternsAllowed[${i}] must be a non-empty string`);
|
|
82
86
|
}
|
|
@@ -117,6 +121,7 @@ export function validateActionsSettings(actions, context) {
|
|
|
117
121
|
throw new ValidationError(`${context}: unknown key '${key}'`);
|
|
118
122
|
}
|
|
119
123
|
}
|
|
124
|
+
validateInheritFlag(actions, context);
|
|
120
125
|
validateValues(actions, context);
|
|
121
126
|
validateCoupling(actions, context);
|
|
122
127
|
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
2
2
|
import { ValidationError } from "../../shared/errors.js";
|
|
3
|
-
import { assertAiBaseUrlEnvAllowed, assertAiHeadersEnvAllowed, assertAiKeyEnvAllowed, } from "../../shared/credential-env.js";
|
|
3
|
+
import { assertAiBaseUrlEnvAllowed, assertAiBaseUrlEnvName, assertAiHeadersEnvAllowed, assertAiKeyEnvAllowed, } from "../../shared/credential-env.js";
|
|
4
|
+
import { assertNoRootInherit } from "./inherit-flag.js";
|
|
4
5
|
const VALID_PROVIDERS = ["anthropic", "openai"];
|
|
5
6
|
const STRING_FIELDS = ["model", "baseUrl", "apiKeyEnv", "prompt"];
|
|
6
7
|
const PROVIDER_KEYS = [
|
|
@@ -10,23 +11,43 @@ const PROVIDER_KEYS = [
|
|
|
10
11
|
"baseUrlEnv",
|
|
11
12
|
...STRING_FIELDS,
|
|
12
13
|
];
|
|
13
|
-
const PRIMARY_KEYS = new Set([...PROVIDER_KEYS, "fallback"]);
|
|
14
|
+
const PRIMARY_KEYS = new Set([...PROVIDER_KEYS, "fallback", "inherit"]);
|
|
14
15
|
const FALLBACK_KEYS = new Set(PROVIDER_KEYS);
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Checks one layer's field shapes; rules that relate fields wait for `validateMergedAi`.
|
|
18
|
+
* `context` names the layer, empty for the root; `inherit` is only valid in a layer.
|
|
19
|
+
*/
|
|
20
|
+
export function validateAiLayer(ai, context = "") {
|
|
16
21
|
if (ai === undefined || typeof ai === "boolean")
|
|
17
22
|
return;
|
|
23
|
+
const path = context ? `${context}: prOptions.ai` : "prOptions.ai";
|
|
18
24
|
if (!isPlainObject(ai)) {
|
|
19
|
-
throw new ValidationError(
|
|
25
|
+
throw new ValidationError(`${path} must be a boolean or an object`);
|
|
20
26
|
}
|
|
21
|
-
|
|
27
|
+
if (!context)
|
|
28
|
+
assertNoRootInherit(ai, "prOptions.ai");
|
|
29
|
+
if (ai.inherit !== undefined && typeof ai.inherit !== "boolean") {
|
|
30
|
+
throw new ValidationError(`${path}.inherit must be a boolean`);
|
|
31
|
+
}
|
|
32
|
+
validateProviderShape(ai, path, PRIMARY_KEYS);
|
|
22
33
|
if (ai.fallback !== undefined) {
|
|
23
34
|
if (!isPlainObject(ai.fallback)) {
|
|
24
|
-
throw new ValidationError(
|
|
35
|
+
throw new ValidationError(`${path}.fallback must be an object`);
|
|
25
36
|
}
|
|
26
|
-
|
|
37
|
+
validateProviderShape(ai.fallback, `${path}.fallback`, FALLBACK_KEYS);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Checks the `ai` of one repo after every layer merged; `context` names the repo. */
|
|
41
|
+
export function validateMergedAi(ai, context) {
|
|
42
|
+
if (!isPlainObject(ai))
|
|
43
|
+
return;
|
|
44
|
+
const path = `${context}: prOptions.ai`;
|
|
45
|
+
validateMergedProvider(ai, path);
|
|
46
|
+
if (isPlainObject(ai.fallback)) {
|
|
47
|
+
validateMergedProvider(ai.fallback, `${path}.fallback`);
|
|
27
48
|
}
|
|
28
49
|
}
|
|
29
|
-
function
|
|
50
|
+
function validateProviderShape(ai, path, knownKeys) {
|
|
30
51
|
const unknown = Object.keys(ai).find((key) => !knownKeys.has(key));
|
|
31
52
|
if (unknown !== undefined) {
|
|
32
53
|
throw new ValidationError(`${path} has unknown key '${unknown}'`);
|
|
@@ -42,17 +63,23 @@ function validateProvider(ai, path, knownKeys) {
|
|
|
42
63
|
throw new ValidationError(`${path}.${field} must be a non-empty string`);
|
|
43
64
|
}
|
|
44
65
|
}
|
|
66
|
+
assertAiBaseUrlEnvName(ai.baseUrlEnv, path);
|
|
67
|
+
assertAiHeadersEnvAllowed(ai.headersEnv, path);
|
|
68
|
+
const max = ai.maxDiffChars;
|
|
69
|
+
if (max !== undefined &&
|
|
70
|
+
(typeof max !== "number" || !Number.isInteger(max) || max <= 0)) {
|
|
71
|
+
throw new ValidationError(`${path}.maxDiffChars must be a positive integer`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function validateMergedProvider(ai, path) {
|
|
75
|
+
const provider = ai.provider ?? "anthropic";
|
|
45
76
|
assertAiBaseUrlEnvAllowed(ai.baseUrlEnv, ai.baseUrl, path);
|
|
46
|
-
assertAiKeyEnvAllowed(provider
|
|
77
|
+
assertAiKeyEnvAllowed(provider, ai.apiKeyEnv, ai.baseUrl, path,
|
|
47
78
|
// A URL read from the env is unknown here, so it never counts as the provider's own API.
|
|
48
79
|
ai.baseUrlEnv !== undefined);
|
|
80
|
+
// Layers can each be valid and still name one header twice in different case.
|
|
49
81
|
assertAiHeadersEnvAllowed(ai.headersEnv, path);
|
|
50
82
|
if (provider === "openai" && ai.model === undefined) {
|
|
51
83
|
throw new ValidationError(`${path}.model is required when provider is 'openai'`);
|
|
52
84
|
}
|
|
53
|
-
const max = ai.maxDiffChars;
|
|
54
|
-
if (max !== undefined &&
|
|
55
|
-
(typeof max !== "number" || !Number.isInteger(max) || max <= 0)) {
|
|
56
|
-
throw new ValidationError(`${path}.maxDiffChars must be a positive integer`);
|
|
57
|
-
}
|
|
58
85
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { extname, isAbsolute } from "node:path";
|
|
2
2
|
import { isTextContent } from "../merge.js";
|
|
3
|
+
import { ARRAY_MERGE_STRATEGIES } from "../array-directive.js";
|
|
3
4
|
import { ValidationError } from "../../shared/errors.js";
|
|
4
5
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
5
6
|
import { hasGitDirSegment } from "../../shared/path-safety.js";
|
|
@@ -8,12 +9,7 @@ export { isPlainObject as isObjectContent };
|
|
|
8
9
|
export function validValues(values) {
|
|
9
10
|
return values;
|
|
10
11
|
}
|
|
11
|
-
const VALID_STRATEGIES =
|
|
12
|
-
"replace",
|
|
13
|
-
"append",
|
|
14
|
-
"prepend",
|
|
15
|
-
"merge",
|
|
16
|
-
]);
|
|
12
|
+
const VALID_STRATEGIES = ARRAY_MERGE_STRATEGIES;
|
|
17
13
|
/**
|
|
18
14
|
* Check if file extension is for structured output (JSON/YAML).
|
|
19
15
|
*/
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { resolveExtendsChain } from "../extends-resolver.js";
|
|
2
2
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
3
3
|
import { ValidationError } from "../../shared/errors.js";
|
|
4
|
-
import {
|
|
5
|
-
import { validateAiOption } from "./ai-validator.js";
|
|
4
|
+
import { validatePrOptions } from "./pr-options-validator.js";
|
|
6
5
|
import { validateFileName } from "./file-validator.js";
|
|
7
6
|
import { validateFileConfigFields, validateSettings, buildRootSettingsContext, } from "./shared.js";
|
|
8
7
|
function validateGroupExtends(groupName, extends_, groupNames) {
|
|
@@ -106,10 +105,7 @@ export function validateGroups(config) {
|
|
|
106
105
|
if (group.settings !== undefined) {
|
|
107
106
|
validateSettings(group.settings, `groups.${groupName}`, rootCtx);
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
validateBranchName(group.prOptions.branch);
|
|
111
|
-
}
|
|
112
|
-
validateAiOption(group.prOptions?.ai);
|
|
108
|
+
validatePrOptions(group.prOptions, `groups.${groupName}`);
|
|
113
109
|
}
|
|
114
110
|
validateNoCircularExtends(config.groups);
|
|
115
111
|
}
|
|
@@ -172,9 +168,6 @@ export function validateConditionalGroups(config) {
|
|
|
172
168
|
if (entry.settings !== undefined) {
|
|
173
169
|
validateSettings(entry.settings, ctx, rootCtx);
|
|
174
170
|
}
|
|
175
|
-
|
|
176
|
-
validateBranchName(entry.prOptions.branch);
|
|
177
|
-
}
|
|
178
|
-
validateAiOption(entry.prOptions?.ai);
|
|
171
|
+
validatePrOptions(entry.prOptions, ctx);
|
|
179
172
|
}
|
|
180
173
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function validateInheritFlag(block: Record<string, unknown>, context: string): void;
|
|
2
|
+
/** Root blocks have nothing to inherit from, so `inherit` there is a mistake. */
|
|
3
|
+
export declare function assertNoRootInherit(block: unknown, name: string, context?: string): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ValidationError } from "../../shared/errors.js";
|
|
2
|
+
import { isPlainObject } from "../../shared/type-guards.js";
|
|
3
|
+
export function validateInheritFlag(block, context) {
|
|
4
|
+
if (block.inherit !== undefined && typeof block.inherit !== "boolean") {
|
|
5
|
+
throw new ValidationError(`${context}: inherit must be a boolean`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Root blocks have nothing to inherit from, so `inherit` there is a mistake. */
|
|
9
|
+
export function assertNoRootInherit(block, name, context = "") {
|
|
10
|
+
if (!isPlainObject(block) || !("inherit" in block))
|
|
11
|
+
return;
|
|
12
|
+
const prefix = context ? `${context}: ` : "";
|
|
13
|
+
throw new ValidationError(`${prefix}'inherit' is not allowed in root-level ${name} (nothing to inherit from)`);
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ValidationError } from "../../shared/errors.js";
|
|
2
|
+
import { validateBranchName } from "../../shared/branch-validation.js";
|
|
3
|
+
import { arrayValues, explainNotArray } from "../array-directive.js";
|
|
4
|
+
import { validateAiLayer } from "./ai-validator.js";
|
|
5
|
+
import { assertNoRootInherit } from "./inherit-flag.js";
|
|
6
|
+
/** Validates prOptions of one layer; `context` names the layer, empty for the root. */
|
|
7
|
+
export function validatePrOptions(prOptions, context = "") {
|
|
8
|
+
if (prOptions === undefined)
|
|
9
|
+
return;
|
|
10
|
+
const prefix = context ? `${context}: ` : "";
|
|
11
|
+
if (!context)
|
|
12
|
+
assertNoRootInherit(prOptions, "prOptions");
|
|
13
|
+
if (prOptions.inherit !== undefined &&
|
|
14
|
+
typeof prOptions.inherit !== "boolean") {
|
|
15
|
+
throw new ValidationError(`${prefix}prOptions.inherit must be a boolean`);
|
|
16
|
+
}
|
|
17
|
+
if (prOptions.branch !== undefined) {
|
|
18
|
+
validateBranchName(prOptions.branch);
|
|
19
|
+
}
|
|
20
|
+
validateAiLayer(prOptions.ai, context);
|
|
21
|
+
if (prOptions.labels === undefined)
|
|
22
|
+
return;
|
|
23
|
+
const labels = arrayValues(prOptions.labels);
|
|
24
|
+
if (labels === null) {
|
|
25
|
+
throw new ValidationError(explainNotArray(`${prefix}prOptions.labels must be an array of strings or $arrayMerge directive`, prOptions.labels));
|
|
26
|
+
}
|
|
27
|
+
for (const label of labels) {
|
|
28
|
+
if (typeof label !== "string" || label.length === 0) {
|
|
29
|
+
throw new ValidationError(`${prefix}prOptions.labels entries must be non-empty strings`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -3,8 +3,7 @@ import { validateFileName } from "./file-validator.js";
|
|
|
3
3
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
4
4
|
import { escapeRegExp } from "../../shared/regex-utils.js";
|
|
5
5
|
import { ValidationError } from "../../shared/errors.js";
|
|
6
|
-
import {
|
|
7
|
-
import { validateAiOption } from "./ai-validator.js";
|
|
6
|
+
import { validatePrOptions } from "./pr-options-validator.js";
|
|
8
7
|
import { validateFileConfigFields, validateSettings, buildRootSettingsContext, enrichSettingsContext, } from "./shared.js";
|
|
9
8
|
function isValidGitUrl(url) {
|
|
10
9
|
return /^git@[^:]+:.+$/.test(url) || /^https?:\/\/[^/]+\/.+$/.test(url);
|
|
@@ -158,17 +157,11 @@ function validateRepoSettingsEntry(config, repo, repoLabel) {
|
|
|
158
157
|
}
|
|
159
158
|
validateSettings(repo.settings, `Repo ${repoLabel}`, rootCtx);
|
|
160
159
|
}
|
|
161
|
-
function validateRepoPrOptions(repo) {
|
|
162
|
-
if (repo.prOptions?.branch !== undefined) {
|
|
163
|
-
validateBranchName(repo.prOptions.branch);
|
|
164
|
-
}
|
|
165
|
-
validateAiOption(repo.prOptions?.ai);
|
|
166
|
-
}
|
|
167
160
|
export function validateRepoEntry(config, repo, index) {
|
|
168
161
|
const repoLabel = validateRepoGitField(repo, index);
|
|
169
162
|
validateRepoOrigins(config, repo, repoLabel);
|
|
170
163
|
validateRepoGroups(config, repo, index);
|
|
171
164
|
validateRepoFiles(config, repo, index, repoLabel);
|
|
172
165
|
validateRepoSettingsEntry(config, repo, repoLabel);
|
|
173
|
-
|
|
166
|
+
validatePrOptions(repo.prOptions, `Repo ${repoLabel}`);
|
|
174
167
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ValidationError } from "../../shared/errors.js";
|
|
2
2
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
3
|
+
import { arrayValues, explainNotArray } from "../array-directive.js";
|
|
3
4
|
import { validValues } from "./file-validator.js";
|
|
4
5
|
const VALID_RULESET_TARGETS = validValues(["branch", "tag"]);
|
|
5
6
|
const VALID_ENFORCEMENT_LEVELS = validValues([
|
|
@@ -64,35 +65,22 @@ const VALID_RULE_TYPES = validValues([
|
|
|
64
65
|
"max_file_path_length",
|
|
65
66
|
"max_file_size",
|
|
66
67
|
]);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!isPlainObject(value))
|
|
76
|
-
return false;
|
|
77
|
-
return (Object.keys(value).every((k) => DIRECTIVE_KEYS.has(k)) &&
|
|
78
|
-
VALID_MERGE_STRATEGIES.includes(value.$arrayMerge) &&
|
|
79
|
-
Array.isArray(value.$values) &&
|
|
80
|
-
(value.$matchBy === undefined || typeof value.$matchBy === "string"));
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Extracts the $values array from a directive, or returns the value as-is if it's already an array.
|
|
84
|
-
* Returns null if value is neither an array nor a valid directive.
|
|
85
|
-
*/
|
|
86
|
-
function extractArrayOrDirectiveValues(value) {
|
|
87
|
-
if (Array.isArray(value))
|
|
88
|
-
return value;
|
|
89
|
-
if (isArrayMergeDirective(value))
|
|
90
|
-
return value.$values;
|
|
91
|
-
return null;
|
|
68
|
+
function arrayParam(params, key, context) {
|
|
69
|
+
if (params[key] === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
const values = arrayValues(params[key]);
|
|
72
|
+
if (values === null) {
|
|
73
|
+
throw new ValidationError(explainNotArray(`${context}: ${key} must be an array or $arrayMerge directive`, params[key]));
|
|
74
|
+
}
|
|
75
|
+
return values;
|
|
92
76
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
const ARRAY_PARAMS_BY_RULE_TYPE = {
|
|
78
|
+
required_status_checks: ["requiredStatusChecks"],
|
|
79
|
+
required_deployments: ["requiredDeploymentEnvironments"],
|
|
80
|
+
workflows: ["workflows"],
|
|
81
|
+
file_path_restriction: ["restrictedFilePaths"],
|
|
82
|
+
file_extension_restriction: ["restrictedFileExtensions"],
|
|
83
|
+
};
|
|
96
84
|
function validateRule(rule, context) {
|
|
97
85
|
if (typeof rule !== "object" || rule === null || Array.isArray(rule)) {
|
|
98
86
|
throw new ValidationError(`${context}: rule must be an object`);
|
|
@@ -104,7 +92,6 @@ function validateRule(rule, context) {
|
|
|
104
92
|
if (!VALID_RULE_TYPES.includes(r.type)) {
|
|
105
93
|
throw new ValidationError(`${context}: invalid rule type '${r.type}'. Must be one of: ${VALID_RULE_TYPES.join(", ")}`);
|
|
106
94
|
}
|
|
107
|
-
// Validate parameters based on rule type
|
|
108
95
|
if (r.parameters !== undefined) {
|
|
109
96
|
if (typeof r.parameters !== "object" ||
|
|
110
97
|
r.parameters === null ||
|
|
@@ -112,7 +99,6 @@ function validateRule(rule, context) {
|
|
|
112
99
|
throw new ValidationError(`${context}: rule parameters must be an object`);
|
|
113
100
|
}
|
|
114
101
|
const params = r.parameters;
|
|
115
|
-
// Validate pattern rule parameters
|
|
116
102
|
if (r.type.toString().endsWith("_pattern")) {
|
|
117
103
|
if (params.operator !== undefined &&
|
|
118
104
|
!VALID_PATTERN_OPERATORS.includes(params.operator)) {
|
|
@@ -122,7 +108,6 @@ function validateRule(rule, context) {
|
|
|
122
108
|
throw new ValidationError(`${context}: pattern rule pattern must be a string`);
|
|
123
109
|
}
|
|
124
110
|
}
|
|
125
|
-
// Validate pull_request parameters
|
|
126
111
|
if (r.type === "pull_request") {
|
|
127
112
|
if (params.requiredApprovingReviewCount !== undefined) {
|
|
128
113
|
const count = params.requiredApprovingReviewCount;
|
|
@@ -133,23 +118,22 @@ function validateRule(rule, context) {
|
|
|
133
118
|
throw new ValidationError(`${context}: requiredApprovingReviewCount must be an integer between 0 and 10`);
|
|
134
119
|
}
|
|
135
120
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
121
|
+
const methods = arrayParam(params, "allowedMergeMethods", context);
|
|
122
|
+
for (const method of methods ?? []) {
|
|
123
|
+
if (!VALID_MERGE_METHODS.includes(method)) {
|
|
124
|
+
throw new ValidationError(`${context}: allowedMergeMethods values must be one of: ${VALID_MERGE_METHODS.join(", ")}`);
|
|
139
125
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
126
|
+
}
|
|
127
|
+
const reviewers = arrayParam(params, "requiredReviewers", context);
|
|
128
|
+
for (const reviewer of reviewers ?? []) {
|
|
129
|
+
if (isPlainObject(reviewer)) {
|
|
130
|
+
arrayParam(reviewer, "filePatterns", `${context}: requiredReviewers`);
|
|
144
131
|
}
|
|
145
132
|
}
|
|
146
133
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
throw new ValidationError(`${context}: codeScanningTools must be an array`);
|
|
151
|
-
}
|
|
152
|
-
for (const tool of params.codeScanningTools) {
|
|
134
|
+
if (r.type === "code_scanning") {
|
|
135
|
+
const tools = arrayParam(params, "codeScanningTools", context);
|
|
136
|
+
for (const tool of tools ?? []) {
|
|
153
137
|
if (typeof tool !== "object" || tool === null) {
|
|
154
138
|
throw new ValidationError(`${context}: each codeScanningTool must be an object`);
|
|
155
139
|
}
|
|
@@ -164,11 +148,11 @@ function validateRule(rule, context) {
|
|
|
164
148
|
}
|
|
165
149
|
}
|
|
166
150
|
}
|
|
151
|
+
for (const key of ARRAY_PARAMS_BY_RULE_TYPE[r.type] ?? []) {
|
|
152
|
+
arrayParam(params, key, context);
|
|
153
|
+
}
|
|
167
154
|
}
|
|
168
155
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Validates a single ruleset.
|
|
171
|
-
*/
|
|
172
156
|
export function validateRuleset(ruleset, name, context) {
|
|
173
157
|
if (typeof ruleset !== "object" ||
|
|
174
158
|
ruleset === null ||
|
|
@@ -184,11 +168,10 @@ export function validateRuleset(ruleset, name, context) {
|
|
|
184
168
|
!VALID_ENFORCEMENT_LEVELS.includes(rs.enforcement)) {
|
|
185
169
|
throw new ValidationError(`${context}: ruleset '${name}' enforcement must be one of: ${VALID_ENFORCEMENT_LEVELS.join(", ")}`);
|
|
186
170
|
}
|
|
187
|
-
// Validate bypassActors
|
|
188
171
|
if (rs.bypassActors !== undefined) {
|
|
189
|
-
const actors =
|
|
172
|
+
const actors = arrayValues(rs.bypassActors);
|
|
190
173
|
if (actors === null) {
|
|
191
|
-
throw new ValidationError(`${context}: ruleset '${name}' bypassActors must be an array or $arrayMerge directive
|
|
174
|
+
throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' bypassActors must be an array or $arrayMerge directive`, rs.bypassActors));
|
|
192
175
|
}
|
|
193
176
|
for (let i = 0; i < actors.length; i++) {
|
|
194
177
|
const actor = actors[i];
|
|
@@ -207,7 +190,6 @@ export function validateRuleset(ruleset, name, context) {
|
|
|
207
190
|
}
|
|
208
191
|
}
|
|
209
192
|
}
|
|
210
|
-
// Validate conditions
|
|
211
193
|
if (rs.conditions !== undefined) {
|
|
212
194
|
if (typeof rs.conditions !== "object" ||
|
|
213
195
|
rs.conditions === null ||
|
|
@@ -223,24 +205,23 @@ export function validateRuleset(ruleset, name, context) {
|
|
|
223
205
|
throw new ValidationError(`${context}: ruleset '${name}' conditions.refName must be an object`);
|
|
224
206
|
}
|
|
225
207
|
if (refName.include !== undefined) {
|
|
226
|
-
const include =
|
|
208
|
+
const include = arrayValues(refName.include);
|
|
227
209
|
if (include === null || !include.every((s) => typeof s === "string")) {
|
|
228
|
-
throw new ValidationError(`${context}: ruleset '${name}' conditions.refName.include must be an array of strings or $arrayMerge directive with string $values
|
|
210
|
+
throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' conditions.refName.include must be an array of strings or $arrayMerge directive with string $values`, refName.include));
|
|
229
211
|
}
|
|
230
212
|
}
|
|
231
213
|
if (refName.exclude !== undefined) {
|
|
232
|
-
const exclude =
|
|
214
|
+
const exclude = arrayValues(refName.exclude);
|
|
233
215
|
if (exclude === null || !exclude.every((s) => typeof s === "string")) {
|
|
234
|
-
throw new ValidationError(`${context}: ruleset '${name}' conditions.refName.exclude must be an array of strings or $arrayMerge directive with string $values
|
|
216
|
+
throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' conditions.refName.exclude must be an array of strings or $arrayMerge directive with string $values`, refName.exclude));
|
|
235
217
|
}
|
|
236
218
|
}
|
|
237
219
|
}
|
|
238
220
|
}
|
|
239
|
-
// Validate rules array
|
|
240
221
|
if (rs.rules !== undefined) {
|
|
241
|
-
const rules =
|
|
222
|
+
const rules = arrayValues(rs.rules);
|
|
242
223
|
if (rules === null) {
|
|
243
|
-
throw new ValidationError(`${context}: ruleset '${name}' rules must be an array or $arrayMerge directive
|
|
224
|
+
throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' rules must be an array or $arrayMerge directive`, rs.rules));
|
|
244
225
|
}
|
|
245
226
|
for (let i = 0; i < rules.length; i++) {
|
|
246
227
|
validateRule(rules[i], `${context}: ruleset '${name}' rules[${i}]`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RawConfig, RawRootSettings, RawRepoSettings } from "../types.js";
|
|
2
|
+
import type { RawCodeScanningSettings, DeploymentBranchPolicy } from "../types.js";
|
|
2
3
|
export interface RootSettingsContext {
|
|
3
4
|
rulesetNames: string[];
|
|
4
5
|
hasRepoSettings: boolean;
|
|
@@ -8,5 +9,12 @@ export interface RootSettingsContext {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function buildRootSettingsContext(config: RawConfig): RootSettingsContext;
|
|
10
11
|
export declare function validateFileConfigFields(fileConfig: Record<string, unknown>, fileName: string, context: string): void;
|
|
12
|
+
/** A layer may omit `state` and inherit it, so only the merged block can be checked. */
|
|
13
|
+
export declare function validateMergedCodeScanningSettings(codeScanning: RawCodeScanningSettings | undefined, context: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* A layer sets only some fields, so the options that must go together are
|
|
16
|
+
* checked on the merged policy.
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateDeploymentBranchPolicy(policy: DeploymentBranchPolicy, context: string): void;
|
|
11
19
|
export declare function validateSettings(settings: unknown, context: string, rootCtx?: RootSettingsContext): void;
|
|
12
20
|
export declare function enrichSettingsContext(rootCtx: RootSettingsContext, settings: RawRepoSettings | RawRootSettings | undefined): void;
|