@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.
- package/dist/cli/settings-factories.d.ts +2 -1
- package/dist/cli/settings-factories.js +6 -1
- package/dist/cli/settings-report-builder.d.ts +6 -1
- package/dist/cli/settings-report-builder.js +12 -0
- package/dist/cli/settings-runner.js +7 -0
- package/dist/cli/types.d.ts +4 -9
- 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/index.d.ts +2 -2
- package/dist/config/index.js +1 -3
- package/dist/config/merge.d.ts +6 -1
- package/dist/config/merge.js +13 -29
- package/dist/config/normalizer.d.ts +0 -8
- package/dist/config/normalizer.js +195 -238
- package/dist/config/types.d.ts +68 -37
- package/dist/config/types.js +6 -0
- package/dist/config/validator.d.ts +3 -9
- package/dist/config/validator.js +41 -45
- package/dist/config/validators/actions-validator.d.ts +7 -0
- package/dist/config/validators/actions-validator.js +139 -0
- 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 +9 -0
- package/dist/config/validators/shared.js +98 -28
- package/dist/settings/actions/diff.d.ts +11 -0
- package/dist/settings/actions/diff.js +32 -0
- package/dist/settings/actions/endpoints.d.ts +21 -0
- package/dist/settings/actions/endpoints.js +89 -0
- package/dist/settings/actions/formatter.d.ts +10 -0
- package/dist/settings/actions/formatter.js +11 -0
- package/dist/settings/actions/github-actions-strategy.d.ts +16 -0
- package/dist/settings/actions/github-actions-strategy.js +23 -0
- package/dist/settings/actions/index.d.ts +3 -0
- package/dist/settings/actions/index.js +2 -0
- package/dist/settings/actions/processor.d.ts +19 -0
- package/dist/settings/actions/processor.js +88 -0
- package/dist/settings/actions/resolve.d.ts +15 -0
- package/dist/settings/actions/resolve.js +42 -0
- package/dist/settings/actions/types.d.ts +9 -0
- package/dist/settings/actions/types.js +1 -0
- package/dist/settings/environments/processor.js +1 -1
- package/dist/settings/index.d.ts +1 -0
- package/dist/settings/index.js +1 -0
- package/dist/settings/labels/diff.js +1 -2
- package/dist/shared/credential-env.d.ts +4 -3
- package/dist/shared/credential-env.js +12 -7
- package/package.json +4 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ACTIONS_SELECTED_FIELDS, } from "../../config/index.js";
|
|
2
|
+
function drop(settings, fields, reason, warnings) {
|
|
3
|
+
const present = fields.filter((f) => settings[f] !== undefined);
|
|
4
|
+
if (present.length === 0)
|
|
5
|
+
return;
|
|
6
|
+
for (const field of present)
|
|
7
|
+
delete settings[field];
|
|
8
|
+
warnings.push(`actions: ${present.join(", ")} ignored: ${reason}`);
|
|
9
|
+
}
|
|
10
|
+
const FIELDS_NEEDING_ENABLED = [
|
|
11
|
+
"allowedActions",
|
|
12
|
+
"shaPinningRequired",
|
|
13
|
+
...ACTIONS_SELECTED_FIELDS,
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Drops merged fields GitHub would reject: a repo can override an inherited
|
|
17
|
+
* `selected` mode or disable Actions without restating the rest of the block.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveActionsSettings(actions) {
|
|
20
|
+
const settings = { ...actions };
|
|
21
|
+
const warnings = [];
|
|
22
|
+
if (settings.enabled === false) {
|
|
23
|
+
drop(settings, FIELDS_NEEDING_ENABLED, "GitHub Actions is disabled (enabled: false)", warnings);
|
|
24
|
+
}
|
|
25
|
+
if (settings.allowedActions !== undefined &&
|
|
26
|
+
settings.allowedActions !== "selected") {
|
|
27
|
+
drop(settings, ACTIONS_SELECTED_FIELDS, 'they only apply when allowedActions is "selected"', warnings);
|
|
28
|
+
}
|
|
29
|
+
return { settings, warnings };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Drops the fields GitHub rejects while Actions is off on the repo, unless the
|
|
33
|
+
* config turns it on, so an inherited block can't fail every run.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveForCurrentState(desired, current) {
|
|
36
|
+
const settings = { ...desired };
|
|
37
|
+
const warnings = [];
|
|
38
|
+
if (desired.enabled === undefined && current.enabled === false) {
|
|
39
|
+
drop(settings, FIELDS_NEEDING_ENABLED, "GitHub Actions is disabled on the repo (set enabled: true to apply them)", warnings);
|
|
40
|
+
}
|
|
41
|
+
return { settings, warnings };
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RepoInfo } from "../../repo/index.js";
|
|
2
|
+
import type { GhApiOptions } from "../../shared/gh-api-utils.js";
|
|
3
|
+
export type ActionsEndpointName = "permissions" | "selectedActions" | "workflow" | "forkPrApproval" | "artifactRetention" | "cacheRetention" | "cacheStorage";
|
|
4
|
+
/** JSON body of an Actions settings endpoint, in the API's snake_case. */
|
|
5
|
+
export type ActionsApiBody = Record<string, unknown>;
|
|
6
|
+
export interface IActionsStrategy {
|
|
7
|
+
get(repoInfo: RepoInfo, endpoint: ActionsEndpointName, options?: GhApiOptions): Promise<ActionsApiBody>;
|
|
8
|
+
update(repoInfo: RepoInfo, endpoint: ActionsEndpointName, payload: ActionsApiBody, options?: GhApiOptions): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -13,7 +13,7 @@ function environmentsOf(repoConfig) {
|
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
function isPermissionError(error) {
|
|
16
|
-
return
|
|
16
|
+
return toErrorMessage(error).includes("HTTP 403") && !isPaidPlanError(error);
|
|
17
17
|
}
|
|
18
18
|
async function deleteAsAdmin(what, run) {
|
|
19
19
|
try {
|
package/dist/settings/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { type PropertyDiff, type RulesetPlanEntry, RulesetProcessor, type IRules
|
|
|
3
3
|
export { RepoSettingsProcessor, type IRepoSettingsProcessor, type RepoSettingsPlanEntry, GitHubRepoSettingsStrategy, } from "./repo-settings/index.js";
|
|
4
4
|
export { type LabelsPlanEntry, LabelsProcessor, type ILabelsProcessor, GitHubLabelsStrategy, } from "./labels/index.js";
|
|
5
5
|
export { type CodeScanningPlanEntry, CodeScanningProcessor, type ICodeScanningProcessor, GitHubCodeScanningStrategy, } from "./code-scanning/index.js";
|
|
6
|
+
export { type ActionsPlanEntry, ActionsProcessor, type IActionsProcessor, GitHubActionsStrategy, } from "./actions/index.js";
|
|
6
7
|
export { type VariablesPlanEntry, VariablesProcessor, type IVariablesProcessor, GitHubVariablesStrategy, } from "./variables/index.js";
|
|
7
8
|
export { type CollaboratorsPlanEntry, CollaboratorsProcessor, type ICollaboratorsProcessor, GitHubCollaboratorsStrategy, } from "./collaborators/index.js";
|
|
8
9
|
export { type EnvironmentsPlanEntry, type EnvironmentsProcessorResult, EnvironmentsProcessor, type IEnvironmentsProcessor, type IEnvironmentSecretsStrategy, GitHubEnvironmentsStrategy, } from "./environments/index.js";
|
package/dist/settings/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { RulesetProcessor, GitHubRulesetStrategy, } from "./rulesets/index.js";
|
|
|
3
3
|
export { RepoSettingsProcessor, GitHubRepoSettingsStrategy, } from "./repo-settings/index.js";
|
|
4
4
|
export { LabelsProcessor, GitHubLabelsStrategy, } from "./labels/index.js";
|
|
5
5
|
export { CodeScanningProcessor, GitHubCodeScanningStrategy, } from "./code-scanning/index.js";
|
|
6
|
+
export { ActionsProcessor, GitHubActionsStrategy, } from "./actions/index.js";
|
|
6
7
|
export { VariablesProcessor, GitHubVariablesStrategy, } from "./variables/index.js";
|
|
7
8
|
export { CollaboratorsProcessor, GitHubCollaboratorsStrategy, } from "./collaborators/index.js";
|
|
8
9
|
export { EnvironmentsProcessor, GitHubEnvironmentsStrategy, } from "./environments/index.js";
|
|
@@ -115,8 +115,7 @@ export function diffLabels(current, desired, deleteOrphaned, noDelete) {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
if (labelConfig.new_name &&
|
|
119
|
-
labelConfig.new_name !== currentLabel.name) {
|
|
118
|
+
if (labelConfig.new_name && labelConfig.new_name !== currentLabel.name) {
|
|
120
119
|
propChanges.push({
|
|
121
120
|
property: "new_name",
|
|
122
121
|
oldValue: currentLabel.name,
|
|
@@ -14,8 +14,9 @@ export declare function assertAiKeyEnvAllowed(provider: string, apiKeyEnv: strin
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function assertAiHeadersEnvAllowed(headersEnv: unknown, path?: string): void;
|
|
16
16
|
/**
|
|
17
|
-
* `baseUrlEnv` names the env var that holds the base URL
|
|
18
|
-
*
|
|
19
|
-
* credential xfg uses elsewhere.
|
|
17
|
+
* `baseUrlEnv` names the env var that holds the base URL, never a URL or a credential xfg uses elsewhere.
|
|
18
|
+
* Checks the one field, so it also holds for a layer before the merge.
|
|
20
19
|
*/
|
|
20
|
+
export declare function assertAiBaseUrlEnvName(baseUrlEnv: unknown, path?: string): void;
|
|
21
|
+
/** `baseUrl` and `baseUrlEnv` are exclusive, then `baseUrlEnv` must pass its own checks. */
|
|
21
22
|
export declare function assertAiBaseUrlEnvAllowed(baseUrlEnv: unknown, baseUrl: unknown, path?: string): void;
|
|
@@ -92,16 +92,12 @@ export function assertAiHeadersEnvAllowed(headersEnv, path = "prOptions.ai") {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
|
-
* `baseUrlEnv` names the env var that holds the base URL
|
|
96
|
-
*
|
|
97
|
-
* credential xfg uses elsewhere.
|
|
95
|
+
* `baseUrlEnv` names the env var that holds the base URL, never a URL or a credential xfg uses elsewhere.
|
|
96
|
+
* Checks the one field, so it also holds for a layer before the merge.
|
|
98
97
|
*/
|
|
99
|
-
export function
|
|
98
|
+
export function assertAiBaseUrlEnvName(baseUrlEnv, path = "prOptions.ai") {
|
|
100
99
|
if (baseUrlEnv === undefined)
|
|
101
100
|
return;
|
|
102
|
-
if (baseUrl !== undefined) {
|
|
103
|
-
throw new ValidationError(`${path}: baseUrl and baseUrlEnv are mutually exclusive`);
|
|
104
|
-
}
|
|
105
101
|
if (typeof baseUrlEnv !== "string" || !ENV_NAME.test(baseUrlEnv)) {
|
|
106
102
|
throw new ValidationError(`${path}.baseUrlEnv must be an env var name, not a value`);
|
|
107
103
|
}
|
|
@@ -110,3 +106,12 @@ export function assertAiBaseUrlEnvAllowed(baseUrlEnv, baseUrl, path = "prOptions
|
|
|
110
106
|
`export the URL under a dedicated name.`);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
109
|
+
/** `baseUrl` and `baseUrlEnv` are exclusive, then `baseUrlEnv` must pass its own checks. */
|
|
110
|
+
export function assertAiBaseUrlEnvAllowed(baseUrlEnv, baseUrl, path = "prOptions.ai") {
|
|
111
|
+
if (baseUrlEnv === undefined)
|
|
112
|
+
return;
|
|
113
|
+
if (baseUrl !== undefined) {
|
|
114
|
+
throw new ValidationError(`${path}: baseUrl and baseUrlEnv are mutually exclusive`);
|
|
115
|
+
}
|
|
116
|
+
assertAiBaseUrlEnvName(baseUrlEnv, path);
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aspruyt/xfg",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Manage files, settings, and repositories across GitHub, Azure DevOps, and GitLab — declaratively, from a single YAML config",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"docs:generate": "tsx scripts/docs/generate-docs.ts",
|
|
39
39
|
"docs:check": "tsx scripts/docs/generate-docs.ts --check",
|
|
40
40
|
"test": "node --import tsx scripts/run-tests.js",
|
|
41
|
-
"test:coverage": "c8 --check-coverage --lines 95 --reporter=text --reporter=lcov --all --src=src --exclude='test/**/*.test.ts' --exclude='scripts/**' --exclude='src/vcs/types.ts' --exclude='src/settings/rulesets/types.ts' --exclude='src/settings/repo-settings/types.ts' --exclude='src/settings/labels/types.ts' --exclude='src/**/index.ts' --exclude='test/mocks/**' --exclude='test/integration/**' --exclude='src/sync/types.ts' --exclude='src/lifecycle/types.ts' --exclude='src/cli/program.ts' --exclude='src/repo/types.ts' --exclude='src/settings/secrets/types.ts' --exclude='src/settings/code-scanning/types.ts' --exclude='src/settings/variables/types.ts' --exclude='src/settings/collaborators/types.ts' --exclude='src/settings/environments/types.ts' --exclude='src/ai/types.ts' --exclude='src/cli/types.ts' --exclude='src/cli.ts' --exclude='src/index.ts' npm test",
|
|
41
|
+
"test:coverage": "c8 --check-coverage --lines 95 --reporter=text --reporter=lcov --all --src=src --exclude='test/**/*.test.ts' --exclude='scripts/**' --exclude='src/vcs/types.ts' --exclude='src/settings/rulesets/types.ts' --exclude='src/settings/repo-settings/types.ts' --exclude='src/settings/labels/types.ts' --exclude='src/**/index.ts' --exclude='test/mocks/**' --exclude='test/integration/**' --exclude='src/sync/types.ts' --exclude='src/lifecycle/types.ts' --exclude='src/cli/program.ts' --exclude='src/repo/types.ts' --exclude='src/settings/secrets/types.ts' --exclude='src/settings/code-scanning/types.ts' --exclude='src/settings/actions/types.ts' --exclude='src/settings/variables/types.ts' --exclude='src/settings/collaborators/types.ts' --exclude='src/settings/environments/types.ts' --exclude='src/ai/types.ts' --exclude='src/cli/types.ts' --exclude='src/cli.ts' --exclude='src/index.ts' npm test",
|
|
42
42
|
"test:integration:ci": "node --import tsx --test",
|
|
43
43
|
"test:integration:github": "npm run build && node --import tsx --test test/integration/github.test.ts",
|
|
44
44
|
"test:integration:ado": "npm run build && node --import tsx --test test/integration/ado.test.ts",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"test:integration:github-repo-settings": "npm run build && node --import tsx --test test/integration/github-repo-settings.test.ts",
|
|
53
53
|
"test:integration:github-labels": "npm run build && node --import tsx --test test/integration/github-labels.test.ts",
|
|
54
54
|
"test:integration:github-code-scanning": "npm run build && node --import tsx --test test/integration/github-code-scanning.test.ts",
|
|
55
|
+
"test:integration:github-actions-settings": "npm run build && node --import tsx --test test/integration/github-actions-settings.test.ts",
|
|
55
56
|
"test:integration:github-lifecycle": "npm run build && node --import tsx --test test/integration/github-lifecycle.test.ts",
|
|
56
57
|
"test:integration:github-lifecycle-app": "npm run build && node --import tsx --test test/integration/github-lifecycle-app.test.ts",
|
|
57
58
|
"test:typecheck": "tsc --project tsconfig.check-tests.json --noEmit",
|
|
@@ -87,6 +88,7 @@
|
|
|
87
88
|
},
|
|
88
89
|
"devDependencies": {
|
|
89
90
|
"@types/node": "^24.12.2",
|
|
91
|
+
"ajv": "^8.20.0",
|
|
90
92
|
"bottleneck": "^2.19.5",
|
|
91
93
|
"c8": "^12.0.0",
|
|
92
94
|
"tsx": "^4.15.0",
|