@aspruyt/xfg 3.7.5 → 3.7.7
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/cli/index.d.ts +6 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/program.d.ts +2 -0
- package/dist/cli/program.js +70 -0
- package/dist/cli/settings-command.d.ts +10 -0
- package/dist/cli/settings-command.js +228 -0
- package/dist/cli/sync-command.d.ts +25 -0
- package/dist/cli/sync-command.js +155 -0
- package/dist/cli/types.d.ts +45 -0
- package/dist/cli/types.js +15 -0
- package/dist/cli.js +2 -19
- package/dist/{file-reference-resolver.d.ts → config/file-reference-resolver.d.ts} +1 -1
- package/dist/config/index.d.ts +7 -0
- package/dist/config/index.js +12 -0
- package/dist/config/loader.d.ts +9 -0
- package/dist/{config.js → config/loader.js} +3 -24
- package/dist/{config-normalizer.d.ts → config/normalizer.d.ts} +1 -1
- package/dist/{config-normalizer.js → config/normalizer.js} +1 -1
- package/dist/{config.d.ts → config/types.d.ts} +5 -9
- package/dist/config/types.js +16 -0
- package/dist/{config-validator.d.ts → config/validator.d.ts} +5 -5
- package/dist/{config-validator.js → config/validator.js} +60 -372
- package/dist/config/validators/file-validator.d.ts +22 -0
- package/dist/config/validators/file-validator.js +46 -0
- package/dist/config/validators/index.d.ts +3 -0
- package/dist/config/validators/index.js +6 -0
- package/dist/config/validators/repo-settings-validator.d.ts +10 -0
- package/dist/config/validators/repo-settings-validator.js +71 -0
- package/dist/config/validators/ruleset-validator.d.ts +18 -0
- package/dist/config/validators/ruleset-validator.js +201 -0
- package/dist/index.d.ts +3 -66
- package/dist/index.js +3 -474
- package/dist/output/index.d.ts +4 -0
- package/dist/output/index.js +8 -0
- package/dist/{summary-utils.d.ts → output/summary-utils.d.ts} +3 -3
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.js +6 -0
- package/dist/{repo-settings-diff.d.ts → settings/repo-settings/diff.d.ts} +2 -2
- package/dist/{repo-settings-plan-formatter.d.ts → settings/repo-settings/formatter.d.ts} +1 -1
- package/dist/{strategies → settings/repo-settings}/github-repo-settings-strategy.d.ts +4 -4
- package/dist/{strategies → settings/repo-settings}/github-repo-settings-strategy.js +3 -3
- package/dist/settings/repo-settings/index.d.ts +5 -0
- package/dist/settings/repo-settings/index.js +10 -0
- package/dist/{repo-settings-processor.d.ts → settings/repo-settings/processor.d.ts} +4 -4
- package/dist/{repo-settings-processor.js → settings/repo-settings/processor.js} +6 -6
- package/dist/{strategies/repo-settings-strategy.d.ts → settings/repo-settings/types.d.ts} +2 -2
- package/dist/{resource-converters.d.ts → settings/resource-converters.d.ts} +4 -4
- package/dist/settings/rulesets/diff-algorithm.d.ts +18 -0
- package/dist/settings/rulesets/diff-algorithm.js +166 -0
- package/dist/{ruleset-diff.d.ts → settings/rulesets/diff.d.ts} +2 -2
- package/dist/{ruleset-diff.js → settings/rulesets/diff.js} +1 -1
- package/dist/{ruleset-plan-formatter.d.ts → settings/rulesets/formatter.d.ts} +4 -12
- package/dist/{ruleset-plan-formatter.js → settings/rulesets/formatter.js} +5 -166
- package/dist/{strategies → settings/rulesets}/github-ruleset-strategy.d.ts +4 -4
- package/dist/{strategies → settings/rulesets}/github-ruleset-strategy.js +3 -3
- package/dist/settings/rulesets/index.d.ts +6 -0
- package/dist/settings/rulesets/index.js +10 -0
- package/dist/{ruleset-processor.d.ts → settings/rulesets/processor.d.ts} +4 -4
- package/dist/{ruleset-processor.js → settings/rulesets/processor.js} +6 -6
- package/dist/{strategies/ruleset-strategy.d.ts → settings/rulesets/types.d.ts} +2 -2
- package/dist/{command-executor.d.ts → shared/command-executor.d.ts} +10 -2
- package/dist/{command-executor.js → shared/command-executor.js} +2 -1
- package/dist/shared/index.d.ts +8 -0
- package/dist/shared/index.js +16 -0
- package/dist/{logger.d.ts → shared/logger.d.ts} +1 -1
- package/dist/{logger.js → shared/logger.js} +1 -1
- package/dist/sync/auth-options-builder.d.ts +12 -0
- package/dist/sync/auth-options-builder.js +54 -0
- package/dist/sync/branch-manager.d.ts +7 -0
- package/dist/sync/branch-manager.js +36 -0
- package/dist/sync/commit-message.d.ts +11 -0
- package/dist/sync/commit-message.js +27 -0
- package/dist/sync/commit-push-manager.d.ts +8 -0
- package/dist/sync/commit-push-manager.js +71 -0
- package/dist/sync/file-sync-orchestrator.d.ts +11 -0
- package/dist/sync/file-sync-orchestrator.js +58 -0
- package/dist/sync/file-writer.d.ts +18 -0
- package/dist/sync/file-writer.js +101 -0
- package/dist/sync/index.d.ts +14 -0
- package/dist/sync/index.js +17 -0
- package/dist/sync/manifest-manager.d.ts +10 -0
- package/dist/sync/manifest-manager.js +64 -0
- package/dist/sync/pr-merge-handler.d.ts +11 -0
- package/dist/sync/pr-merge-handler.js +62 -0
- package/dist/sync/repository-processor.d.ts +30 -0
- package/dist/sync/repository-processor.js +278 -0
- package/dist/sync/repository-session.d.ts +9 -0
- package/dist/sync/repository-session.js +35 -0
- package/dist/sync/types.d.ts +296 -0
- package/dist/{xfg-template.d.ts → sync/xfg-template.d.ts} +2 -2
- package/dist/{authenticated-git-ops.js → vcs/authenticated-git-ops.js} +3 -3
- package/dist/{strategies → vcs}/azure-pr-strategy.d.ts +2 -2
- package/dist/{strategies → vcs}/azure-pr-strategy.js +5 -5
- package/dist/{strategies → vcs}/commit-strategy-selector.d.ts +3 -3
- package/dist/{strategies → vcs}/commit-strategy-selector.js +1 -1
- package/dist/{strategies → vcs}/git-commit-strategy.d.ts +2 -2
- package/dist/{strategies → vcs}/git-commit-strategy.js +3 -3
- package/dist/{git-ops.d.ts → vcs/git-ops.d.ts} +1 -1
- package/dist/{git-ops.js → vcs/git-ops.js} +4 -4
- package/dist/{github-app-token-manager.d.ts → vcs/github-app-token-manager.d.ts} +1 -1
- package/dist/{github-app-token-manager.js → vcs/github-app-token-manager.js} +1 -1
- package/dist/{strategies → vcs}/github-pr-strategy.d.ts +2 -2
- package/dist/{strategies → vcs}/github-pr-strategy.js +30 -33
- package/dist/{strategies → vcs}/gitlab-pr-strategy.d.ts +2 -2
- package/dist/{strategies → vcs}/gitlab-pr-strategy.js +5 -5
- package/dist/{strategies → vcs}/graphql-commit-strategy.d.ts +2 -2
- package/dist/{strategies → vcs}/graphql-commit-strategy.js +3 -3
- package/dist/vcs/index.d.ts +16 -0
- package/dist/{strategies → vcs}/index.js +15 -10
- package/dist/{pr-creator.d.ts → vcs/pr-creator.d.ts} +4 -4
- package/dist/{pr-creator.js → vcs/pr-creator.js} +3 -3
- package/dist/vcs/pr-strategy.d.ts +41 -0
- package/dist/{strategies → vcs}/pr-strategy.js +1 -1
- package/dist/{strategies/pr-strategy.d.ts → vcs/types.d.ts} +32 -35
- package/dist/vcs/types.js +1 -0
- package/package.json +2 -2
- package/dist/repository-processor.d.ts +0 -79
- package/dist/repository-processor.js +0 -659
- package/dist/strategies/commit-strategy.d.ts +0 -36
- package/dist/strategies/index.d.ts +0 -18
- /package/dist/{file-reference-resolver.js → config/file-reference-resolver.js} +0 -0
- /package/dist/{config-formatter.d.ts → config/formatter.d.ts} +0 -0
- /package/dist/{config-formatter.js → config/formatter.js} +0 -0
- /package/dist/{merge.d.ts → config/merge.d.ts} +0 -0
- /package/dist/{merge.js → config/merge.js} +0 -0
- /package/dist/{github-summary.d.ts → output/github-summary.d.ts} +0 -0
- /package/dist/{github-summary.js → output/github-summary.js} +0 -0
- /package/dist/{plan-formatter.d.ts → output/plan-formatter.d.ts} +0 -0
- /package/dist/{plan-formatter.js → output/plan-formatter.js} +0 -0
- /package/dist/{plan-summary.d.ts → output/plan-summary.d.ts} +0 -0
- /package/dist/{plan-summary.js → output/plan-summary.js} +0 -0
- /package/dist/{summary-utils.js → output/summary-utils.js} +0 -0
- /package/dist/{repo-settings-diff.js → settings/repo-settings/diff.js} +0 -0
- /package/dist/{repo-settings-plan-formatter.js → settings/repo-settings/formatter.js} +0 -0
- /package/dist/{strategies/repo-settings-strategy.js → settings/repo-settings/types.js} +0 -0
- /package/dist/{resource-converters.js → settings/resource-converters.js} +0 -0
- /package/dist/{strategies/commit-strategy.js → settings/rulesets/types.js} +0 -0
- /package/dist/{env.d.ts → shared/env.d.ts} +0 -0
- /package/dist/{env.js → shared/env.js} +0 -0
- /package/dist/{repo-detector.d.ts → shared/repo-detector.d.ts} +0 -0
- /package/dist/{repo-detector.js → shared/repo-detector.js} +0 -0
- /package/dist/{retry-utils.d.ts → shared/retry-utils.d.ts} +0 -0
- /package/dist/{retry-utils.js → shared/retry-utils.js} +0 -0
- /package/dist/{sanitize-utils.d.ts → shared/sanitize-utils.d.ts} +0 -0
- /package/dist/{sanitize-utils.js → shared/sanitize-utils.js} +0 -0
- /package/dist/{shell-utils.d.ts → shared/shell-utils.d.ts} +0 -0
- /package/dist/{shell-utils.js → shared/shell-utils.js} +0 -0
- /package/dist/{workspace-utils.d.ts → shared/workspace-utils.d.ts} +0 -0
- /package/dist/{workspace-utils.js → shared/workspace-utils.js} +0 -0
- /package/dist/{diff-utils.d.ts → sync/diff-utils.d.ts} +0 -0
- /package/dist/{diff-utils.js → sync/diff-utils.js} +0 -0
- /package/dist/{manifest.d.ts → sync/manifest.d.ts} +0 -0
- /package/dist/{manifest.js → sync/manifest.js} +0 -0
- /package/dist/{strategies/ruleset-strategy.js → sync/types.js} +0 -0
- /package/dist/{xfg-template.js → sync/xfg-template.js} +0 -0
- /package/dist/{authenticated-git-ops.d.ts → vcs/authenticated-git-ops.d.ts} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const VALID_VISIBILITY = ["public", "private", "internal"];
|
|
2
|
+
const VALID_SQUASH_MERGE_COMMIT_TITLE = ["PR_TITLE", "COMMIT_OR_PR_TITLE"];
|
|
3
|
+
const VALID_SQUASH_MERGE_COMMIT_MESSAGE = [
|
|
4
|
+
"PR_BODY",
|
|
5
|
+
"COMMIT_MESSAGES",
|
|
6
|
+
"BLANK",
|
|
7
|
+
];
|
|
8
|
+
const VALID_MERGE_COMMIT_TITLE = ["PR_TITLE", "MERGE_MESSAGE"];
|
|
9
|
+
const VALID_MERGE_COMMIT_MESSAGE = ["PR_BODY", "PR_TITLE", "BLANK"];
|
|
10
|
+
/**
|
|
11
|
+
* Validates GitHub repository settings.
|
|
12
|
+
*/
|
|
13
|
+
export function validateRepoSettings(repo, context) {
|
|
14
|
+
if (typeof repo !== "object" || repo === null || Array.isArray(repo)) {
|
|
15
|
+
throw new Error(`${context}: repo must be an object`);
|
|
16
|
+
}
|
|
17
|
+
const r = repo;
|
|
18
|
+
// Validate boolean fields
|
|
19
|
+
const booleanFields = [
|
|
20
|
+
"hasIssues",
|
|
21
|
+
"hasProjects",
|
|
22
|
+
"hasWiki",
|
|
23
|
+
"hasDiscussions",
|
|
24
|
+
"isTemplate",
|
|
25
|
+
"allowForking",
|
|
26
|
+
"archived",
|
|
27
|
+
"allowSquashMerge",
|
|
28
|
+
"allowMergeCommit",
|
|
29
|
+
"allowRebaseMerge",
|
|
30
|
+
"allowAutoMerge",
|
|
31
|
+
"deleteBranchOnMerge",
|
|
32
|
+
"allowUpdateBranch",
|
|
33
|
+
"vulnerabilityAlerts",
|
|
34
|
+
"automatedSecurityFixes",
|
|
35
|
+
"secretScanning",
|
|
36
|
+
"secretScanningPushProtection",
|
|
37
|
+
"privateVulnerabilityReporting",
|
|
38
|
+
"webCommitSignoffRequired",
|
|
39
|
+
];
|
|
40
|
+
for (const field of booleanFields) {
|
|
41
|
+
if (r[field] !== undefined && typeof r[field] !== "boolean") {
|
|
42
|
+
throw new Error(`${context}: ${field} must be a boolean`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Validate string fields
|
|
46
|
+
if (r.defaultBranch !== undefined && typeof r.defaultBranch !== "string") {
|
|
47
|
+
throw new Error(`${context}: defaultBranch must be a string`);
|
|
48
|
+
}
|
|
49
|
+
// Validate enum fields
|
|
50
|
+
if (r.visibility !== undefined &&
|
|
51
|
+
!VALID_VISIBILITY.includes(r.visibility)) {
|
|
52
|
+
throw new Error(`${context}: visibility must be one of: ${VALID_VISIBILITY.join(", ")}`);
|
|
53
|
+
}
|
|
54
|
+
if (r.squashMergeCommitTitle !== undefined &&
|
|
55
|
+
!VALID_SQUASH_MERGE_COMMIT_TITLE.includes(r.squashMergeCommitTitle)) {
|
|
56
|
+
throw new Error(`${context}: squashMergeCommitTitle must be one of: ${VALID_SQUASH_MERGE_COMMIT_TITLE.join(", ")}`);
|
|
57
|
+
}
|
|
58
|
+
if (r.squashMergeCommitMessage !== undefined &&
|
|
59
|
+
!VALID_SQUASH_MERGE_COMMIT_MESSAGE.includes(r.squashMergeCommitMessage)) {
|
|
60
|
+
throw new Error(`${context}: squashMergeCommitMessage must be one of: ${VALID_SQUASH_MERGE_COMMIT_MESSAGE.join(", ")}`);
|
|
61
|
+
}
|
|
62
|
+
if (r.mergeCommitTitle !== undefined &&
|
|
63
|
+
!VALID_MERGE_COMMIT_TITLE.includes(r.mergeCommitTitle)) {
|
|
64
|
+
throw new Error(`${context}: mergeCommitTitle must be one of: ${VALID_MERGE_COMMIT_TITLE.join(", ")}`);
|
|
65
|
+
}
|
|
66
|
+
if (r.mergeCommitMessage !== undefined &&
|
|
67
|
+
!VALID_MERGE_COMMIT_MESSAGE.includes(r.mergeCommitMessage)) {
|
|
68
|
+
throw new Error(`${context}: mergeCommitMessage must be one of: ${VALID_MERGE_COMMIT_MESSAGE.join(", ")}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export { VALID_VISIBILITY, VALID_SQUASH_MERGE_COMMIT_TITLE, VALID_SQUASH_MERGE_COMMIT_MESSAGE, VALID_MERGE_COMMIT_TITLE, VALID_MERGE_COMMIT_MESSAGE, };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const VALID_RULESET_TARGETS: string[];
|
|
2
|
+
declare const VALID_ENFORCEMENT_LEVELS: string[];
|
|
3
|
+
declare const VALID_ACTOR_TYPES: string[];
|
|
4
|
+
declare const VALID_BYPASS_MODES: string[];
|
|
5
|
+
declare const VALID_PATTERN_OPERATORS: string[];
|
|
6
|
+
declare const VALID_MERGE_METHODS: string[];
|
|
7
|
+
declare const VALID_ALERTS_THRESHOLDS: string[];
|
|
8
|
+
declare const VALID_SECURITY_THRESHOLDS: string[];
|
|
9
|
+
declare const VALID_RULE_TYPES: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Validates a single ruleset rule.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateRule(rule: unknown, context: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Validates a single ruleset.
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateRuleset(ruleset: unknown, name: string, context: string): void;
|
|
18
|
+
export { VALID_RULESET_TARGETS, VALID_ENFORCEMENT_LEVELS, VALID_ACTOR_TYPES, VALID_BYPASS_MODES, VALID_PATTERN_OPERATORS, VALID_MERGE_METHODS, VALID_ALERTS_THRESHOLDS, VALID_SECURITY_THRESHOLDS, VALID_RULE_TYPES, };
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
const VALID_RULESET_TARGETS = ["branch", "tag"];
|
|
2
|
+
const VALID_ENFORCEMENT_LEVELS = ["active", "disabled", "evaluate"];
|
|
3
|
+
const VALID_ACTOR_TYPES = ["Team", "User", "Integration"];
|
|
4
|
+
const VALID_BYPASS_MODES = ["always", "pull_request"];
|
|
5
|
+
const VALID_PATTERN_OPERATORS = [
|
|
6
|
+
"starts_with",
|
|
7
|
+
"ends_with",
|
|
8
|
+
"contains",
|
|
9
|
+
"regex",
|
|
10
|
+
];
|
|
11
|
+
const VALID_MERGE_METHODS = ["merge", "squash", "rebase"];
|
|
12
|
+
const VALID_ALERTS_THRESHOLDS = [
|
|
13
|
+
"none",
|
|
14
|
+
"errors",
|
|
15
|
+
"errors_and_warnings",
|
|
16
|
+
"all",
|
|
17
|
+
];
|
|
18
|
+
const VALID_SECURITY_THRESHOLDS = [
|
|
19
|
+
"none",
|
|
20
|
+
"critical",
|
|
21
|
+
"high_or_higher",
|
|
22
|
+
"medium_or_higher",
|
|
23
|
+
"all",
|
|
24
|
+
];
|
|
25
|
+
const VALID_RULE_TYPES = [
|
|
26
|
+
"pull_request",
|
|
27
|
+
"required_status_checks",
|
|
28
|
+
"required_signatures",
|
|
29
|
+
"required_linear_history",
|
|
30
|
+
"non_fast_forward",
|
|
31
|
+
"creation",
|
|
32
|
+
"update",
|
|
33
|
+
"deletion",
|
|
34
|
+
"required_deployments",
|
|
35
|
+
"code_scanning",
|
|
36
|
+
"code_quality",
|
|
37
|
+
"workflows",
|
|
38
|
+
"commit_author_email_pattern",
|
|
39
|
+
"commit_message_pattern",
|
|
40
|
+
"committer_email_pattern",
|
|
41
|
+
"branch_name_pattern",
|
|
42
|
+
"tag_name_pattern",
|
|
43
|
+
"file_path_restriction",
|
|
44
|
+
"file_extension_restriction",
|
|
45
|
+
"max_file_path_length",
|
|
46
|
+
"max_file_size",
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Validates a single ruleset rule.
|
|
50
|
+
*/
|
|
51
|
+
export function validateRule(rule, context) {
|
|
52
|
+
if (typeof rule !== "object" || rule === null || Array.isArray(rule)) {
|
|
53
|
+
throw new Error(`${context}: rule must be an object`);
|
|
54
|
+
}
|
|
55
|
+
const r = rule;
|
|
56
|
+
if (!r.type || typeof r.type !== "string") {
|
|
57
|
+
throw new Error(`${context}: rule must have a 'type' string field`);
|
|
58
|
+
}
|
|
59
|
+
if (!VALID_RULE_TYPES.includes(r.type)) {
|
|
60
|
+
throw new Error(`${context}: invalid rule type '${r.type}'. Must be one of: ${VALID_RULE_TYPES.join(", ")}`);
|
|
61
|
+
}
|
|
62
|
+
// Validate parameters based on rule type
|
|
63
|
+
if (r.parameters !== undefined) {
|
|
64
|
+
if (typeof r.parameters !== "object" ||
|
|
65
|
+
r.parameters === null ||
|
|
66
|
+
Array.isArray(r.parameters)) {
|
|
67
|
+
throw new Error(`${context}: rule parameters must be an object`);
|
|
68
|
+
}
|
|
69
|
+
const params = r.parameters;
|
|
70
|
+
// Validate pattern rule parameters
|
|
71
|
+
if (r.type.toString().endsWith("_pattern")) {
|
|
72
|
+
if (params.operator !== undefined &&
|
|
73
|
+
!VALID_PATTERN_OPERATORS.includes(params.operator)) {
|
|
74
|
+
throw new Error(`${context}: pattern rule operator must be one of: ${VALID_PATTERN_OPERATORS.join(", ")}`);
|
|
75
|
+
}
|
|
76
|
+
if (params.pattern !== undefined && typeof params.pattern !== "string") {
|
|
77
|
+
throw new Error(`${context}: pattern rule pattern must be a string`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Validate pull_request parameters
|
|
81
|
+
if (r.type === "pull_request") {
|
|
82
|
+
if (params.requiredApprovingReviewCount !== undefined) {
|
|
83
|
+
const count = params.requiredApprovingReviewCount;
|
|
84
|
+
if (typeof count !== "number" ||
|
|
85
|
+
!Number.isInteger(count) ||
|
|
86
|
+
count < 0 ||
|
|
87
|
+
count > 10) {
|
|
88
|
+
throw new Error(`${context}: requiredApprovingReviewCount must be an integer between 0 and 10`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (params.allowedMergeMethods !== undefined) {
|
|
92
|
+
if (!Array.isArray(params.allowedMergeMethods)) {
|
|
93
|
+
throw new Error(`${context}: allowedMergeMethods must be an array`);
|
|
94
|
+
}
|
|
95
|
+
for (const method of params.allowedMergeMethods) {
|
|
96
|
+
if (!VALID_MERGE_METHODS.includes(method)) {
|
|
97
|
+
throw new Error(`${context}: allowedMergeMethods values must be one of: ${VALID_MERGE_METHODS.join(", ")}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Validate code_scanning parameters
|
|
103
|
+
if (r.type === "code_scanning" && params.codeScanningTools !== undefined) {
|
|
104
|
+
if (!Array.isArray(params.codeScanningTools)) {
|
|
105
|
+
throw new Error(`${context}: codeScanningTools must be an array`);
|
|
106
|
+
}
|
|
107
|
+
for (const tool of params.codeScanningTools) {
|
|
108
|
+
if (typeof tool !== "object" || tool === null) {
|
|
109
|
+
throw new Error(`${context}: each codeScanningTool must be an object`);
|
|
110
|
+
}
|
|
111
|
+
const t = tool;
|
|
112
|
+
if (t.alertsThreshold !== undefined &&
|
|
113
|
+
!VALID_ALERTS_THRESHOLDS.includes(t.alertsThreshold)) {
|
|
114
|
+
throw new Error(`${context}: alertsThreshold must be one of: ${VALID_ALERTS_THRESHOLDS.join(", ")}`);
|
|
115
|
+
}
|
|
116
|
+
if (t.securityAlertsThreshold !== undefined &&
|
|
117
|
+
!VALID_SECURITY_THRESHOLDS.includes(t.securityAlertsThreshold)) {
|
|
118
|
+
throw new Error(`${context}: securityAlertsThreshold must be one of: ${VALID_SECURITY_THRESHOLDS.join(", ")}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Validates a single ruleset.
|
|
126
|
+
*/
|
|
127
|
+
export function validateRuleset(ruleset, name, context) {
|
|
128
|
+
if (typeof ruleset !== "object" ||
|
|
129
|
+
ruleset === null ||
|
|
130
|
+
Array.isArray(ruleset)) {
|
|
131
|
+
throw new Error(`${context}: ruleset '${name}' must be an object`);
|
|
132
|
+
}
|
|
133
|
+
const rs = ruleset;
|
|
134
|
+
if (rs.target !== undefined &&
|
|
135
|
+
!VALID_RULESET_TARGETS.includes(rs.target)) {
|
|
136
|
+
throw new Error(`${context}: ruleset '${name}' target must be one of: ${VALID_RULESET_TARGETS.join(", ")}`);
|
|
137
|
+
}
|
|
138
|
+
if (rs.enforcement !== undefined &&
|
|
139
|
+
!VALID_ENFORCEMENT_LEVELS.includes(rs.enforcement)) {
|
|
140
|
+
throw new Error(`${context}: ruleset '${name}' enforcement must be one of: ${VALID_ENFORCEMENT_LEVELS.join(", ")}`);
|
|
141
|
+
}
|
|
142
|
+
// Validate bypassActors
|
|
143
|
+
if (rs.bypassActors !== undefined) {
|
|
144
|
+
if (!Array.isArray(rs.bypassActors)) {
|
|
145
|
+
throw new Error(`${context}: ruleset '${name}' bypassActors must be an array`);
|
|
146
|
+
}
|
|
147
|
+
for (let i = 0; i < rs.bypassActors.length; i++) {
|
|
148
|
+
const actor = rs.bypassActors[i];
|
|
149
|
+
if (typeof actor !== "object" || actor === null) {
|
|
150
|
+
throw new Error(`${context}: ruleset '${name}' bypassActors[${i}] must be an object`);
|
|
151
|
+
}
|
|
152
|
+
if (typeof actor.actorId !== "number") {
|
|
153
|
+
throw new Error(`${context}: ruleset '${name}' bypassActors[${i}].actorId must be a number`);
|
|
154
|
+
}
|
|
155
|
+
if (!VALID_ACTOR_TYPES.includes(actor.actorType)) {
|
|
156
|
+
throw new Error(`${context}: ruleset '${name}' bypassActors[${i}].actorType must be one of: ${VALID_ACTOR_TYPES.join(", ")}`);
|
|
157
|
+
}
|
|
158
|
+
if (actor.bypassMode !== undefined &&
|
|
159
|
+
!VALID_BYPASS_MODES.includes(actor.bypassMode)) {
|
|
160
|
+
throw new Error(`${context}: ruleset '${name}' bypassActors[${i}].bypassMode must be one of: ${VALID_BYPASS_MODES.join(", ")}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Validate conditions
|
|
165
|
+
if (rs.conditions !== undefined) {
|
|
166
|
+
if (typeof rs.conditions !== "object" ||
|
|
167
|
+
rs.conditions === null ||
|
|
168
|
+
Array.isArray(rs.conditions)) {
|
|
169
|
+
throw new Error(`${context}: ruleset '${name}' conditions must be an object`);
|
|
170
|
+
}
|
|
171
|
+
const conditions = rs.conditions;
|
|
172
|
+
if (conditions.refName !== undefined) {
|
|
173
|
+
const refName = conditions.refName;
|
|
174
|
+
if (typeof refName !== "object" ||
|
|
175
|
+
refName === null ||
|
|
176
|
+
Array.isArray(refName)) {
|
|
177
|
+
throw new Error(`${context}: ruleset '${name}' conditions.refName must be an object`);
|
|
178
|
+
}
|
|
179
|
+
if (refName.include !== undefined &&
|
|
180
|
+
(!Array.isArray(refName.include) ||
|
|
181
|
+
!refName.include.every((s) => typeof s === "string"))) {
|
|
182
|
+
throw new Error(`${context}: ruleset '${name}' conditions.refName.include must be an array of strings`);
|
|
183
|
+
}
|
|
184
|
+
if (refName.exclude !== undefined &&
|
|
185
|
+
(!Array.isArray(refName.exclude) ||
|
|
186
|
+
!refName.exclude.every((s) => typeof s === "string"))) {
|
|
187
|
+
throw new Error(`${context}: ruleset '${name}' conditions.refName.exclude must be an array of strings`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Validate rules array
|
|
192
|
+
if (rs.rules !== undefined) {
|
|
193
|
+
if (!Array.isArray(rs.rules)) {
|
|
194
|
+
throw new Error(`${context}: ruleset '${name}' rules must be an array`);
|
|
195
|
+
}
|
|
196
|
+
for (let i = 0; i < rs.rules.length; i++) {
|
|
197
|
+
validateRule(rs.rules[i], `${context}: ruleset '${name}' rules[${i}]`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
export { VALID_RULESET_TARGETS, VALID_ENFORCEMENT_LEVELS, VALID_ACTOR_TYPES, VALID_BYPASS_MODES, VALID_PATTERN_OPERATORS, VALID_MERGE_METHODS, VALID_ALERTS_THRESHOLDS, VALID_SECURITY_THRESHOLDS, VALID_RULE_TYPES, };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,66 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { ProcessorResult } from "./repository-processor.js";
|
|
5
|
-
import { RepoConfig } from "./config.js";
|
|
6
|
-
import { RepoInfo } from "./repo-detector.js";
|
|
7
|
-
import { ProcessorOptions } from "./repository-processor.js";
|
|
8
|
-
import { RulesetProcessorOptions, RulesetProcessorResult } from "./ruleset-processor.js";
|
|
9
|
-
import { IRepoSettingsProcessor } from "./repo-settings-processor.js";
|
|
10
|
-
/**
|
|
11
|
-
* Processor interface for dependency injection in tests.
|
|
12
|
-
*/
|
|
13
|
-
export interface IRepositoryProcessor {
|
|
14
|
-
process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: ProcessorOptions): Promise<ProcessorResult>;
|
|
15
|
-
updateManifestOnly(repoInfo: RepoInfo, repoConfig: RepoConfig, options: ProcessorOptions, manifestUpdate: {
|
|
16
|
-
rulesets: string[];
|
|
17
|
-
}): Promise<ProcessorResult>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Factory function type for creating processors.
|
|
21
|
-
* Allows dependency injection for testing.
|
|
22
|
-
*/
|
|
23
|
-
export type ProcessorFactory = () => IRepositoryProcessor;
|
|
24
|
-
/**
|
|
25
|
-
* Default factory that creates a real RepositoryProcessor.
|
|
26
|
-
*/
|
|
27
|
-
export declare const defaultProcessorFactory: ProcessorFactory;
|
|
28
|
-
/**
|
|
29
|
-
* Ruleset processor interface for dependency injection in tests.
|
|
30
|
-
*/
|
|
31
|
-
export interface IRulesetProcessor {
|
|
32
|
-
process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: RulesetProcessorOptions): Promise<RulesetProcessorResult>;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Factory function type for creating ruleset processors.
|
|
36
|
-
*/
|
|
37
|
-
export type RulesetProcessorFactory = () => IRulesetProcessor;
|
|
38
|
-
/**
|
|
39
|
-
* Default factory that creates a real RulesetProcessor.
|
|
40
|
-
*/
|
|
41
|
-
export declare const defaultRulesetProcessorFactory: RulesetProcessorFactory;
|
|
42
|
-
/**
|
|
43
|
-
* Repo settings processor factory function type.
|
|
44
|
-
*/
|
|
45
|
-
export type RepoSettingsProcessorFactory = () => IRepoSettingsProcessor;
|
|
46
|
-
/**
|
|
47
|
-
* Default factory that creates a real RepoSettingsProcessor.
|
|
48
|
-
*/
|
|
49
|
-
export declare const defaultRepoSettingsProcessorFactory: RepoSettingsProcessorFactory;
|
|
50
|
-
interface SharedOptions {
|
|
51
|
-
config: string;
|
|
52
|
-
dryRun?: boolean;
|
|
53
|
-
workDir?: string;
|
|
54
|
-
retries?: number;
|
|
55
|
-
noDelete?: boolean;
|
|
56
|
-
}
|
|
57
|
-
interface SyncOptions extends SharedOptions {
|
|
58
|
-
branch?: string;
|
|
59
|
-
merge?: MergeMode;
|
|
60
|
-
mergeStrategy?: MergeStrategy;
|
|
61
|
-
deleteBranch?: boolean;
|
|
62
|
-
}
|
|
63
|
-
type SettingsOptions = SharedOptions;
|
|
64
|
-
export declare function runSync(options: SyncOptions, processorFactory?: ProcessorFactory): Promise<void>;
|
|
65
|
-
export declare function runSettings(options: SettingsOptions, processorFactory?: RulesetProcessorFactory, repoProcessorFactory?: ProcessorFactory, repoSettingsProcessorFactory?: RepoSettingsProcessorFactory): Promise<void>;
|
|
66
|
-
export { program };
|
|
1
|
+
export { runSync, runSettings } from "./cli/index.js";
|
|
2
|
+
export type { SyncOptions, SettingsOptions, SharedOptions, } from "./cli/index.js";
|
|
3
|
+
export { type IRepositoryProcessor, type ProcessorFactory, defaultProcessorFactory, type IRulesetProcessor, type RulesetProcessorFactory, defaultRulesetProcessorFactory, type RepoSettingsProcessorFactory, defaultRepoSettingsProcessorFactory, } from "./cli/index.js";
|