github-settings-as-code 3.2.0 → 4.0.1
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/README.md +17 -15
- package/dist/cmd/repo-settings.mjs +4 -2
- package/dist/cmd/repo-settings.mjs.map +1 -1
- package/dist/github/actions-settings/apply.d.mts.map +1 -1
- package/dist/github/actions-settings/apply.mjs +0 -4
- package/dist/github/actions-settings/apply.mjs.map +1 -1
- package/dist/github/actions-settings/backup.d.mts +1 -1
- package/dist/github/actions-settings/backup.d.mts.map +1 -1
- package/dist/github/actions-settings/backup.mjs +4 -4
- package/dist/github/actions-settings/backup.mjs.map +1 -1
- package/dist/github/actions-settings/constants.d.mts +1 -1
- package/dist/github/clear-json-files.d.mts +17 -0
- package/dist/github/clear-json-files.d.mts.map +1 -0
- package/dist/github/clear-json-files.mjs +29 -0
- package/dist/github/clear-json-files.mjs.map +1 -0
- package/dist/github/constants.d.mts +1 -0
- package/dist/github/constants.d.mts.map +1 -1
- package/dist/github/constants.mjs +1 -0
- package/dist/github/constants.mjs.map +1 -1
- package/dist/github/environments/api/get-environments.d.mts +1 -1
- package/dist/github/environments/apply.d.mts +3 -3
- package/dist/github/environments/apply.d.mts.map +1 -1
- package/dist/github/environments/apply.mjs +5 -9
- package/dist/github/environments/apply.mjs.map +1 -1
- package/dist/github/environments/backup.d.mts +6 -1
- package/dist/github/environments/backup.d.mts.map +1 -1
- package/dist/github/environments/backup.mjs +11 -5
- package/dist/github/environments/backup.mjs.map +1 -1
- package/dist/github/environments/constants.d.mts +1 -1
- package/dist/github/environments/read-environment-contents.d.mts +0 -1
- package/dist/github/environments/read-environment-contents.d.mts.map +1 -1
- package/dist/github/environments/read-environment-contents.mjs +0 -1
- package/dist/github/environments/read-environment-contents.mjs.map +1 -1
- package/dist/github/index.d.mts +2 -0
- package/dist/github/index.d.mts.map +1 -1
- package/dist/github/index.mjs +2 -0
- package/dist/github/index.mjs.map +1 -1
- package/dist/github/pages/apply.d.mts.map +1 -1
- package/dist/github/pages/apply.mjs +0 -2
- package/dist/github/pages/apply.mjs.map +1 -1
- package/dist/github/pages/backup.d.mts +11 -1
- package/dist/github/pages/backup.d.mts.map +1 -1
- package/dist/github/pages/backup.mjs +18 -5
- package/dist/github/pages/backup.mjs.map +1 -1
- package/dist/github/repository/apply.d.mts.map +1 -1
- package/dist/github/repository/apply.mjs +0 -4
- package/dist/github/repository/apply.mjs.map +1 -1
- package/dist/github/repository/backup.d.mts.map +1 -1
- package/dist/github/repository/backup.mjs +4 -4
- package/dist/github/repository/backup.mjs.map +1 -1
- package/dist/github/ruleset/apply.d.mts.map +1 -1
- package/dist/github/ruleset/apply.mjs +9 -9
- package/dist/github/ruleset/apply.mjs.map +1 -1
- package/dist/github/ruleset/backup.d.mts +7 -0
- package/dist/github/ruleset/backup.d.mts.map +1 -1
- package/dist/github/ruleset/backup.mjs +20 -7
- package/dist/github/ruleset/backup.mjs.map +1 -1
- package/dist/github/ruleset/read-rule-set-contents.d.mts +0 -1
- package/dist/github/ruleset/read-rule-set-contents.d.mts.map +1 -1
- package/dist/github/ruleset/read-rule-set-contents.mjs +0 -1
- package/dist/github/ruleset/read-rule-set-contents.mjs.map +1 -1
- package/dist/github/settings-file-path.d.mts +14 -0
- package/dist/github/settings-file-path.d.mts.map +1 -0
- package/dist/github/settings-file-path.mjs +41 -0
- package/dist/github/settings-file-path.mjs.map +1 -0
- package/dist/github/variables/api/list-repo-variables.d.mts.map +1 -1
- package/dist/github/variables/api/list-repo-variables.mjs +3 -1
- package/dist/github/variables/api/list-repo-variables.mjs.map +1 -1
- package/dist/github/variables/apply.d.mts +9 -0
- package/dist/github/variables/apply.d.mts.map +1 -1
- package/dist/github/variables/apply.mjs +31 -17
- package/dist/github/variables/apply.mjs.map +1 -1
- package/dist/github/variables/backup.d.mts +20 -0
- package/dist/github/variables/backup.d.mts.map +1 -0
- package/dist/github/variables/backup.mjs +35 -0
- package/dist/github/variables/backup.mjs.map +1 -0
- package/dist/github/variables/constants.d.mts +65 -0
- package/dist/github/variables/constants.d.mts.map +1 -0
- package/dist/github/variables/constants.mjs +48 -0
- package/dist/github/variables/constants.mjs.map +1 -0
- package/dist/github/variables/index.d.mts +2 -0
- package/dist/github/variables/index.d.mts.map +1 -1
- package/dist/github/variables/index.mjs +2 -0
- package/dist/github/variables/index.mjs.map +1 -1
- package/dist/github/vulnerability-alerts/apply.d.mts.map +1 -1
- package/dist/github/vulnerability-alerts/apply.mjs +0 -2
- package/dist/github/vulnerability-alerts/apply.mjs.map +1 -1
- package/dist/github/vulnerability-alerts/backup.d.mts +1 -1
- package/dist/github/vulnerability-alerts/backup.d.mts.map +1 -1
- package/dist/github/vulnerability-alerts/backup.mjs +4 -4
- package/dist/github/vulnerability-alerts/backup.mjs.map +1 -1
- package/package.json +35 -34
- package/src/cmd/repo-settings.mts +5 -2
- package/src/github/actions-settings/apply.mts +0 -9
- package/src/github/actions-settings/backup.mts +6 -11
- package/src/github/actions-settings/constants.mts +1 -1
- package/src/github/clear-json-files.mts +31 -0
- package/src/github/clear-json-files.test.mts +78 -0
- package/src/github/constants.mts +2 -0
- package/src/github/environments/api/get-environments.mts +1 -1
- package/src/github/environments/apply.mts +8 -13
- package/src/github/environments/backup.mts +13 -12
- package/src/github/environments/constants.mts +1 -1
- package/src/github/environments/read-environment-contents.mts +0 -4
- package/src/github/index.mts +2 -0
- package/src/github/pages/apply.mts +0 -6
- package/src/github/pages/backup.mts +21 -12
- package/src/github/repository/apply.mts +0 -9
- package/src/github/repository/backup.mts +5 -10
- package/src/github/ruleset/apply.mts +10 -18
- package/src/github/ruleset/backup.mts +23 -13
- package/src/github/ruleset/read-rule-set-contents.mts +0 -4
- package/src/github/ruleset/schema.test.mts +13 -24
- package/src/github/settings-file-path.mts +51 -0
- package/src/github/settings-file-path.test.mts +70 -0
- package/src/github/variables/api/list-repo-variables.mts +3 -1
- package/src/github/variables/apply.mts +54 -27
- package/src/github/variables/backup.mts +47 -0
- package/src/github/variables/constants.mts +61 -0
- package/src/github/variables/constants.test.mts +112 -0
- package/src/github/variables/index.mts +2 -0
- package/src/github/vulnerability-alerts/apply.mts +0 -6
- package/src/github/vulnerability-alerts/backup.mts +6 -11
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Result } from 'ts-data-forge';
|
|
2
|
+
import {
|
|
3
|
+
assertVariableNamesAreValid,
|
|
4
|
+
RepositoryVariables,
|
|
5
|
+
} from './constants.mjs';
|
|
6
|
+
|
|
7
|
+
/** `'rejected'` when the names were refused, `'accepted'` when they were not. */
|
|
8
|
+
const outcomeOf = (variables: RepositoryVariables): string =>
|
|
9
|
+
Result.isErr(
|
|
10
|
+
Result.fromThrowable(() => {
|
|
11
|
+
assertVariableNamesAreValid(variables);
|
|
12
|
+
}),
|
|
13
|
+
)
|
|
14
|
+
? 'rejected'
|
|
15
|
+
: 'accepted';
|
|
16
|
+
|
|
17
|
+
describe('the repository-variables schema', () => {
|
|
18
|
+
test('accepts a declaration of names to values', () => {
|
|
19
|
+
const result = RepositoryVariables.validate({
|
|
20
|
+
REPO_AUTOMATION_BOT_CLIENT_ID: 'Iv1example0client0id',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
assert.isTrue(Result.isOk(result));
|
|
24
|
+
|
|
25
|
+
if (Result.isOk(result)) {
|
|
26
|
+
assert.deepStrictEqual(result.value, {
|
|
27
|
+
REPO_AUTOMATION_BOT_CLIENT_ID: 'Iv1example0client0id',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('accepts an empty declaration', () => {
|
|
33
|
+
assert.isTrue(Result.isOk(RepositoryVariables.validate({})));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('rejects a value that is not a string', () => {
|
|
37
|
+
// A variable's value is always a string on GitHub's side. A number here
|
|
38
|
+
// would be sent as one and read back as `"4476573"`, which reads as drift
|
|
39
|
+
// on the next backup.
|
|
40
|
+
assert.isTrue(
|
|
41
|
+
Result.isErr(RepositoryVariables.validate({ A_NUMBER: 123 })),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
assert.isTrue(Result.isErr(RepositoryVariables.validate({ A_NULL: null })));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('rejects a declaration that is not a record', () => {
|
|
48
|
+
assert.isTrue(Result.isErr(RepositoryVariables.validate([])));
|
|
49
|
+
|
|
50
|
+
assert.isTrue(Result.isErr(RepositoryVariables.validate('')));
|
|
51
|
+
|
|
52
|
+
assert.isTrue(Result.isErr(RepositoryVariables.validate(null)));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe(assertVariableNamesAreValid, () => {
|
|
57
|
+
test('accepts the names GitHub accepts', () => {
|
|
58
|
+
assert.deepStrictEqual(
|
|
59
|
+
outcomeOf({
|
|
60
|
+
REPO_AUTOMATION_BOT_CLIENT_ID: 'x',
|
|
61
|
+
lowercase_is_allowed: 'x',
|
|
62
|
+
_LEADING_UNDERSCORE: 'x',
|
|
63
|
+
MIXED_Case_9: 'x',
|
|
64
|
+
}),
|
|
65
|
+
'accepted',
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('rejects a name starting with a digit', () => {
|
|
70
|
+
assert.deepStrictEqual(outcomeOf({ '1ST_PLACE': 'x' }), 'rejected');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('rejects a name carrying a character GitHub does not allow', () => {
|
|
74
|
+
assert.deepStrictEqual(outcomeOf({ 'WITH-HYPHEN': 'x' }), 'rejected');
|
|
75
|
+
|
|
76
|
+
assert.deepStrictEqual(outcomeOf({ 'WITH SPACE': 'x' }), 'rejected');
|
|
77
|
+
|
|
78
|
+
assert.deepStrictEqual(outcomeOf({ 'WITH.DOT': 'x' }), 'rejected');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('rejects the reserved GITHUB_ prefix, in any case', () => {
|
|
82
|
+
assert.deepStrictEqual(outcomeOf({ GITHUB_TOKEN: 'x' }), 'rejected');
|
|
83
|
+
|
|
84
|
+
assert.deepStrictEqual(outcomeOf({ github_token: 'x' }), 'rejected');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('rejects an empty name', () => {
|
|
88
|
+
assert.deepStrictEqual(outcomeOf({ '': 'x' }), 'rejected');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('names every offender, so one run fixes the file', () => {
|
|
92
|
+
const result = Result.fromThrowable(() => {
|
|
93
|
+
assertVariableNamesAreValid({
|
|
94
|
+
'WITH-HYPHEN': 'x',
|
|
95
|
+
GITHUB_TOKEN: 'x',
|
|
96
|
+
FINE: 'x',
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
assert.isTrue(Result.isErr(result));
|
|
101
|
+
|
|
102
|
+
if (!Result.isErr(result)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
assert.isTrue(result.value.message.includes('WITH-HYPHEN'));
|
|
107
|
+
|
|
108
|
+
assert.isTrue(result.value.message.includes('GITHUB_TOKEN'));
|
|
109
|
+
|
|
110
|
+
assert.isFalse(result.value.message.includes('FINE'));
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -43,12 +43,6 @@ export const applyVulnerabilityAlerts = async (): Promise<void> => {
|
|
|
43
43
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
44
44
|
await fs.writeFile(settingsPath, str);
|
|
45
45
|
|
|
46
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
47
|
-
await fs.writeFile(
|
|
48
|
-
path.resolve(vulnerabilityAlertsDir, 'bk', settingsJsonName),
|
|
49
|
-
str,
|
|
50
|
-
);
|
|
51
|
-
|
|
52
46
|
await formatUncommittedFiles();
|
|
53
47
|
}
|
|
54
48
|
};
|
|
@@ -2,27 +2,22 @@
|
|
|
2
2
|
import 'dotenv/config';
|
|
3
3
|
import * as fs from 'node:fs/promises';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
isDirectlyExecuted,
|
|
8
|
-
makeEmptyDir,
|
|
9
|
-
} from 'ts-repo-utils';
|
|
5
|
+
import { formatUncommittedFiles, isDirectlyExecuted } from 'ts-repo-utils';
|
|
6
|
+
import { clearJsonFilesIn } from '../clear-json-files.mjs';
|
|
10
7
|
import { settingsJsonName, vulnerabilityAlertsDir } from '../constants.mjs';
|
|
11
8
|
import { getVulnerabilityAlerts } from './api/index.mjs';
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/** Dependabot alerts の現在値を `bk/` に保存する。 */
|
|
10
|
+
/** Dependabot alerts の現在値を宣言ファイルへ撮り直す。 */
|
|
16
11
|
export const backupVulnerabilityAlerts = async (
|
|
17
12
|
fmt: boolean = true,
|
|
18
13
|
): Promise<void> => {
|
|
19
|
-
await makeEmptyDir(backupDir);
|
|
20
|
-
|
|
21
14
|
const settings = await getVulnerabilityAlerts();
|
|
22
15
|
|
|
16
|
+
await clearJsonFilesIn(vulnerabilityAlertsDir);
|
|
17
|
+
|
|
23
18
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
24
19
|
await fs.writeFile(
|
|
25
|
-
path.resolve(
|
|
20
|
+
path.resolve(vulnerabilityAlertsDir, settingsJsonName),
|
|
26
21
|
JSON.stringify(settings, undefined, 2),
|
|
27
22
|
);
|
|
28
23
|
|