@aspruyt/xfg 8.5.5 → 8.6.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/index.d.ts +2 -2
- package/dist/config/index.js +1 -3
- package/dist/config/normalizer.d.ts +0 -8
- package/dist/config/normalizer.js +24 -26
- package/dist/config/types.d.ts +30 -27
- package/dist/config/types.js +6 -0
- package/dist/config/validator.d.ts +2 -9
- package/dist/config/validator.js +11 -10
- package/dist/config/validators/actions-validator.d.ts +7 -0
- package/dist/config/validators/actions-validator.js +134 -0
- package/dist/config/validators/shared.d.ts +1 -0
- package/dist/config/validators/shared.js +21 -0
- 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/package.json +3 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ProcessExecutor } from "../shared/command-executor.js";
|
|
2
|
-
import type { RulesetProcessorFactory, RepoSettingsProcessorFactory, LabelsProcessorFactory, CodeScanningProcessorFactory, VariablesProcessorFactory, CollaboratorsProcessorFactory, EnvironmentsProcessorFactory, SettingsProcessorFactories } from "./types.js";
|
|
2
|
+
import type { RulesetProcessorFactory, RepoSettingsProcessorFactory, LabelsProcessorFactory, CodeScanningProcessorFactory, ActionsProcessorFactory, VariablesProcessorFactory, CollaboratorsProcessorFactory, EnvironmentsProcessorFactory, SettingsProcessorFactories } from "./types.js";
|
|
3
3
|
export declare function createDefaultRulesetProcessorFactory(executor: ProcessExecutor): RulesetProcessorFactory;
|
|
4
4
|
export declare function createDefaultRepoSettingsProcessorFactory(executor: ProcessExecutor): RepoSettingsProcessorFactory;
|
|
5
5
|
export declare function createDefaultLabelsProcessorFactory(executor: ProcessExecutor): LabelsProcessorFactory;
|
|
6
6
|
export declare function createDefaultCodeScanningProcessorFactory(executor: ProcessExecutor): CodeScanningProcessorFactory;
|
|
7
|
+
export declare function createDefaultActionsProcessorFactory(executor: ProcessExecutor): ActionsProcessorFactory;
|
|
7
8
|
export declare function createDefaultVariablesProcessorFactory(executor: ProcessExecutor): VariablesProcessorFactory;
|
|
8
9
|
export declare function createDefaultCollaboratorsProcessorFactory(executor: ProcessExecutor): CollaboratorsProcessorFactory;
|
|
9
10
|
export declare function createDefaultEnvironmentsProcessorFactory(executor: ProcessExecutor): EnvironmentsProcessorFactory;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RulesetProcessor, RepoSettingsProcessor, LabelsProcessor, CodeScanningProcessor, VariablesProcessor, CollaboratorsProcessor, EnvironmentsProcessor, GitHubRulesetStrategy, GitHubRepoSettingsStrategy, GitHubLabelsStrategy, GitHubCodeScanningStrategy, GitHubVariablesStrategy, GitHubCollaboratorsStrategy, GitHubEnvironmentsStrategy, } from "../settings/index.js";
|
|
1
|
+
import { RulesetProcessor, RepoSettingsProcessor, LabelsProcessor, CodeScanningProcessor, ActionsProcessor, VariablesProcessor, CollaboratorsProcessor, EnvironmentsProcessor, GitHubRulesetStrategy, GitHubRepoSettingsStrategy, GitHubLabelsStrategy, GitHubCodeScanningStrategy, GitHubActionsStrategy, GitHubVariablesStrategy, GitHubCollaboratorsStrategy, GitHubEnvironmentsStrategy, } from "../settings/index.js";
|
|
2
2
|
import { GitHubRepoMetadataProvider } from "../repo/index.js";
|
|
3
3
|
export function createDefaultRulesetProcessorFactory(executor) {
|
|
4
4
|
const cwd = process.cwd();
|
|
@@ -16,6 +16,10 @@ export function createDefaultCodeScanningProcessorFactory(executor) {
|
|
|
16
16
|
const cwd = process.cwd();
|
|
17
17
|
return () => new CodeScanningProcessor(new GitHubCodeScanningStrategy(executor, { cwd }), new GitHubRepoMetadataProvider(executor, { cwd }));
|
|
18
18
|
}
|
|
19
|
+
export function createDefaultActionsProcessorFactory(executor) {
|
|
20
|
+
const cwd = process.cwd();
|
|
21
|
+
return () => new ActionsProcessor(new GitHubActionsStrategy(executor, { cwd }));
|
|
22
|
+
}
|
|
19
23
|
export function createDefaultVariablesProcessorFactory(executor) {
|
|
20
24
|
const cwd = process.cwd();
|
|
21
25
|
return () => new VariablesProcessor(new GitHubVariablesStrategy(executor, { cwd }));
|
|
@@ -35,6 +39,7 @@ export function createDefaultFactories(executor, overrides) {
|
|
|
35
39
|
repo: overrides?.repo ?? createDefaultRepoSettingsProcessorFactory(executor),
|
|
36
40
|
codeScanning: overrides?.codeScanning ??
|
|
37
41
|
createDefaultCodeScanningProcessorFactory(executor),
|
|
42
|
+
actions: overrides?.actions ?? createDefaultActionsProcessorFactory(executor),
|
|
38
43
|
variables: overrides?.variables ?? createDefaultVariablesProcessorFactory(executor),
|
|
39
44
|
collaborators: overrides?.collaborators ??
|
|
40
45
|
createDefaultCollaboratorsProcessorFactory(executor),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SettingsReport } from "../output/index.js";
|
|
2
|
-
import { type RepoSettingsPlanEntry, type RulesetPlanEntry, type LabelsPlanEntry, type CodeScanningPlanEntry, type VariablesPlanEntry, type CollaboratorsPlanEntry, type SecretsPlanEntry, type EnvironmentsPlanEntry } from "../settings/index.js";
|
|
2
|
+
import { type RepoSettingsPlanEntry, type RulesetPlanEntry, type LabelsPlanEntry, type CodeScanningPlanEntry, type ActionsPlanEntry, type VariablesPlanEntry, type CollaboratorsPlanEntry, type SecretsPlanEntry, type EnvironmentsPlanEntry } from "../settings/index.js";
|
|
3
3
|
export interface ProcessorResults {
|
|
4
4
|
repoName: string;
|
|
5
5
|
settingsResult?: {
|
|
@@ -22,6 +22,11 @@ export interface ProcessorResults {
|
|
|
22
22
|
entries?: CodeScanningPlanEntry[];
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
actionsResult?: {
|
|
26
|
+
planOutput?: {
|
|
27
|
+
entries?: ActionsPlanEntry[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
25
30
|
variablesResult?: {
|
|
26
31
|
planOutput?: {
|
|
27
32
|
entries?: VariablesPlanEntry[];
|
|
@@ -45,6 +45,18 @@ export function buildSettingsReport(results) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
if (result.actionsResult?.planOutput?.entries) {
|
|
49
|
+
for (const entry of result.actionsResult.planOutput.entries) {
|
|
50
|
+
if (!isActiveAction(entry))
|
|
51
|
+
continue;
|
|
52
|
+
repoChanges.settings.push({
|
|
53
|
+
name: `actions.${entry.property}`,
|
|
54
|
+
action: entry.action,
|
|
55
|
+
oldValue: entry.oldValue,
|
|
56
|
+
newValue: entry.newValue ?? null,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
48
60
|
if (repoChanges.settings.length > 0) {
|
|
49
61
|
const counts = countActions(repoChanges.settings);
|
|
50
62
|
totals.settings.create += counts.create;
|
|
@@ -72,6 +72,13 @@ function buildSettingsDescriptors(ctx) {
|
|
|
72
72
|
e.codeScanningResult = r;
|
|
73
73
|
}),
|
|
74
74
|
},
|
|
75
|
+
{
|
|
76
|
+
key: "actions",
|
|
77
|
+
label: "Actions",
|
|
78
|
+
run: () => runAndStoreResult(factories.actions, repoConfig, repoInfo, sharedOpts, repoName, settingsCollector, (e, r) => {
|
|
79
|
+
e.actionsResult = r;
|
|
80
|
+
}),
|
|
81
|
+
},
|
|
75
82
|
{
|
|
76
83
|
key: "variables",
|
|
77
84
|
label: "Variables",
|
package/dist/cli/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MergeMode, MergeStrategy, RepoConfig } from "../config/index.js";
|
|
2
2
|
import type { IRepoLifecycleManager } from "../lifecycle/index.js";
|
|
3
3
|
import type { IRepositoryProcessor, FileChangeDetail } from "../sync/index.js";
|
|
4
|
-
import type { ISettingsProcessor, IRulesetProcessor, IRepoSettingsProcessor, ILabelsProcessor, ICodeScanningProcessor, IVariablesProcessor, ICollaboratorsProcessor, IEnvironmentsProcessor, BaseProcessorResult } from "../settings/index.js";
|
|
4
|
+
import type { ISettingsProcessor, IRulesetProcessor, IRepoSettingsProcessor, ILabelsProcessor, ICodeScanningProcessor, IActionsProcessor, IVariablesProcessor, ICollaboratorsProcessor, IEnvironmentsProcessor, BaseProcessorResult } from "../settings/index.js";
|
|
5
5
|
import type { RepoInfo } from "../repo/index.js";
|
|
6
6
|
import type { ResultsCollector } from "./results-collector.js";
|
|
7
7
|
import type { Logger } from "../shared/logger.js";
|
|
@@ -11,22 +11,21 @@ export type RulesetProcessorFactory = SettingsProcessorFactory<IRulesetProcessor
|
|
|
11
11
|
export type RepoSettingsProcessorFactory = SettingsProcessorFactory<IRepoSettingsProcessor>;
|
|
12
12
|
export type LabelsProcessorFactory = SettingsProcessorFactory<ILabelsProcessor>;
|
|
13
13
|
export type CodeScanningProcessorFactory = SettingsProcessorFactory<ICodeScanningProcessor>;
|
|
14
|
+
export type ActionsProcessorFactory = SettingsProcessorFactory<IActionsProcessor>;
|
|
14
15
|
export type VariablesProcessorFactory = SettingsProcessorFactory<IVariablesProcessor>;
|
|
15
16
|
export type CollaboratorsProcessorFactory = SettingsProcessorFactory<ICollaboratorsProcessor>;
|
|
16
17
|
export type EnvironmentsProcessorFactory = SettingsProcessorFactory<IEnvironmentsProcessor>;
|
|
17
|
-
export type SettingsKind = "rulesets" | "labels" | "repo" | "codeScanning" | "variables" | "collaborators" | "environments";
|
|
18
|
+
export type SettingsKind = "rulesets" | "labels" | "repo" | "codeScanning" | "actions" | "variables" | "collaborators" | "environments";
|
|
18
19
|
export interface SettingsProcessorFactories {
|
|
19
20
|
rulesets: RulesetProcessorFactory;
|
|
20
21
|
labels: LabelsProcessorFactory;
|
|
21
22
|
repo: RepoSettingsProcessorFactory;
|
|
22
23
|
codeScanning: CodeScanningProcessorFactory;
|
|
24
|
+
actions: ActionsProcessorFactory;
|
|
23
25
|
variables: VariablesProcessorFactory;
|
|
24
26
|
collaborators: CollaboratorsProcessorFactory;
|
|
25
27
|
environments: EnvironmentsProcessorFactory;
|
|
26
28
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Dependencies for the sync command (dependency injection).
|
|
29
|
-
*/
|
|
30
29
|
export interface SyncDependencies {
|
|
31
30
|
processorFactory?: ProcessorFactory;
|
|
32
31
|
lifecycleManager?: IRepoLifecycleManager;
|
|
@@ -61,10 +60,6 @@ export interface SettingsResult extends BaseProcessorResult {
|
|
|
61
60
|
};
|
|
62
61
|
warnings?: string[];
|
|
63
62
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Context for applying repo settings (rulesets, labels, repo config).
|
|
66
|
-
* Groups parameters that were previously passed individually.
|
|
67
|
-
*/
|
|
68
63
|
export interface ApplyRepoSettingsContext {
|
|
69
64
|
repoConfig: RepoConfig;
|
|
70
65
|
repoInfo: RepoInfo;
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { PRMergeOptions, RepoPROptions, AiConfig, AiProvider, ResolvedAiConfig, AiProviderConfig, ResolvedAiProviderConfig, MergeMode, MergeStrategy, BypassActor, BypassMode, StatusCheckConfig, CodeScanningTool, PullRequestRuleParameters, RulesetRule, Ruleset, GitHubRepoSettings, RepoVisibility, SquashMergeCommitTitle, SquashMergeCommitMessage, MergeCommitTitle, MergeCommitMessage, Label, CodeScanningSettings, CodeScanningState, CodeScanningQuerySuite, CodeScanningLanguage, DeploymentBranchPatternType, DeploymentBranchPattern, DeploymentBranchPolicy, EnvironmentConfig, EnvironmentsConfig, RawEnvironmentConfig, RepoSettings, RawFileConfig, RawRepoFileOverride, RawGroupConfig, SecretConfig, CollaboratorsConfig, RawCollaboratorsConfig, SecretsConfig, RawRootSettings, RawRepoSettings, RawRepoConfig, RawConfig, RawConditionalGroupWhen, RawConditionalGroupConfig, RepoConfig, Config, FileContent, ContentValue, } from "./types.js";
|
|
2
|
-
export { RULESET_COMPARABLE_FIELDS } from "./types.js";
|
|
1
|
+
export type { PRMergeOptions, RepoPROptions, AiConfig, AiProvider, ResolvedAiConfig, AiProviderConfig, ResolvedAiProviderConfig, MergeMode, MergeStrategy, BypassActor, BypassMode, StatusCheckConfig, CodeScanningTool, PullRequestRuleParameters, RulesetRule, Ruleset, GitHubRepoSettings, RepoVisibility, SquashMergeCommitTitle, SquashMergeCommitMessage, MergeCommitTitle, MergeCommitMessage, Label, CodeScanningSettings, CodeScanningState, CodeScanningQuerySuite, CodeScanningLanguage, ActionsSettings, ActionsAllowedActions, ActionsDefaultWorkflowPermissions, ActionsForkPrApprovalPolicy, DeploymentBranchPatternType, DeploymentBranchPattern, DeploymentBranchPolicy, EnvironmentConfig, EnvironmentsConfig, RawEnvironmentConfig, RepoSettings, RawFileConfig, RawRepoFileOverride, RawGroupConfig, SecretConfig, CollaboratorsConfig, RawCollaboratorsConfig, SecretsConfig, RawRootSettings, RawRepoSettings, RawRepoConfig, RawConfig, RawConditionalGroupWhen, RawConditionalGroupConfig, RepoConfig, Config, FileContent, ContentValue, } from "./types.js";
|
|
2
|
+
export { RULESET_COMPARABLE_FIELDS, ACTIONS_SELECTED_FIELDS } from "./types.js";
|
|
3
3
|
export { loadRawConfig, loadConfig, normalizeConfig } from "./loader.js";
|
|
4
4
|
export { convertContentToString } from "./formatter.js";
|
|
5
5
|
export { validateForSync, validateSecretsConfig, validateNormalizedConfig, } from "./validator.js";
|
package/dist/config/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { RULESET_COMPARABLE_FIELDS } from "./types.js";
|
|
1
|
+
export { RULESET_COMPARABLE_FIELDS, ACTIONS_SELECTED_FIELDS } from "./types.js";
|
|
2
2
|
export { loadRawConfig, loadConfig, normalizeConfig } from "./loader.js";
|
|
3
|
-
// Config formatting
|
|
4
3
|
export { convertContentToString } from "./formatter.js";
|
|
5
|
-
// Config validation
|
|
6
4
|
export { validateForSync, validateSecretsConfig, validateNormalizedConfig, } from "./validator.js";
|
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
import type { RawConfig, Config, RepoSettings, RawRootSettings, RawRepoSettings } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Merges settings: per-repo settings deep merge with root settings.
|
|
4
|
-
* Returns undefined if no settings are defined.
|
|
5
|
-
*/
|
|
6
2
|
export declare function mergeSettings(root: RawRootSettings | undefined, perRepo: RawRepoSettings | undefined): RepoSettings | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Normalizes raw config into expanded, merged config.
|
|
9
|
-
* Pipeline: expand git arrays -> merge content -> interpolate env vars
|
|
10
|
-
*/
|
|
11
3
|
export declare function normalizeConfig(raw: RawConfig, env: Record<string, string | undefined>): Config;
|
|
@@ -33,10 +33,6 @@ function resolveFileContent(fileName, rootContent, repoOverride, mergeStrategy)
|
|
|
33
33
|
}
|
|
34
34
|
return mergeContentPair(fileName, rootContent, repoOverride.content, mergeStrategy);
|
|
35
35
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Merge two content values using the appropriate strategy.
|
|
38
|
-
* Handles text+text, object+object, and type mismatch cases.
|
|
39
|
-
*/
|
|
40
36
|
function mergeContentPair(fileName, base, overlay, strategy) {
|
|
41
37
|
if (isTextContent(base) && isTextContent(overlay)) {
|
|
42
38
|
return mergeTextContent(base, overlay, strategy);
|
|
@@ -48,9 +44,6 @@ function mergeContentPair(fileName, base, overlay, strategy) {
|
|
|
48
44
|
}
|
|
49
45
|
return cloneContent(overlay, fileName);
|
|
50
46
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Checks whether an object's `inherit` property is not explicitly set to false.
|
|
53
|
-
*/
|
|
54
47
|
function shouldInherit(obj) {
|
|
55
48
|
return obj?.inherit !== false;
|
|
56
49
|
}
|
|
@@ -61,10 +54,6 @@ function normalizeHeader(header) {
|
|
|
61
54
|
return [header];
|
|
62
55
|
return header;
|
|
63
56
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Merges PR options: per-repo overrides global defaults.
|
|
66
|
-
* Returns undefined if no options are set.
|
|
67
|
-
*/
|
|
68
57
|
function mergePROptions(global, perRepo) {
|
|
69
58
|
if (!global && !perRepo)
|
|
70
59
|
return undefined;
|
|
@@ -110,9 +99,6 @@ function normalizeAiOption(prOptions) {
|
|
|
110
99
|
function rulesetLocation(name) {
|
|
111
100
|
return `ruleset '${name}'`;
|
|
112
101
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Deep merges two rulesets: per-repo values override root values.
|
|
115
|
-
*/
|
|
116
102
|
function mergeRuleset(name, root, perRepo) {
|
|
117
103
|
if (!root)
|
|
118
104
|
return structuredClone(perRepo ?? {});
|
|
@@ -141,6 +127,8 @@ function mergeLabels(rootLabels, repoLabels) {
|
|
|
141
127
|
const repoLabel = repo[name];
|
|
142
128
|
if (repoLabel === false)
|
|
143
129
|
continue;
|
|
130
|
+
if (rootLabel === false && !repoLabel)
|
|
131
|
+
continue;
|
|
144
132
|
if (!inheritLabels && !repoLabel && rootLabel)
|
|
145
133
|
continue;
|
|
146
134
|
const base = rootLabel && typeof rootLabel === "object" ? rootLabel : {};
|
|
@@ -304,10 +292,6 @@ function mergeEnvironments(root, perRepo) {
|
|
|
304
292
|
}
|
|
305
293
|
return result;
|
|
306
294
|
}
|
|
307
|
-
/**
|
|
308
|
-
* Merges settings: per-repo settings deep merge with root settings.
|
|
309
|
-
* Returns undefined if no settings are defined.
|
|
310
|
-
*/
|
|
311
295
|
export function mergeSettings(root, perRepo) {
|
|
312
296
|
if (!root && !perRepo)
|
|
313
297
|
return undefined;
|
|
@@ -324,7 +308,7 @@ export function mergeSettings(root, perRepo) {
|
|
|
324
308
|
for (const name of allRulesetNames) {
|
|
325
309
|
const rootRuleset = rootRulesets[name];
|
|
326
310
|
const repoRuleset = repoRulesets[name];
|
|
327
|
-
if (repoRuleset === false) {
|
|
311
|
+
if (repoRuleset === false || (rootRuleset === false && !repoRuleset)) {
|
|
328
312
|
continue;
|
|
329
313
|
}
|
|
330
314
|
if (!inheritRulesets && !repoRuleset && rootRuleset) {
|
|
@@ -366,6 +350,16 @@ export function mergeSettings(root, perRepo) {
|
|
|
366
350
|
}
|
|
367
351
|
}
|
|
368
352
|
}
|
|
353
|
+
if (perRepo?.actions !== false) {
|
|
354
|
+
const rootActions = root?.actions;
|
|
355
|
+
const perRepoActions = perRepo?.actions;
|
|
356
|
+
if (rootActions || perRepoActions) {
|
|
357
|
+
result.actions = {
|
|
358
|
+
...(rootActions === false ? {} : rootActions),
|
|
359
|
+
...perRepoActions,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
369
363
|
if (root?.variables || perRepo?.variables) {
|
|
370
364
|
const merged = dropEntryMapIfEmpty(mergeEntryMapLayer(root?.variables, perRepo?.variables));
|
|
371
365
|
if (merged) {
|
|
@@ -435,9 +429,6 @@ function applyFileLayer(accumulated, layerFiles) {
|
|
|
435
429
|
}
|
|
436
430
|
return accumulated;
|
|
437
431
|
}
|
|
438
|
-
/**
|
|
439
|
-
* Merges group file layers onto root files, producing an effective root file map.
|
|
440
|
-
*/
|
|
441
432
|
function mergeGroupFiles(rootFiles, groupNames, groupDefs) {
|
|
442
433
|
let accumulated = structuredClone(rootFiles);
|
|
443
434
|
for (const groupName of groupNames) {
|
|
@@ -521,6 +512,17 @@ function mergeRawSettings(base, overlay) {
|
|
|
521
512
|
result.codeScanning = structuredClone(overlay.codeScanning);
|
|
522
513
|
}
|
|
523
514
|
}
|
|
515
|
+
if (overlay.actions !== undefined) {
|
|
516
|
+
if (overlay.actions === false) {
|
|
517
|
+
result.actions = false;
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
result.actions = {
|
|
521
|
+
...(result.actions === false ? {} : result.actions),
|
|
522
|
+
...overlay.actions,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
524
526
|
if (overlay.variables) {
|
|
525
527
|
result.variables = mergeEntryMapLayer(result.variables, overlay.variables);
|
|
526
528
|
}
|
|
@@ -645,10 +647,6 @@ function normalizeRepoEntry(ctx) {
|
|
|
645
647
|
source: ctx.rawRepo.source,
|
|
646
648
|
};
|
|
647
649
|
}
|
|
648
|
-
/**
|
|
649
|
-
* Normalizes raw config into expanded, merged config.
|
|
650
|
-
* Pipeline: expand git arrays -> merge content -> interpolate env vars
|
|
651
|
-
*/
|
|
652
650
|
export function normalizeConfig(raw, env) {
|
|
653
651
|
const expandedRepos = [];
|
|
654
652
|
for (const rawRepo of raw.repos) {
|
package/dist/config/types.d.ts
CHANGED
|
@@ -56,12 +56,10 @@ interface RefNameCondition {
|
|
|
56
56
|
export interface RulesetConditions {
|
|
57
57
|
refName?: RefNameCondition;
|
|
58
58
|
}
|
|
59
|
-
/** Status check in required_status_checks rule */
|
|
60
59
|
export interface StatusCheckConfig {
|
|
61
60
|
context: string;
|
|
62
61
|
integrationId?: number;
|
|
63
62
|
}
|
|
64
|
-
/** Reviewer configuration for pull_request rule (beta) */
|
|
65
63
|
export interface RequiredReviewer {
|
|
66
64
|
filePatterns: string[];
|
|
67
65
|
minimumApprovals: number;
|
|
@@ -70,13 +68,11 @@ export interface RequiredReviewer {
|
|
|
70
68
|
type: "Team";
|
|
71
69
|
};
|
|
72
70
|
}
|
|
73
|
-
/** Code scanning tool configuration */
|
|
74
71
|
export interface CodeScanningTool {
|
|
75
72
|
tool: string;
|
|
76
73
|
alertsThreshold: AlertsThreshold;
|
|
77
74
|
securityAlertsThreshold: SecurityAlertsThreshold;
|
|
78
75
|
}
|
|
79
|
-
/** Workflow configuration */
|
|
80
76
|
interface WorkflowConfig {
|
|
81
77
|
path: string;
|
|
82
78
|
repositoryId: number;
|
|
@@ -216,15 +212,10 @@ export type RulesetRule = PullRequestRule | RequiredStatusChecksRule | RequiredS
|
|
|
216
212
|
* @see https://docs.github.com/en/rest/repos/rules
|
|
217
213
|
*/
|
|
218
214
|
export interface Ruleset {
|
|
219
|
-
/** Target type: branch or tag */
|
|
220
215
|
target?: RulesetTarget;
|
|
221
|
-
/** Enforcement level */
|
|
222
216
|
enforcement?: RulesetEnforcement;
|
|
223
|
-
/** Actors who can bypass this ruleset */
|
|
224
217
|
bypassActors?: BypassActor[];
|
|
225
|
-
/** Conditions for when this ruleset applies */
|
|
226
218
|
conditions?: RulesetConditions;
|
|
227
|
-
/** Rules to enforce */
|
|
228
219
|
rules?: RulesetRule[];
|
|
229
220
|
}
|
|
230
221
|
/**
|
|
@@ -232,15 +223,10 @@ export interface Ruleset {
|
|
|
232
223
|
* Used as an allowlist — any API response field not in this set is ignored.
|
|
233
224
|
*/
|
|
234
225
|
export declare const RULESET_COMPARABLE_FIELDS: Set<string>;
|
|
235
|
-
/** Squash merge commit title format */
|
|
236
226
|
export type SquashMergeCommitTitle = "PR_TITLE" | "COMMIT_OR_PR_TITLE";
|
|
237
|
-
/** Squash merge commit message format */
|
|
238
227
|
export type SquashMergeCommitMessage = "PR_BODY" | "COMMIT_MESSAGES" | "BLANK";
|
|
239
|
-
/** Merge commit title format */
|
|
240
228
|
export type MergeCommitTitle = "PR_TITLE" | "MERGE_MESSAGE";
|
|
241
|
-
/** Merge commit message format */
|
|
242
229
|
export type MergeCommitMessage = "PR_BODY" | "PR_TITLE" | "BLANK";
|
|
243
|
-
/** Repository visibility */
|
|
244
230
|
export type RepoVisibility = "public" | "private" | "internal";
|
|
245
231
|
/**
|
|
246
232
|
* GitHub repository settings configuration.
|
|
@@ -295,6 +281,33 @@ export interface CodeScanningSettings {
|
|
|
295
281
|
querySuite?: CodeScanningQuerySuite;
|
|
296
282
|
languages?: CodeScanningLanguage[];
|
|
297
283
|
}
|
|
284
|
+
export type ActionsAllowedActions = "all" | "local_only" | "selected";
|
|
285
|
+
export type ActionsDefaultWorkflowPermissions = "read" | "write";
|
|
286
|
+
export type ActionsForkPrApprovalPolicy = "first_time_contributors_new_to_github" | "first_time_contributors" | "all_external_contributors";
|
|
287
|
+
/**
|
|
288
|
+
* GitHub Actions repository settings.
|
|
289
|
+
* @see https://docs.github.com/en/rest/actions/permissions
|
|
290
|
+
*/
|
|
291
|
+
export interface ActionsSettings {
|
|
292
|
+
enabled?: boolean;
|
|
293
|
+
allowedActions?: ActionsAllowedActions;
|
|
294
|
+
shaPinningRequired?: boolean;
|
|
295
|
+
/** Only applies when allowedActions is `selected` */
|
|
296
|
+
githubOwnedAllowed?: boolean;
|
|
297
|
+
/** Only applies when allowedActions is `selected` */
|
|
298
|
+
verifiedAllowed?: boolean;
|
|
299
|
+
/** Only applies when allowedActions is `selected`; `!` prefix blocks a pattern */
|
|
300
|
+
patternsAllowed?: string[];
|
|
301
|
+
defaultWorkflowPermissions?: ActionsDefaultWorkflowPermissions;
|
|
302
|
+
/** Covers creating pull requests as well as approving them */
|
|
303
|
+
canApprovePullRequestReviews?: boolean;
|
|
304
|
+
forkPrApprovalPolicy?: ActionsForkPrApprovalPolicy;
|
|
305
|
+
artifactAndLogRetentionDays?: number;
|
|
306
|
+
cacheRetentionDays?: number;
|
|
307
|
+
cacheSizeGb?: number;
|
|
308
|
+
}
|
|
309
|
+
/** Fields of the selected-actions endpoint; GitHub only accepts them when allowedActions is `selected`. */
|
|
310
|
+
export declare const ACTIONS_SELECTED_FIELDS: readonly ["githubOwnedAllowed", "verifiedAllowed", "patternsAllowed"];
|
|
298
311
|
export interface SecretConfig {
|
|
299
312
|
env: string;
|
|
300
313
|
}
|
|
@@ -344,25 +357,18 @@ export interface RawCollaboratorsConfig extends CollaboratorsConfig {
|
|
|
344
357
|
inherit?: boolean;
|
|
345
358
|
}
|
|
346
359
|
export interface RepoSettings {
|
|
347
|
-
/** GitHub rulesets keyed by name */
|
|
348
360
|
rulesets?: Record<string, Ruleset>;
|
|
349
|
-
/** GitHub repository settings */
|
|
350
361
|
repo?: GitHubRepoSettings;
|
|
351
|
-
/** GitHub labels keyed by name */
|
|
352
362
|
labels?: Record<string, Label>;
|
|
353
|
-
/** GitHub code scanning default setup */
|
|
354
363
|
codeScanning?: CodeScanningSettings;
|
|
355
|
-
|
|
364
|
+
actions?: ActionsSettings;
|
|
356
365
|
variables?: Record<string, string> & {
|
|
357
366
|
deleteOrphaned?: boolean;
|
|
358
367
|
};
|
|
359
|
-
/** GitHub Actions secrets keyed by name */
|
|
360
368
|
secrets?: Record<string, SecretConfig> & {
|
|
361
369
|
deleteOrphaned?: boolean;
|
|
362
370
|
};
|
|
363
|
-
/** Direct collaborators on personal (user-owned) repos */
|
|
364
371
|
collaborators?: CollaboratorsConfig;
|
|
365
|
-
/** GitHub deployment environments keyed by name */
|
|
366
372
|
environments?: EnvironmentsConfig;
|
|
367
373
|
deleteOrphaned?: boolean;
|
|
368
374
|
}
|
|
@@ -397,7 +403,6 @@ export interface RawGroupConfig {
|
|
|
397
403
|
prOptions?: PRMergeOptions;
|
|
398
404
|
settings?: RawRepoSettings;
|
|
399
405
|
}
|
|
400
|
-
/** Condition for conditional group activation */
|
|
401
406
|
export interface RawConditionalGroupWhen {
|
|
402
407
|
/** All listed groups must be present in the repo's effective group set */
|
|
403
408
|
allOf?: string[];
|
|
@@ -406,17 +411,13 @@ export interface RawConditionalGroupWhen {
|
|
|
406
411
|
/** None of the listed groups may be present */
|
|
407
412
|
noneOf?: string[];
|
|
408
413
|
}
|
|
409
|
-
/** Conditional group: activates based on which groups a repo has */
|
|
410
414
|
export interface RawConditionalGroupConfig {
|
|
411
|
-
/** Condition that determines when this group activates */
|
|
412
415
|
when: RawConditionalGroupWhen;
|
|
413
416
|
/** File definitions or overrides (same capabilities as regular groups) */
|
|
414
417
|
files?: Record<string, RawFileConfig | RawRepoFileOverride | false> & {
|
|
415
418
|
inherit?: boolean;
|
|
416
419
|
};
|
|
417
|
-
/** PR merge options */
|
|
418
420
|
prOptions?: PRMergeOptions;
|
|
419
|
-
/** Repository settings (rulesets, labels, repo settings) */
|
|
420
421
|
settings?: RawRepoSettings;
|
|
421
422
|
}
|
|
422
423
|
export interface RawRootSettings {
|
|
@@ -424,6 +425,7 @@ export interface RawRootSettings {
|
|
|
424
425
|
repo?: GitHubRepoSettings | false;
|
|
425
426
|
labels?: Record<string, Label | false>;
|
|
426
427
|
codeScanning?: CodeScanningSettings | false;
|
|
428
|
+
actions?: ActionsSettings | false;
|
|
427
429
|
variables?: Record<string, string | false> & {
|
|
428
430
|
deleteOrphaned?: boolean;
|
|
429
431
|
};
|
|
@@ -443,6 +445,7 @@ export interface RawRepoSettings {
|
|
|
443
445
|
inherit?: boolean;
|
|
444
446
|
};
|
|
445
447
|
codeScanning?: CodeScanningSettings | false;
|
|
448
|
+
actions?: ActionsSettings | false;
|
|
446
449
|
variables?: Record<string, string | false> & {
|
|
447
450
|
inherit?: boolean;
|
|
448
451
|
deleteOrphaned?: boolean;
|
package/dist/config/types.js
CHANGED
|
@@ -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,10 @@
|
|
|
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
|
|
6
|
+
* the same name collide at GitHub, and selected-actions fields need an
|
|
7
|
+
* allowedActions from some layer. Must run post-normalize — a per-layer check
|
|
15
8
|
* misses a root secret colliding with a repo variable.
|
|
16
9
|
*/
|
|
17
10
|
export declare function validateNormalizedConfig(config: Config): void;
|
package/dist/config/validator.js
CHANGED
|
@@ -8,6 +8,7 @@ import { validateAiOption } from "./validators/ai-validator.js";
|
|
|
8
8
|
import { validateFileConfigFields, validateSettings, } from "./validators/shared.js";
|
|
9
9
|
import { validateGroups, validateConditionalGroups, } from "./validators/group-validator.js";
|
|
10
10
|
import { validateRepoEntry } from "./validators/repo-entry-validator.js";
|
|
11
|
+
import { validateMergedActionsSettings } from "./validators/actions-validator.js";
|
|
11
12
|
const CONFIG_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
12
13
|
const VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
13
14
|
const VARIABLE_RESERVED_KEYS = new Set(["deleteOrphaned", "inherit"]);
|
|
@@ -140,10 +141,6 @@ function hasConditionalGroupPR(config) {
|
|
|
140
141
|
return (Array.isArray(config.conditionalGroups) &&
|
|
141
142
|
config.conditionalGroups.some((cg) => cg.prOptions && isPlainObject(cg.prOptions)));
|
|
142
143
|
}
|
|
143
|
-
/**
|
|
144
|
-
* Validates raw config structure before normalization.
|
|
145
|
-
* @throws ValidationError if validation fails
|
|
146
|
-
*/
|
|
147
144
|
export function validateRawConfig(config) {
|
|
148
145
|
// Must run before the "nothing to do" check below, or an old secrets-only
|
|
149
146
|
// config trips the generic error and never sees the migration message.
|
|
@@ -189,10 +186,6 @@ export function validateRawConfig(config) {
|
|
|
189
186
|
validateRepoEntry(config, config.repos[i], i);
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Validates that config is suitable for the sync command.
|
|
194
|
-
* @throws ValidationError if neither files nor settings are present
|
|
195
|
-
*/
|
|
196
189
|
export function validateForSync(config) {
|
|
197
190
|
const hasRootFiles = config.files && Object.keys(config.files).length > 0;
|
|
198
191
|
const hasGrpFiles = hasGroupFiles(config);
|
|
@@ -266,7 +259,8 @@ function assertNoOverlap(settings, context) {
|
|
|
266
259
|
}
|
|
267
260
|
/**
|
|
268
261
|
* Cross-validates the MERGED settings of each repo: a variable and a secret with
|
|
269
|
-
* the same name collide at GitHub
|
|
262
|
+
* the same name collide at GitHub, and selected-actions fields need an
|
|
263
|
+
* allowedActions from some layer. Must run post-normalize — a per-layer check
|
|
270
264
|
* misses a root secret colliding with a repo variable.
|
|
271
265
|
*/
|
|
272
266
|
export function validateNormalizedConfig(config) {
|
|
@@ -274,8 +268,12 @@ export function validateNormalizedConfig(config) {
|
|
|
274
268
|
assertNoOverlap(config.settings, "Root settings");
|
|
275
269
|
for (const repo of config.repos) {
|
|
276
270
|
assertNoOverlap(repo.settings, `Repo '${repo.git}'`);
|
|
271
|
+
validateMergedActionsSettings(repo.settings?.actions, `Repo '${repo.git}'`);
|
|
277
272
|
}
|
|
278
273
|
}
|
|
274
|
+
function hasKeys(value) {
|
|
275
|
+
return !!value && Object.keys(value).length > 0;
|
|
276
|
+
}
|
|
279
277
|
export function hasActionableSettings(settings) {
|
|
280
278
|
if (!settings)
|
|
281
279
|
return false;
|
|
@@ -283,7 +281,7 @@ export function hasActionableSettings(settings) {
|
|
|
283
281
|
Object.keys(settings.rulesets).filter((k) => k !== "inherit").length > 0) {
|
|
284
282
|
return true;
|
|
285
283
|
}
|
|
286
|
-
if (
|
|
284
|
+
if (hasKeys(settings.repo)) {
|
|
287
285
|
return true;
|
|
288
286
|
}
|
|
289
287
|
if (settings.labels &&
|
|
@@ -293,6 +291,9 @@ export function hasActionableSettings(settings) {
|
|
|
293
291
|
if (settings.codeScanning) {
|
|
294
292
|
return true;
|
|
295
293
|
}
|
|
294
|
+
if (hasKeys(settings.actions)) {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
296
297
|
if (settings.variables) {
|
|
297
298
|
const { deleteOrphaned, inherit: _i, ...entries } = settings.variables;
|
|
298
299
|
if (Object.keys(entries).length > 0 || deleteOrphaned === true) {
|
|
@@ -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,134 @@
|
|
|
1
|
+
import { ValidationError } from "../../shared/errors.js";
|
|
2
|
+
import { isPlainObject } from "../../shared/type-guards.js";
|
|
3
|
+
import { ACTIONS_SELECTED_FIELDS, } from "../types.js";
|
|
4
|
+
import { validValues } from "./file-validator.js";
|
|
5
|
+
const ACTIONS_KEYS = new Set([
|
|
6
|
+
"enabled",
|
|
7
|
+
"allowedActions",
|
|
8
|
+
"shaPinningRequired",
|
|
9
|
+
"githubOwnedAllowed",
|
|
10
|
+
"verifiedAllowed",
|
|
11
|
+
"patternsAllowed",
|
|
12
|
+
"defaultWorkflowPermissions",
|
|
13
|
+
"canApprovePullRequestReviews",
|
|
14
|
+
"forkPrApprovalPolicy",
|
|
15
|
+
"artifactAndLogRetentionDays",
|
|
16
|
+
"cacheRetentionDays",
|
|
17
|
+
"cacheSizeGb",
|
|
18
|
+
]);
|
|
19
|
+
const BOOLEAN_FIELDS = [
|
|
20
|
+
"enabled",
|
|
21
|
+
"shaPinningRequired",
|
|
22
|
+
"githubOwnedAllowed",
|
|
23
|
+
"verifiedAllowed",
|
|
24
|
+
"canApprovePullRequestReviews",
|
|
25
|
+
];
|
|
26
|
+
// Upper bounds vary by visibility and plan, so the API enforces them.
|
|
27
|
+
const POSITIVE_INTEGER_FIELDS = [
|
|
28
|
+
"artifactAndLogRetentionDays",
|
|
29
|
+
"cacheRetentionDays",
|
|
30
|
+
"cacheSizeGb",
|
|
31
|
+
];
|
|
32
|
+
const ENUM_FIELDS = [
|
|
33
|
+
[
|
|
34
|
+
"allowedActions",
|
|
35
|
+
validValues(["all", "local_only", "selected"]),
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
"defaultWorkflowPermissions",
|
|
39
|
+
validValues(["read", "write"]),
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
"forkPrApprovalPolicy",
|
|
43
|
+
validValues([
|
|
44
|
+
"first_time_contributors_new_to_github",
|
|
45
|
+
"first_time_contributors",
|
|
46
|
+
"all_external_contributors",
|
|
47
|
+
]),
|
|
48
|
+
],
|
|
49
|
+
];
|
|
50
|
+
function validateBooleans(a, context) {
|
|
51
|
+
for (const field of BOOLEAN_FIELDS) {
|
|
52
|
+
if (a[field] !== undefined && typeof a[field] !== "boolean") {
|
|
53
|
+
throw new ValidationError(`${context}: ${field} must be a boolean`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function validateEnums(a, context) {
|
|
58
|
+
for (const [field, allowed] of ENUM_FIELDS) {
|
|
59
|
+
if (a[field] !== undefined && !allowed.includes(a[field])) {
|
|
60
|
+
throw new ValidationError(`${context}: ${field} must be one of: ${allowed.join(", ")}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function validatePositiveIntegers(a, context) {
|
|
65
|
+
for (const field of POSITIVE_INTEGER_FIELDS) {
|
|
66
|
+
const value = a[field];
|
|
67
|
+
if (value !== undefined &&
|
|
68
|
+
!(Number.isInteger(value) && Number(value) > 0)) {
|
|
69
|
+
throw new ValidationError(`${context}: ${field} must be a positive integer`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function validatePatternsAllowed(a, context) {
|
|
74
|
+
if (a.patternsAllowed === undefined)
|
|
75
|
+
return;
|
|
76
|
+
if (!Array.isArray(a.patternsAllowed)) {
|
|
77
|
+
throw new ValidationError(`${context}: patternsAllowed must be an array of strings`);
|
|
78
|
+
}
|
|
79
|
+
a.patternsAllowed.forEach((pattern, i) => {
|
|
80
|
+
if (typeof pattern !== "string" || pattern.trim() === "") {
|
|
81
|
+
throw new ValidationError(`${context}: patternsAllowed[${i}] must be a non-empty string`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function validateValues(a, context) {
|
|
86
|
+
validateBooleans(a, context);
|
|
87
|
+
validateEnums(a, context);
|
|
88
|
+
validatePositiveIntegers(a, context);
|
|
89
|
+
validatePatternsAllowed(a, context);
|
|
90
|
+
}
|
|
91
|
+
function validateCoupling(a, context) {
|
|
92
|
+
const selectedField = ACTIONS_SELECTED_FIELDS.find((f) => a[f] !== undefined);
|
|
93
|
+
const { allowedActions } = a;
|
|
94
|
+
// validateValues has already limited a defined allowedActions to a string
|
|
95
|
+
if (selectedField &&
|
|
96
|
+
typeof allowedActions === "string" &&
|
|
97
|
+
allowedActions !== "selected") {
|
|
98
|
+
throw new ValidationError(`${context}: ${selectedField} requires allowedActions: selected, but this layer sets allowedActions: ${allowedActions}`);
|
|
99
|
+
}
|
|
100
|
+
if (a.enabled === false) {
|
|
101
|
+
const conflicting = [
|
|
102
|
+
"allowedActions",
|
|
103
|
+
"shaPinningRequired",
|
|
104
|
+
...ACTIONS_SELECTED_FIELDS,
|
|
105
|
+
].find((f) => a[f] !== undefined);
|
|
106
|
+
if (conflicting) {
|
|
107
|
+
throw new ValidationError(`${context}: ${conflicting} cannot be set with enabled: false`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
export function validateActionsSettings(actions, context) {
|
|
112
|
+
if (!isPlainObject(actions)) {
|
|
113
|
+
throw new ValidationError(`${context}: must be an object`);
|
|
114
|
+
}
|
|
115
|
+
for (const key of Object.keys(actions)) {
|
|
116
|
+
if (!ACTIONS_KEYS.has(key)) {
|
|
117
|
+
throw new ValidationError(`${context}: unknown key '${key}'`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
validateValues(actions, context);
|
|
121
|
+
validateCoupling(actions, context);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Selected-actions fields need allowedActions: selected from some layer. A layer
|
|
125
|
+
* may omit it and inherit it, so only the merged block can be checked.
|
|
126
|
+
*/
|
|
127
|
+
export function validateMergedActionsSettings(actions, context) {
|
|
128
|
+
if (!actions || actions.allowedActions !== undefined)
|
|
129
|
+
return;
|
|
130
|
+
const present = ACTIONS_SELECTED_FIELDS.filter((f) => actions[f] !== undefined);
|
|
131
|
+
if (present.length > 0) {
|
|
132
|
+
throw new ValidationError(`${context}: ${present.join(", ")} require allowedActions: selected, but no layer sets allowedActions`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -3,6 +3,7 @@ export interface RootSettingsContext {
|
|
|
3
3
|
rulesetNames: string[];
|
|
4
4
|
hasRepoSettings: boolean;
|
|
5
5
|
hasCodeScanningSettings: boolean;
|
|
6
|
+
hasActionsSettings: boolean;
|
|
6
7
|
labelNames: string[];
|
|
7
8
|
}
|
|
8
9
|
export declare function buildRootSettingsContext(config: RawConfig): RootSettingsContext;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isTextContent, isObjectContent, isStructuredFileExtension, validValues, VALID_STRATEGIES, } from "./file-validator.js";
|
|
2
2
|
import { validateRuleset } from "./ruleset-validator.js";
|
|
3
3
|
import { validateRepoSettings } from "./repo-settings-validator.js";
|
|
4
|
+
import { validateActionsSettings } from "./actions-validator.js";
|
|
4
5
|
import { isPlainObject } from "../../shared/type-guards.js";
|
|
5
6
|
import { ValidationError } from "../../shared/errors.js";
|
|
6
7
|
export function buildRootSettingsContext(config) {
|
|
@@ -11,6 +12,8 @@ export function buildRootSettingsContext(config) {
|
|
|
11
12
|
hasRepoSettings: config.settings?.repo !== undefined && config.settings.repo !== false,
|
|
12
13
|
hasCodeScanningSettings: config.settings?.codeScanning !== undefined &&
|
|
13
14
|
config.settings.codeScanning !== false,
|
|
15
|
+
hasActionsSettings: config.settings?.actions !== undefined &&
|
|
16
|
+
config.settings.actions !== false,
|
|
14
17
|
labelNames: config.settings?.labels
|
|
15
18
|
? Object.keys(config.settings.labels).filter((k) => k !== "inherit")
|
|
16
19
|
: [],
|
|
@@ -208,6 +211,20 @@ function validateSettingsCodeScanning(settings, context, rootCtx) {
|
|
|
208
211
|
}
|
|
209
212
|
validateCodeScanningSettings(settings.codeScanning, `${context} codeScanning`);
|
|
210
213
|
}
|
|
214
|
+
function validateSettingsActions(settings, context, rootCtx) {
|
|
215
|
+
if (settings.actions === undefined)
|
|
216
|
+
return;
|
|
217
|
+
if (settings.actions === false) {
|
|
218
|
+
if (!rootCtx) {
|
|
219
|
+
throw new ValidationError(`${context}: actions: false is not valid at root level. Define actions settings or remove the field.`);
|
|
220
|
+
}
|
|
221
|
+
if (!rootCtx.hasActionsSettings) {
|
|
222
|
+
throw new ValidationError(`${context}: Cannot opt out of actions settings — not defined in root settings.actions`);
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
validateActionsSettings(settings.actions, `${context} actions`);
|
|
227
|
+
}
|
|
211
228
|
function validateSettingsSecrets(settings, context) {
|
|
212
229
|
if (settings.secrets === undefined)
|
|
213
230
|
return;
|
|
@@ -409,6 +426,7 @@ export function validateSettings(settings, context, rootCtx) {
|
|
|
409
426
|
validateSettingsDeleteOrphaned(settings, context);
|
|
410
427
|
validateSettingsRepo(settings, context, rootCtx);
|
|
411
428
|
validateSettingsCodeScanning(settings, context, rootCtx);
|
|
429
|
+
validateSettingsActions(settings, context, rootCtx);
|
|
412
430
|
validateSettingsSecrets(settings, context);
|
|
413
431
|
validateSettingsCollaborators(settings, context);
|
|
414
432
|
validateSettingsEnvironments(settings, context, rootCtx);
|
|
@@ -434,4 +452,7 @@ export function enrichSettingsContext(rootCtx, settings) {
|
|
|
434
452
|
if (settings.codeScanning !== undefined && settings.codeScanning !== false) {
|
|
435
453
|
rootCtx.hasCodeScanningSettings = true;
|
|
436
454
|
}
|
|
455
|
+
if (settings.actions !== undefined && settings.actions !== false) {
|
|
456
|
+
rootCtx.hasActionsSettings = true;
|
|
457
|
+
}
|
|
437
458
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActionsSettings } from "../../config/index.js";
|
|
2
|
+
import type { SettingsAction } from "../base-processor.js";
|
|
3
|
+
export interface ActionsChange {
|
|
4
|
+
property: keyof ActionsSettings;
|
|
5
|
+
action: SettingsAction;
|
|
6
|
+
oldValue?: unknown;
|
|
7
|
+
newValue?: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Only fields set in desired are compared; patternsAllowed compares as a set. */
|
|
10
|
+
export declare function diffActions(current: ActionsSettings, desired: ActionsSettings): ActionsChange[];
|
|
11
|
+
export declare function hasActionsChanges(changes: ActionsChange[]): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ACTIONS_ENDPOINTS } from "./endpoints.js";
|
|
2
|
+
const FIELD_ORDER = ACTIONS_ENDPOINTS.flatMap((e) => e.fields.map((f) => f.setting));
|
|
3
|
+
function sameValue(current, desired) {
|
|
4
|
+
if (Array.isArray(current) && Array.isArray(desired)) {
|
|
5
|
+
const currentSet = new Set(current);
|
|
6
|
+
const desiredSet = new Set(desired);
|
|
7
|
+
return (currentSet.size === desiredSet.size &&
|
|
8
|
+
[...desiredSet].every((v) => currentSet.has(v)));
|
|
9
|
+
}
|
|
10
|
+
return current === desired;
|
|
11
|
+
}
|
|
12
|
+
function classify(oldValue, newValue) {
|
|
13
|
+
if (sameValue(oldValue, newValue))
|
|
14
|
+
return "unchanged";
|
|
15
|
+
return oldValue === undefined ? "create" : "update";
|
|
16
|
+
}
|
|
17
|
+
/** Only fields set in desired are compared; patternsAllowed compares as a set. */
|
|
18
|
+
export function diffActions(current, desired) {
|
|
19
|
+
const changes = [];
|
|
20
|
+
for (const property of FIELD_ORDER) {
|
|
21
|
+
const newValue = desired[property];
|
|
22
|
+
if (newValue === undefined)
|
|
23
|
+
continue;
|
|
24
|
+
const oldValue = current[property];
|
|
25
|
+
const action = classify(oldValue, newValue);
|
|
26
|
+
changes.push({ property, action, oldValue, newValue });
|
|
27
|
+
}
|
|
28
|
+
return changes;
|
|
29
|
+
}
|
|
30
|
+
export function hasActionsChanges(changes) {
|
|
31
|
+
return changes.some((c) => c.action !== "unchanged");
|
|
32
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ActionsSettings } from "../../config/index.js";
|
|
2
|
+
import type { ActionsApiBody, ActionsEndpointName } from "./types.js";
|
|
3
|
+
interface ActionsEndpointField {
|
|
4
|
+
setting: keyof ActionsSettings;
|
|
5
|
+
api: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ActionsEndpoint {
|
|
8
|
+
name: ActionsEndpointName;
|
|
9
|
+
/** Path under /repos/{owner}/{repo}/actions/ */
|
|
10
|
+
path: string;
|
|
11
|
+
fields: readonly ActionsEndpointField[];
|
|
12
|
+
}
|
|
13
|
+
export declare const ACTIONS_ENDPOINTS: readonly ActionsEndpoint[];
|
|
14
|
+
export declare function endpointByName(name: ActionsEndpointName): ActionsEndpoint;
|
|
15
|
+
export declare function readEndpoint(endpoint: ActionsEndpoint, body: ActionsApiBody): ActionsSettings;
|
|
16
|
+
/**
|
|
17
|
+
* GitHub doesn't document whether a PUT keeps omitted fields, so the current
|
|
18
|
+
* value of every unconfigured field is sent too.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildPayload(endpoint: ActionsEndpoint, desired: ActionsSettings, current: ActionsSettings): ActionsApiBody;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Order is the write order: selected-actions needs allowed_actions: selected set first.
|
|
2
|
+
export const ACTIONS_ENDPOINTS = [
|
|
3
|
+
{
|
|
4
|
+
name: "permissions",
|
|
5
|
+
path: "permissions",
|
|
6
|
+
fields: [
|
|
7
|
+
{ setting: "enabled", api: "enabled" },
|
|
8
|
+
{ setting: "allowedActions", api: "allowed_actions" },
|
|
9
|
+
{ setting: "shaPinningRequired", api: "sha_pinning_required" },
|
|
10
|
+
],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "selectedActions",
|
|
14
|
+
path: "permissions/selected-actions",
|
|
15
|
+
fields: [
|
|
16
|
+
{ setting: "githubOwnedAllowed", api: "github_owned_allowed" },
|
|
17
|
+
{ setting: "verifiedAllowed", api: "verified_allowed" },
|
|
18
|
+
{ setting: "patternsAllowed", api: "patterns_allowed" },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "workflow",
|
|
23
|
+
path: "permissions/workflow",
|
|
24
|
+
fields: [
|
|
25
|
+
{
|
|
26
|
+
setting: "defaultWorkflowPermissions",
|
|
27
|
+
api: "default_workflow_permissions",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
setting: "canApprovePullRequestReviews",
|
|
31
|
+
api: "can_approve_pull_request_reviews",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "forkPrApproval",
|
|
37
|
+
path: "permissions/fork-pr-contributor-approval",
|
|
38
|
+
fields: [{ setting: "forkPrApprovalPolicy", api: "approval_policy" }],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "artifactRetention",
|
|
42
|
+
path: "permissions/artifact-and-log-retention",
|
|
43
|
+
fields: [{ setting: "artifactAndLogRetentionDays", api: "days" }],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "cacheRetention",
|
|
47
|
+
path: "cache/retention-limit",
|
|
48
|
+
fields: [
|
|
49
|
+
{ setting: "cacheRetentionDays", api: "max_cache_retention_days" },
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "cacheStorage",
|
|
54
|
+
path: "cache/storage-limit",
|
|
55
|
+
fields: [{ setting: "cacheSizeGb", api: "max_cache_size_gb" }],
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
export function endpointByName(name) {
|
|
59
|
+
const endpoint = ACTIONS_ENDPOINTS.find((e) => e.name === name);
|
|
60
|
+
if (!endpoint)
|
|
61
|
+
throw new Error(`Unknown Actions endpoint: ${name}`);
|
|
62
|
+
return endpoint;
|
|
63
|
+
}
|
|
64
|
+
export function readEndpoint(endpoint, body) {
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const { setting, api } of endpoint.fields) {
|
|
67
|
+
if (body[api] !== undefined)
|
|
68
|
+
result[setting] = body[api];
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* GitHub doesn't document whether a PUT keeps omitted fields, so the current
|
|
74
|
+
* value of every unconfigured field is sent too.
|
|
75
|
+
*/
|
|
76
|
+
export function buildPayload(endpoint, desired, current) {
|
|
77
|
+
// Only enabled is written while Actions is off: GitHub answers 409 to allowed_actions with enabled: false
|
|
78
|
+
if (endpoint.name === "permissions" &&
|
|
79
|
+
(desired.enabled ?? current.enabled) === false) {
|
|
80
|
+
return { enabled: false };
|
|
81
|
+
}
|
|
82
|
+
const body = {};
|
|
83
|
+
for (const { setting, api } of endpoint.fields) {
|
|
84
|
+
const value = desired[setting] ?? current[setting];
|
|
85
|
+
if (value !== undefined)
|
|
86
|
+
body[api] = value;
|
|
87
|
+
}
|
|
88
|
+
return body;
|
|
89
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ActionsChange } from "./diff.js";
|
|
2
|
+
import { type PlanEntry } from "../base-processor.js";
|
|
3
|
+
export type ActionsPlanEntry = PlanEntry;
|
|
4
|
+
export interface ActionsPlanResult {
|
|
5
|
+
lines: string[];
|
|
6
|
+
creates: number;
|
|
7
|
+
updates: number;
|
|
8
|
+
entries: ActionsPlanEntry[];
|
|
9
|
+
}
|
|
10
|
+
export declare function formatActionsPlan(changes: ActionsChange[]): ActionsPlanResult;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { formatScalarValue } from "../../shared/string-utils.js";
|
|
2
|
+
import { formatChangeLines } from "../base-processor.js";
|
|
3
|
+
function formatValue(val) {
|
|
4
|
+
if (Array.isArray(val)) {
|
|
5
|
+
return `[${val.join(", ")}]`;
|
|
6
|
+
}
|
|
7
|
+
return formatScalarValue(val) ?? String(val);
|
|
8
|
+
}
|
|
9
|
+
export function formatActionsPlan(changes) {
|
|
10
|
+
return formatChangeLines(changes, formatValue);
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ICommandExecutor } from "../../shared/command-executor.js";
|
|
2
|
+
import { type RepoInfo } from "../../repo/index.js";
|
|
3
|
+
import { type GhApiOptions } from "../../shared/gh-api-utils.js";
|
|
4
|
+
import type { ActionsApiBody, ActionsEndpointName, IActionsStrategy } from "./types.js";
|
|
5
|
+
interface GitHubActionsStrategyOptions {
|
|
6
|
+
retries?: number;
|
|
7
|
+
cwd: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class GitHubActionsStrategy implements IActionsStrategy {
|
|
10
|
+
private readonly api;
|
|
11
|
+
constructor(executor: ICommandExecutor, options: GitHubActionsStrategyOptions);
|
|
12
|
+
get(repoInfo: RepoInfo, endpoint: ActionsEndpointName, options?: GhApiOptions): Promise<ActionsApiBody>;
|
|
13
|
+
update(repoInfo: RepoInfo, endpoint: ActionsEndpointName, payload: ActionsApiBody, options?: GhApiOptions): Promise<void>;
|
|
14
|
+
private url;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { assertGitHubRepo } from "../../repo/index.js";
|
|
2
|
+
import { GhApiClient } from "../../shared/gh-api-utils.js";
|
|
3
|
+
import { parseApiJson } from "../../shared/json-utils.js";
|
|
4
|
+
import { endpointByName } from "./endpoints.js";
|
|
5
|
+
export class GitHubActionsStrategy {
|
|
6
|
+
api;
|
|
7
|
+
constructor(executor, options) {
|
|
8
|
+
this.api = new GhApiClient(executor, options.retries ?? 3, options.cwd);
|
|
9
|
+
}
|
|
10
|
+
async get(repoInfo, endpoint, options) {
|
|
11
|
+
const url = this.url(repoInfo, endpoint);
|
|
12
|
+
const result = await this.api.call("GET", url, { options });
|
|
13
|
+
return parseApiJson(result, `Actions ${endpoint} settings response`);
|
|
14
|
+
}
|
|
15
|
+
async update(repoInfo, endpoint, payload, options) {
|
|
16
|
+
const url = this.url(repoInfo, endpoint);
|
|
17
|
+
await this.api.call("PUT", url, { payload, options });
|
|
18
|
+
}
|
|
19
|
+
url(repoInfo, endpoint) {
|
|
20
|
+
assertGitHubRepo(repoInfo, "GitHub Actions strategy");
|
|
21
|
+
return `/repos/${repoInfo.owner}/${repoInfo.repo}/actions/${endpointByName(endpoint).path}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RepoConfig } from "../../config/index.js";
|
|
2
|
+
import type { RepoInfo } from "../../repo/index.js";
|
|
3
|
+
import type { IActionsStrategy } from "./types.js";
|
|
4
|
+
import { type ActionsPlanResult } from "./formatter.js";
|
|
5
|
+
import { type BaseProcessorOptions, type BaseProcessorResult, type ISettingsProcessor, type ChangeCounts } from "../base-processor.js";
|
|
6
|
+
export type IActionsProcessor = ISettingsProcessor<ActionsProcessorOptions, ActionsProcessorResult>;
|
|
7
|
+
export type ActionsProcessorOptions = BaseProcessorOptions;
|
|
8
|
+
export interface ActionsProcessorResult extends BaseProcessorResult {
|
|
9
|
+
changes?: ChangeCounts;
|
|
10
|
+
planOutput?: ActionsPlanResult;
|
|
11
|
+
warnings?: string[];
|
|
12
|
+
}
|
|
13
|
+
export declare class ActionsProcessor implements IActionsProcessor {
|
|
14
|
+
private readonly strategy;
|
|
15
|
+
constructor(strategy: IActionsStrategy);
|
|
16
|
+
process(repoConfig: RepoConfig, repoInfo: RepoInfo, options: ActionsProcessorOptions): Promise<ActionsProcessorResult>;
|
|
17
|
+
private applySettings;
|
|
18
|
+
private readCurrent;
|
|
19
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { runSequentially } from "../../shared/sequential.js";
|
|
2
|
+
import { ACTIONS_ENDPOINTS, buildPayload, readEndpoint, } from "./endpoints.js";
|
|
3
|
+
import { resolveActionsSettings, resolveForCurrentState } from "./resolve.js";
|
|
4
|
+
import { diffActions, hasActionsChanges } from "./diff.js";
|
|
5
|
+
import { formatActionsPlan } from "./formatter.js";
|
|
6
|
+
import { withGitHubGuards, countActions, buildDryRunResult, buildApplyResult, } from "../base-processor.js";
|
|
7
|
+
function withWarnings(result, warnings) {
|
|
8
|
+
return warnings.length > 0 ? { ...result, warnings } : result;
|
|
9
|
+
}
|
|
10
|
+
function touches(endpoint, settings) {
|
|
11
|
+
return endpoint.fields.some(({ setting }) => settings[setting] !== undefined);
|
|
12
|
+
}
|
|
13
|
+
function changed(endpoint, changes) {
|
|
14
|
+
return changes.some((c) => c.action !== "unchanged" &&
|
|
15
|
+
endpoint.fields.some(({ setting }) => setting === c.property));
|
|
16
|
+
}
|
|
17
|
+
export class ActionsProcessor {
|
|
18
|
+
strategy;
|
|
19
|
+
constructor(strategy) {
|
|
20
|
+
this.strategy = strategy;
|
|
21
|
+
}
|
|
22
|
+
async process(repoConfig, repoInfo, options) {
|
|
23
|
+
return withGitHubGuards(repoConfig, repoInfo, options, {
|
|
24
|
+
hasDesiredSettings: (rc) => {
|
|
25
|
+
const actions = rc.settings?.actions;
|
|
26
|
+
return !!actions && Object.keys(actions).length > 0;
|
|
27
|
+
},
|
|
28
|
+
emptySettingsMessage: "No Actions settings configured",
|
|
29
|
+
applySettings: (githubRepo, rc, opts, token, repoName) => this.applySettings(githubRepo, rc, opts, token, repoName),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
async applySettings(githubRepo, repoConfig, options, effectiveToken, repoName) {
|
|
33
|
+
const configured = repoConfig.settings?.actions;
|
|
34
|
+
if (!configured) {
|
|
35
|
+
throw new Error("applySettings called without actions settings");
|
|
36
|
+
}
|
|
37
|
+
const resolved = resolveActionsSettings(configured);
|
|
38
|
+
const strategyOptions = {
|
|
39
|
+
token: effectiveToken,
|
|
40
|
+
host: githubRepo.host,
|
|
41
|
+
};
|
|
42
|
+
const current = await this.readCurrent(githubRepo, resolved.settings, strategyOptions);
|
|
43
|
+
const settled = resolveForCurrentState(resolved.settings, current);
|
|
44
|
+
const desired = settled.settings;
|
|
45
|
+
const warnings = [...resolved.warnings, ...settled.warnings].map((w) => `${repoName}: ${w}`);
|
|
46
|
+
const endpoints = ACTIONS_ENDPOINTS.filter((e) => touches(e, desired));
|
|
47
|
+
if (endpoints.length === 0) {
|
|
48
|
+
return withWarnings({
|
|
49
|
+
success: true,
|
|
50
|
+
repoName,
|
|
51
|
+
message: "No Actions settings to apply",
|
|
52
|
+
skipped: true,
|
|
53
|
+
}, warnings);
|
|
54
|
+
}
|
|
55
|
+
const changes = diffActions(current, desired);
|
|
56
|
+
const changeCounts = countActions(changes);
|
|
57
|
+
if (!hasActionsChanges(changes)) {
|
|
58
|
+
return withWarnings({
|
|
59
|
+
success: true,
|
|
60
|
+
repoName,
|
|
61
|
+
message: "No changes needed",
|
|
62
|
+
changes: changeCounts,
|
|
63
|
+
}, warnings);
|
|
64
|
+
}
|
|
65
|
+
const planOutput = formatActionsPlan(changes);
|
|
66
|
+
if (options.dryRun) {
|
|
67
|
+
return withWarnings(buildDryRunResult(repoName, changeCounts, { planOutput }), warnings);
|
|
68
|
+
}
|
|
69
|
+
// Serial: GitHub asks for serial requests to avoid secondary rate limits
|
|
70
|
+
await runSequentially(endpoints.filter((e) => changed(e, changes)), (endpoint) => this.strategy.update(githubRepo, endpoint.name, buildPayload(endpoint, desired, current), strategyOptions));
|
|
71
|
+
const appliedCount = changes.filter((c) => c.action !== "unchanged").length;
|
|
72
|
+
return withWarnings(buildApplyResult(repoName, changeCounts, appliedCount, { planOutput }), warnings);
|
|
73
|
+
}
|
|
74
|
+
async readCurrent(githubRepo, desired, strategyOptions) {
|
|
75
|
+
let current = {};
|
|
76
|
+
// Serial: GitHub asks for serial requests to avoid secondary rate limits
|
|
77
|
+
await runSequentially(ACTIONS_ENDPOINTS.filter((e) => touches(e, desired)), async (endpoint) => {
|
|
78
|
+
// GitHub answers 409 to a selected-actions GET in any other mode
|
|
79
|
+
if (endpoint.name === "selectedActions" &&
|
|
80
|
+
current.allowedActions !== "selected") {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const body = await this.strategy.get(githubRepo, endpoint.name, strategyOptions);
|
|
84
|
+
current = { ...current, ...readEndpoint(endpoint, body) };
|
|
85
|
+
});
|
|
86
|
+
return current;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ActionsSettings } from "../../config/index.js";
|
|
2
|
+
export interface ResolvedActionsSettings {
|
|
3
|
+
settings: ActionsSettings;
|
|
4
|
+
warnings: string[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Drops merged fields GitHub would reject: a repo can override an inherited
|
|
8
|
+
* `selected` mode or disable Actions without restating the rest of the block.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveActionsSettings(actions: ActionsSettings): ResolvedActionsSettings;
|
|
11
|
+
/**
|
|
12
|
+
* Drops the fields GitHub rejects while Actions is off on the repo, unless the
|
|
13
|
+
* config turns it on, so an inherited block can't fail every run.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveForCurrentState(desired: ActionsSettings, current: ActionsSettings): ResolvedActionsSettings;
|
|
@@ -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,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aspruyt/xfg",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.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",
|