github-settings-as-code 4.0.5 → 4.0.6
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/github/clear-json-files.d.mts.map +1 -1
- package/dist/github/clear-json-files.mjs +3 -7
- package/dist/github/clear-json-files.mjs.map +1 -1
- package/dist/github/environments/api/get-environments.d.mts.map +1 -1
- package/dist/github/environments/api/get-environments.mjs +5 -5
- package/dist/github/environments/api/get-environments.mjs.map +1 -1
- package/dist/github/environments/read-environment-contents.d.mts +5 -0
- package/dist/github/environments/read-environment-contents.d.mts.map +1 -1
- package/dist/github/environments/read-environment-contents.mjs +9 -10
- package/dist/github/environments/read-environment-contents.mjs.map +1 -1
- package/dist/github/index.d.mts +1 -0
- package/dist/github/index.d.mts.map +1 -1
- package/dist/github/index.mjs +1 -0
- package/dist/github/index.mjs.map +1 -1
- package/dist/github/list-json-files.d.mts +11 -0
- package/dist/github/list-json-files.d.mts.map +1 -0
- package/dist/github/list-json-files.mjs +19 -0
- package/dist/github/list-json-files.mjs.map +1 -0
- package/dist/github/resolve-target-repo.d.mts.map +1 -1
- package/dist/github/resolve-target-repo.mjs +37 -37
- package/dist/github/resolve-target-repo.mjs.map +1 -1
- package/dist/github/ruleset/read-rule-set-contents.d.mts +5 -0
- package/dist/github/ruleset/read-rule-set-contents.d.mts.map +1 -1
- package/dist/github/ruleset/read-rule-set-contents.mjs +9 -12
- package/dist/github/ruleset/read-rule-set-contents.mjs.map +1 -1
- package/package.json +10 -10
- package/src/github/clear-json-files.mts +3 -8
- package/src/github/environments/api/get-environments.mts +9 -9
- package/src/github/environments/read-environment-contents.mts +12 -14
- package/src/github/environments/read-environment-contents.test.mts +31 -0
- package/src/github/index.mts +1 -0
- package/src/github/list-json-files.mts +22 -0
- package/src/github/list-json-files.test.mts +45 -0
- package/src/github/resolve-target-repo.mts +47 -47
- package/src/github/ruleset/read-rule-set-contents.mts +14 -16
- package/src/github/ruleset/read-rule-set-contents.test.mts +31 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear-json-files.d.mts","sourceRoot":"","sources":["../../src/github/clear-json-files.mts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,QAAe,MAAM,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"clear-json-files.d.mts","sourceRoot":"","sources":["../../src/github/clear-json-files.mts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,QAAe,MAAM,KAAG,OAAO,CAAC,IAAI,CAOhE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import
|
|
2
|
+
import { listJsonFilesIn } from './list-json-files.mjs';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
@@ -18,12 +18,8 @@ import * as path from 'node:path';
|
|
|
18
18
|
export const clearJsonFilesIn = async (dir) => {
|
|
19
19
|
|
|
20
20
|
await fs.mkdir(dir, { recursive: true });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (const entry of entries) {
|
|
24
|
-
if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
25
|
-
await fs.rm(path.resolve(dir, entry.name));
|
|
26
|
-
}
|
|
21
|
+
for (const file of await listJsonFilesIn(dir)) {
|
|
22
|
+
await fs.rm(file);
|
|
27
23
|
}
|
|
28
24
|
};
|
|
29
25
|
//# sourceMappingURL=clear-json-files.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear-json-files.mjs","sourceRoot":"","sources":["../../src/github/clear-json-files.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"clear-json-files.mjs","sourceRoot":"","sources":["../../src/github/clear-json-files.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,GAAW,EAAiB,EAAE;IACnE,mEAAmE;IACnE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEzC,KAAK,MAAM,IAAI,IAAI,MAAM,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-environments.d.mts","sourceRoot":"","sources":["../../../../src/github/environments/api/get-environments.mts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QAAa,OAAO,CACjD,SAAS,mBAAmB,EAAE,CAoC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"get-environments.d.mts","sourceRoot":"","sources":["../../../../src/github/environments/api/get-environments.mts"],"names":[],"mappings":"AAMA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,QAAa,OAAO,CACjD,SAAS,mBAAmB,EAAE,CAoC/B,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,2BAA2B,oBACrB,MAAM,KACtB,OAAO,CAAC,SAAS,sBAAsB,EAAE,CAkB3C,CAAC;AAWF,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,GAAG,KAAK,CAAC;CACxB,CAAC,CAAC"}
|
|
@@ -36,11 +36,6 @@ export const getAllEnvironments = async () => {
|
|
|
36
36
|
return settings.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const getDeploymentBranchPolicyNames = async (environmentName) => {
|
|
40
|
-
const policies = await getDeploymentBranchPolicies(environmentName);
|
|
41
|
-
return policies.map(({ name, type }) => ({ name, type }));
|
|
42
|
-
};
|
|
43
|
-
|
|
44
39
|
export const getDeploymentBranchPolicies = async (environmentName) => {
|
|
45
40
|
|
|
46
41
|
const response = await octokit.request('GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies', {
|
|
@@ -57,6 +52,11 @@ export const getDeploymentBranchPolicies = async (environmentName) => {
|
|
|
57
52
|
}));
|
|
58
53
|
};
|
|
59
54
|
|
|
55
|
+
const getDeploymentBranchPolicyNames = async (environmentName) => {
|
|
56
|
+
const policies = await getDeploymentBranchPolicies(environmentName);
|
|
57
|
+
return policies.map(({ name, type }) => ({ name, type }));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-environments.mjs","sourceRoot":"","sources":["../../../../src/github/environments/api/get-environments.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAErC,EAAE;IACF,0EAA0E;IAC1E,EAAE;IACF,uCAAuC;IACvC,wCAAwC;IACxC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CACpC,wCAA+D,EAC/D,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,CACrE,CAAC;IAEF,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC;IAEtD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,CAChC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,WAAW,CAAC,wBAAwB,IAAI,SAAS,CAAC;QAEjE,OAAO,mBAAmB,CAAC,IAAI,CAAC;YAC9B,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,GAAG,oBAAoB,CAAC,WAAW,CAAC,gBAAgB,CAAC;YACrD,wBAAwB,EACtB,MAAM,KAAK,SAAS;gBAClB,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC;oBACE,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;oBAC7C,sBAAsB,EAAE,MAAM,CAAC,sBAAsB;iBACtD;YACP,0BAA0B,EACxB,MAAM,EAAE,sBAAsB,KAAK,IAAI;gBACrC,CAAC,CAAC,MAAM,8BAA8B,CAAC,WAAW,CAAC,IAAI,CAAC;gBACxD,CAAC,CAAC,EAAE;SACT,CAAC,CAAC;IACL,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,
|
|
1
|
+
{"version":3,"file":"get-environments.mjs","sourceRoot":"","sources":["../../../../src/github/environments/api/get-environments.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,O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,CAAC,CAAC;IACnC,mBAAmB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,SAAS,EAAE,CAAC,CAAC,QAAQ,CACnB,CAAC,CAAC,KAAK,CACL,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;YACjC,QAAQ,EAAE,yBAAyB;YACnC,YAAY,EAAE,MAAM;SACrB,CAAC;QACF,iDAAiD;QACjD,yCAAyC;QACzC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC,CAAC,CACH,CACF;CACF,CAAC,EACF,EAAE,QAAQ,EAAE,4BAA4B,EAAE,CAC3C,CAAC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { EnvironmentSettings } from './constants.mjs';
|
|
2
2
|
export declare const readEnvironmentFiles: () => Promise<readonly EnvironmentSettings[]>;
|
|
3
|
+
/**
|
|
4
|
+
* `dir` の直下の宣言(`*.json`)を読んで検証する。テストが一時ディレクトリを
|
|
5
|
+
* 渡せるように、ディレクトリを引数に取る。
|
|
6
|
+
*/
|
|
7
|
+
export declare const readEnvironmentFilesIn: (dir: string) => Promise<readonly EnvironmentSettings[]>;
|
|
3
8
|
//# sourceMappingURL=read-environment-contents.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-environment-contents.d.mts","sourceRoot":"","sources":["../../../src/github/environments/read-environment-contents.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-environment-contents.d.mts","sourceRoot":"","sources":["../../../src/github/environments/read-environment-contents.mts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,QAAa,OAAO,CACnD,SAAS,mBAAmB,EAAE,CACY,CAAC;AAE7C;;;GAGG;AACH,eAAO,MAAM,sBAAsB,QAC5B,MAAM,KACV,OAAO,CAAC,SAAS,mBAAmB,EAAE,CAyBxC,CAAC"}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
2
|
import * as t from 'ts-fortress';
|
|
4
3
|
import { isDirectlyExecuted, Result } from 'ts-repo-utils';
|
|
5
4
|
import { environmentsDir } from '../constants.mjs';
|
|
5
|
+
import { listJsonFilesIn } from '../list-json-files.mjs';
|
|
6
6
|
import { EnvironmentSettings } from './constants.mjs';
|
|
7
|
-
export const readEnvironmentFiles = async () =>
|
|
8
|
-
const readFilesIn = async (dir) => {
|
|
7
|
+
export const readEnvironmentFiles = async () => readEnvironmentFilesIn(environmentsDir);
|
|
9
8
|
|
|
10
|
-
const files = await fs.readdir(dir, {
|
|
11
|
-
withFileTypes: true,
|
|
12
|
-
});
|
|
13
|
-
const fileContents = await Promise.all(files
|
|
14
|
-
.filter((d) => d.isFile())
|
|
15
|
-
.map((d) =>
|
|
16
9
|
|
|
17
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export const readEnvironmentFilesIn = async (dir) => {
|
|
13
|
+
const files = await listJsonFilesIn(dir);
|
|
14
|
+
const fileContents = await Promise.all(files.map((file) =>
|
|
15
|
+
|
|
16
|
+
fs.readFile(file, { encoding: 'utf8' })));
|
|
18
17
|
const validationResults = fileContents.map((content) => EnvironmentSettings.validate(JSON.parse(content)));
|
|
19
18
|
const mut_values = [];
|
|
20
19
|
for (const r of validationResults) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-environment-contents.mjs","sourceRoot":"","sources":["../../../src/github/environments/read-environment-contents.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-environment-contents.mjs","sourceRoot":"","sources":["../../../src/github/environments/read-environment-contents.mts"],"names":[],"mappings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AI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,IAAI,kBAAkB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACxC,MAAM,oBAAoB,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/github/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './actions-settings/index.mjs';
|
|
|
2
2
|
export * from './clear-json-files.mjs';
|
|
3
3
|
export * from './constants.mjs';
|
|
4
4
|
export * from './environments/index.mjs';
|
|
5
|
+
export * from './list-json-files.mjs';
|
|
5
6
|
export * from './pages/index.mjs';
|
|
6
7
|
export * from './repository/index.mjs';
|
|
7
8
|
export * from './resolve-target-repo.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/github/index.mts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/github/index.mts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC"}
|
package/dist/github/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ export * from './actions-settings/index.mjs';
|
|
|
2
2
|
export * from './clear-json-files.mjs';
|
|
3
3
|
export * from './constants.mjs';
|
|
4
4
|
export * from './environments/index.mjs';
|
|
5
|
+
export * from './list-json-files.mjs';
|
|
5
6
|
export * from './pages/index.mjs';
|
|
6
7
|
export * from './repository/index.mjs';
|
|
7
8
|
export * from './resolve-target-repo.mjs';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/github/index.mts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/github/index.mts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `dir` の直下にある `*.json` の絶対パス。宣言のディレクトリを読むところと
|
|
3
|
+
* 消すところは、どちらもこれで宣言のファイルを選ぶ。
|
|
4
|
+
*
|
|
5
|
+
* 拡張子で絞るのは、宣言の隣に置く README(`repo-settings/variables/README.md`
|
|
6
|
+
* のような、JSON でない同居ファイル)を宣言として読んだり消したりしないため。
|
|
7
|
+
* 読む側が絞らないと、README を置いただけで `JSON.parse` が投げ、apply が何も
|
|
8
|
+
* 送らずに止まる。
|
|
9
|
+
*/
|
|
10
|
+
export declare const listJsonFilesIn: (dir: string) => Promise<readonly string[]>;
|
|
11
|
+
//# sourceMappingURL=list-json-files.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-json-files.d.mts","sourceRoot":"","sources":["../../src/github/list-json-files.mts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,QACrB,MAAM,KACV,OAAO,CAAC,SAAS,MAAM,EAAE,CAO3B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export const listJsonFilesIn = async (dir) => {
|
|
13
|
+
|
|
14
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
15
|
+
return entries
|
|
16
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.json'))
|
|
17
|
+
.map((entry) => path.resolve(dir, entry.name));
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=list-json-files.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-json-files.mjs","sourceRoot":"","sources":["../../src/github/list-json-files.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAClC,GAAW,EACiB,EAAE;IAC9B,mEAAmE;IACnE,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAE/D,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SACjE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-target-repo.d.mts","sourceRoot":"","sources":["../../src/github/resolve-target-repo.mts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-target-repo.d.mts","sourceRoot":"","sources":["../../src/github/resolve-target-repo.mts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,iBAAiB,QAAa,OAAO,CAAC,UAAU,CAmC5D,CAAC"}
|
|
@@ -5,6 +5,43 @@ import * as util from 'node:util';
|
|
|
5
5
|
import { Arr, hasKey, isRecord, isString, Json } from 'ts-data-forge';
|
|
6
6
|
import { Result } from 'ts-repo-utils';
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
export const resolveTargetRepo = async () => {
|
|
18
|
+
const sources = [
|
|
19
|
+
fromCliArgs(),
|
|
20
|
+
fromEnv(),
|
|
21
|
+
fromGitRemote(),
|
|
22
|
+
await fromPackageJson(),
|
|
23
|
+
];
|
|
24
|
+
const owner = sources.map((s) => s.owner).find((v) => v !== undefined);
|
|
25
|
+
if (owner === undefined) {
|
|
26
|
+
throw new Error([
|
|
27
|
+
'owner を特定できませんでした。次のいずれかで指定してください:',
|
|
28
|
+
' --owner <owner> (コマンドライン引数)',
|
|
29
|
+
' OWNER=<owner> (環境変数)',
|
|
30
|
+
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
31
|
+
].join('\n'));
|
|
32
|
+
}
|
|
33
|
+
const repo = sources.map((s) => s.repo).find((v) => v !== undefined);
|
|
34
|
+
if (repo === undefined) {
|
|
35
|
+
throw new Error([
|
|
36
|
+
'repository 名を特定できませんでした。次のいずれかで指定してください:',
|
|
37
|
+
' --repo <repo> (コマンドライン引数)',
|
|
38
|
+
' REPO_NAME=<repo> (環境変数)',
|
|
39
|
+
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
40
|
+
].join('\n'));
|
|
41
|
+
}
|
|
42
|
+
return { owner, repo };
|
|
43
|
+
};
|
|
44
|
+
|
|
8
45
|
const pickString = (value) => value !== '' && isString(value) ? value : undefined;
|
|
9
46
|
|
|
10
47
|
|
|
@@ -73,41 +110,4 @@ const fromPackageJson = async () => {
|
|
|
73
110
|
return {};
|
|
74
111
|
}
|
|
75
112
|
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
export const resolveTargetRepo = async () => {
|
|
87
|
-
const sources = [
|
|
88
|
-
fromCliArgs(),
|
|
89
|
-
fromEnv(),
|
|
90
|
-
fromGitRemote(),
|
|
91
|
-
await fromPackageJson(),
|
|
92
|
-
];
|
|
93
|
-
const owner = sources.map((s) => s.owner).find((v) => v !== undefined);
|
|
94
|
-
if (owner === undefined) {
|
|
95
|
-
throw new Error([
|
|
96
|
-
'owner を特定できませんでした。次のいずれかで指定してください:',
|
|
97
|
-
' --owner <owner> (コマンドライン引数)',
|
|
98
|
-
' OWNER=<owner> (環境変数)',
|
|
99
|
-
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
100
|
-
].join('\n'));
|
|
101
|
-
}
|
|
102
|
-
const repo = sources.map((s) => s.repo).find((v) => v !== undefined);
|
|
103
|
-
if (repo === undefined) {
|
|
104
|
-
throw new Error([
|
|
105
|
-
'repository 名を特定できませんでした。次のいずれかで指定してください:',
|
|
106
|
-
' --repo <repo> (コマンドライン引数)',
|
|
107
|
-
' REPO_NAME=<repo> (環境変数)',
|
|
108
|
-
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
109
|
-
].join('\n'));
|
|
110
|
-
}
|
|
111
|
-
return { owner, repo };
|
|
112
|
-
};
|
|
113
113
|
//# sourceMappingURL=resolve-target-repo.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-target-repo.mjs","sourceRoot":"","sources":["../../src/github/resolve-target-repo.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAOvC,gEAAgE;AAChE,MAAM,UAAU,GAAG,CAAC,KAAc,EAAsB,EAAE,CACxD,KAAK,KAAK,EAAE,IAAI,QAAQ,CAAC,KAAK,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MAAM,CAAC;SAChC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEF,0DAA0D;AAC1D,MAAM,eAAe,GAAG,KAAK,IAAkC,EAAE;IAC/D,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,gBAAgB,CAAC,CAAC;IAEtE,IAAI,CAAC;QACH,mEAAmE;QACnE,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,EAAE;YACxD,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAE/C,IACE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC;YACzB,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC;YAC5B,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC;YAClC,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,EACjC,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { RulesetPicked } from './constants.mjs';
|
|
2
2
|
export declare const readRulesetFiles: () => Promise<readonly RulesetPicked[]>;
|
|
3
|
+
/**
|
|
4
|
+
* `dir` の直下の宣言(`*.json`)を読んで検証する。テストが一時ディレクトリを
|
|
5
|
+
* 渡せるように、ディレクトリを引数に取る。
|
|
6
|
+
*/
|
|
7
|
+
export declare const readRulesetFilesIn: (dir: string) => Promise<readonly RulesetPicked[]>;
|
|
3
8
|
//# sourceMappingURL=read-rule-set-contents.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-rule-set-contents.d.mts","sourceRoot":"","sources":["../../../src/github/ruleset/read-rule-set-contents.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-rule-set-contents.d.mts","sourceRoot":"","sources":["../../../src/github/ruleset/read-rule-set-contents.mts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAAC,SAAS,aAAa,EAAE,CACzC,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QACxB,MAAM,KACV,OAAO,CAAC,SAAS,aAAa,EAAE,CAyBlC,CAAC"}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
2
|
import * as t from 'ts-fortress';
|
|
4
3
|
import { isDirectlyExecuted, Result } from 'ts-repo-utils';
|
|
5
4
|
import { rulesetsDir } from '../constants.mjs';
|
|
5
|
+
import { listJsonFilesIn } from '../list-json-files.mjs';
|
|
6
6
|
import { RulesetPicked } from './constants.mjs';
|
|
7
|
-
export const readRulesetFiles = async () =>
|
|
8
|
-
const readFilesIn = async (dir) => {
|
|
7
|
+
export const readRulesetFiles = async () => readRulesetFilesIn(rulesetsDir);
|
|
9
8
|
|
|
10
|
-
const files = await fs.readdir(dir, {
|
|
11
|
-
withFileTypes: true,
|
|
12
|
-
});
|
|
13
|
-
const rulesetFileContents = await Promise.all(files
|
|
14
|
-
.filter((d) => d.isFile())
|
|
15
|
-
.map((d) =>
|
|
16
9
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export const readRulesetFilesIn = async (dir) => {
|
|
13
|
+
const files = await listJsonFilesIn(dir);
|
|
14
|
+
const rulesetFileContents = await Promise.all(files.map((file) =>
|
|
15
|
+
|
|
16
|
+
fs.readFile(file, { encoding: 'utf8' })));
|
|
20
17
|
const validationResults = rulesetFileContents.map((rule) => RulesetPicked.validate(JSON.parse(rule)));
|
|
21
18
|
const mut_values = [];
|
|
22
19
|
for (const r of validationResults) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-rule-set-contents.mjs","sourceRoot":"","sources":["../../../src/github/ruleset/read-rule-set-contents.mts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"read-rule-set-contents.mjs","sourceRoot":"","sources":["../../../src/github/ruleset/read-rule-set-contents.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAAuC,EAAE,CAC5E,kBAAkB,CAAC,WAAW,CAAC,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,GAAW,EACwB,EAAE;IACrC,MAAM,KAAK,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAEzC,MAAM,mBAAmB,GAAsB,MAAM,OAAO,CAAC,GAAG,CAC9D,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;IACjB,mEAAmE;IACnE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CACxC,CACF,CAAC;IAEF,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACzD,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CACzC,CAAC;IAEF,MAAM,UAAU,GAAoB,EAAE,CAAC;IAEvC,KAAK,MAAM,CAAC,IAAI,iBAAiB,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACpE,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,IAAI,kBAAkB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACxC,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-settings-as-code",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"dedent": "^1.7.2",
|
|
30
30
|
"dotenv": "^18.0.8",
|
|
31
31
|
"octokit-safe-types": "^1.2.28",
|
|
32
|
-
"ts-data-forge": "^14.
|
|
33
|
-
"ts-fortress": "^12.4.
|
|
34
|
-
"ts-repo-utils": "^10.7.
|
|
32
|
+
"ts-data-forge": "^14.11.0",
|
|
33
|
+
"ts-fortress": "^12.4.3",
|
|
34
|
+
"ts-repo-utils": "^10.7.2",
|
|
35
35
|
"ts-type-forge": "^9.2.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"@vitest/ui": "5.0.5",
|
|
41
41
|
"cspell": "10.4.0",
|
|
42
42
|
"eslint": "10.13.0",
|
|
43
|
-
"eslint-config-typed": "
|
|
44
|
-
"eslint-plugin-ts-data-forge": "0.10.
|
|
45
|
-
"eslint-plugin-ts-fortress": "1.3.
|
|
46
|
-
"eslint-plugin-ts-type-forge": "0.8.
|
|
43
|
+
"eslint-config-typed": "7.4.0",
|
|
44
|
+
"eslint-plugin-ts-data-forge": "0.10.9",
|
|
45
|
+
"eslint-plugin-ts-fortress": "1.3.13",
|
|
46
|
+
"eslint-plugin-ts-type-forge": "0.8.18",
|
|
47
47
|
"jiti": "2.7.0",
|
|
48
|
-
"npm-run-all2": "9.0.
|
|
48
|
+
"npm-run-all2": "9.0.4",
|
|
49
49
|
"prettier": "3.9.10",
|
|
50
50
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
51
51
|
"prettier-plugin-packagejson": "3.0.2",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"vitest": "5.0.5"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
|
-
"node": ">=22.
|
|
58
|
+
"node": ">=22.23.4",
|
|
59
59
|
"pnpm": ">=9.0.0"
|
|
60
60
|
},
|
|
61
61
|
"volta": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as fs from 'node:fs/promises';
|
|
2
|
-
import
|
|
2
|
+
import { listJsonFilesIn } from './list-json-files.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* `dir` の直下の `*.json` を消す。ディレクトリが無ければ作る。
|
|
@@ -20,12 +20,7 @@ export const clearJsonFilesIn = async (dir: string): Promise<void> => {
|
|
|
20
20
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
21
21
|
await fs.mkdir(dir, { recursive: true });
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (const entry of entries) {
|
|
27
|
-
if (entry.isFile() && entry.name.endsWith('.json')) {
|
|
28
|
-
await fs.rm(path.resolve(dir, entry.name));
|
|
29
|
-
}
|
|
23
|
+
for (const file of await listJsonFilesIn(dir)) {
|
|
24
|
+
await fs.rm(file);
|
|
30
25
|
}
|
|
31
26
|
};
|
|
@@ -51,15 +51,6 @@ export const getAllEnvironments = async (): Promise<
|
|
|
51
51
|
return settings.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
/** 宣言ファイルに載る形。 `id` は GitHub 側の都合なので落とす。 */
|
|
55
|
-
const getDeploymentBranchPolicyNames = async (
|
|
56
|
-
environmentName: string,
|
|
57
|
-
): Promise<readonly Readonly<{ name: string; type: 'branch' | 'tag' }>[]> => {
|
|
58
|
-
const policies = await getDeploymentBranchPolicies(environmentName);
|
|
59
|
-
|
|
60
|
-
return policies.map(({ name, type }) => ({ name, type }));
|
|
61
|
-
};
|
|
62
|
-
|
|
63
54
|
/** 「 Selected branches and tags 」に登録されている pattern を列挙する。 */
|
|
64
55
|
export const getDeploymentBranchPolicies = async (
|
|
65
56
|
environmentName: string,
|
|
@@ -83,6 +74,15 @@ export const getDeploymentBranchPolicies = async (
|
|
|
83
74
|
}));
|
|
84
75
|
};
|
|
85
76
|
|
|
77
|
+
/** 宣言ファイルに載る形。 `id` は GitHub 側の都合なので落とす。 */
|
|
78
|
+
const getDeploymentBranchPolicyNames = async (
|
|
79
|
+
environmentName: string,
|
|
80
|
+
): Promise<readonly Readonly<{ name: string; type: 'branch' | 'tag' }>[]> => {
|
|
81
|
+
const policies = await getDeploymentBranchPolicies(environmentName);
|
|
82
|
+
|
|
83
|
+
return policies.map(({ name, type }) => ({ name, type }));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
86
|
export type DeploymentBranchPolicy = Readonly<{
|
|
87
87
|
id: number;
|
|
88
88
|
name: string;
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import type { Dirent } from 'node:fs';
|
|
2
1
|
import * as fs from 'node:fs/promises';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
2
|
import * as t from 'ts-fortress';
|
|
5
3
|
import { isDirectlyExecuted, Result } from 'ts-repo-utils';
|
|
6
4
|
import { environmentsDir } from '../constants.mjs';
|
|
5
|
+
import { listJsonFilesIn } from '../list-json-files.mjs';
|
|
7
6
|
import { EnvironmentSettings } from './constants.mjs';
|
|
8
7
|
|
|
9
8
|
export const readEnvironmentFiles = async (): Promise<
|
|
10
9
|
readonly EnvironmentSettings[]
|
|
11
|
-
> =>
|
|
10
|
+
> => readEnvironmentFilesIn(environmentsDir);
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
/**
|
|
13
|
+
* `dir` の直下の宣言(`*.json`)を読んで検証する。テストが一時ディレクトリを
|
|
14
|
+
* 渡せるように、ディレクトリを引数に取る。
|
|
15
|
+
*/
|
|
16
|
+
export const readEnvironmentFilesIn = async (
|
|
14
17
|
dir: string,
|
|
15
18
|
): Promise<readonly EnvironmentSettings[]> => {
|
|
16
|
-
|
|
17
|
-
const files: readonly Dirent<string>[] = await fs.readdir(dir, {
|
|
18
|
-
withFileTypes: true,
|
|
19
|
-
});
|
|
19
|
+
const files = await listJsonFilesIn(dir);
|
|
20
20
|
|
|
21
21
|
const fileContents: readonly string[] = await Promise.all(
|
|
22
|
-
files
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
fs.readFile(path.resolve(dir, d.name), { encoding: 'utf8' }),
|
|
27
|
-
),
|
|
22
|
+
files.map((file) =>
|
|
23
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
24
|
+
fs.readFile(file, { encoding: 'utf8' }),
|
|
25
|
+
),
|
|
28
26
|
);
|
|
29
27
|
|
|
30
28
|
const validationResults = fileContents.map((content) =>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { readEnvironmentFilesIn } from './read-environment-contents.mjs';
|
|
5
|
+
|
|
6
|
+
// This repository's own declarations, as a known-valid fixture.
|
|
7
|
+
const environmentsDir = path.resolve(
|
|
8
|
+
import.meta.dirname,
|
|
9
|
+
'../../../../../repo-settings/environments',
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
describe(readEnvironmentFilesIn, () => {
|
|
13
|
+
test('reads the declarations and ignores a README beside them', async () => {
|
|
14
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'read-environments-'));
|
|
15
|
+
|
|
16
|
+
const declarations = await fs
|
|
17
|
+
.readdir(environmentsDir)
|
|
18
|
+
.then((names) => names.filter((n) => n.endsWith('.json')));
|
|
19
|
+
|
|
20
|
+
for (const name of declarations) {
|
|
21
|
+
await fs.copyFile(path.join(environmentsDir, name), path.join(dir, name));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
25
|
+
await fs.writeFile(path.join(dir, 'README.md'), '# notes');
|
|
26
|
+
|
|
27
|
+
const values = await readEnvironmentFilesIn(dir);
|
|
28
|
+
|
|
29
|
+
expect(values).toHaveLength(declarations.length);
|
|
30
|
+
});
|
|
31
|
+
});
|
package/src/github/index.mts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './actions-settings/index.mjs';
|
|
|
2
2
|
export * from './clear-json-files.mjs';
|
|
3
3
|
export * from './constants.mjs';
|
|
4
4
|
export * from './environments/index.mjs';
|
|
5
|
+
export * from './list-json-files.mjs';
|
|
5
6
|
export * from './pages/index.mjs';
|
|
6
7
|
export * from './repository/index.mjs';
|
|
7
8
|
export * from './resolve-target-repo.mjs';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `dir` の直下にある `*.json` の絶対パス。宣言のディレクトリを読むところと
|
|
6
|
+
* 消すところは、どちらもこれで宣言のファイルを選ぶ。
|
|
7
|
+
*
|
|
8
|
+
* 拡張子で絞るのは、宣言の隣に置く README(`repo-settings/variables/README.md`
|
|
9
|
+
* のような、JSON でない同居ファイル)を宣言として読んだり消したりしないため。
|
|
10
|
+
* 読む側が絞らないと、README を置いただけで `JSON.parse` が投げ、apply が何も
|
|
11
|
+
* 送らずに止まる。
|
|
12
|
+
*/
|
|
13
|
+
export const listJsonFilesIn = async (
|
|
14
|
+
dir: string,
|
|
15
|
+
): Promise<readonly string[]> => {
|
|
16
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
17
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
18
|
+
|
|
19
|
+
return entries
|
|
20
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith('.json'))
|
|
21
|
+
.map((entry) => path.resolve(dir, entry.name));
|
|
22
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { listJsonFilesIn } from './list-json-files.mjs';
|
|
5
|
+
|
|
6
|
+
const makeDir = async (): Promise<string> =>
|
|
7
|
+
fs.mkdtemp(path.join(os.tmpdir(), 'list-json-files-'));
|
|
8
|
+
|
|
9
|
+
/** 途中のディレクトリごと作って書く。入れ子の fixture もこれで用意する。 */
|
|
10
|
+
const write = async (filePath: string, content: string): Promise<void> => {
|
|
11
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
12
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
15
|
+
await fs.writeFile(filePath, content);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe(listJsonFilesIn, () => {
|
|
19
|
+
test('lists the json files directly under the directory, and nothing beside them', async () => {
|
|
20
|
+
const dir = await makeDir();
|
|
21
|
+
|
|
22
|
+
await write(path.join(dir, 'main.json'), '{}');
|
|
23
|
+
|
|
24
|
+
await write(path.join(dir, 'release.json'), '{}');
|
|
25
|
+
|
|
26
|
+
await write(path.join(dir, 'README.md'), '# notes');
|
|
27
|
+
|
|
28
|
+
await write(path.join(dir, 'nested', 'deep.json'), '{}');
|
|
29
|
+
|
|
30
|
+
const files = await listJsonFilesIn(dir);
|
|
31
|
+
|
|
32
|
+
assert.deepStrictEqual(files.toSorted(), [
|
|
33
|
+
path.join(dir, 'main.json'),
|
|
34
|
+
path.join(dir, 'release.json'),
|
|
35
|
+
]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('is empty for a directory holding no json', async () => {
|
|
39
|
+
const dir = await makeDir();
|
|
40
|
+
|
|
41
|
+
await write(path.join(dir, 'README.md'), '# notes');
|
|
42
|
+
|
|
43
|
+
assert.deepStrictEqual(await listJsonFilesIn(dir), []);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -10,6 +10,53 @@ export type TargetRepo = Readonly<{
|
|
|
10
10
|
repo: string;
|
|
11
11
|
}>;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 操作対象の repository を決める。
|
|
15
|
+
*
|
|
16
|
+
* 優先順位は以下の通り。
|
|
17
|
+
*
|
|
18
|
+
* 1. コマンドライン引数 `--owner` / `--repo`
|
|
19
|
+
* 2. 環境変数 `OWNER` / `REPO_NAME`
|
|
20
|
+
* 3. `git remote get-url origin`
|
|
21
|
+
* 4. `package.json` の `name` ( repo のみ )
|
|
22
|
+
*/
|
|
23
|
+
export const resolveTargetRepo = async (): Promise<TargetRepo> => {
|
|
24
|
+
const sources: readonly Partial<TargetRepo>[] = [
|
|
25
|
+
fromCliArgs(),
|
|
26
|
+
fromEnv(),
|
|
27
|
+
fromGitRemote(),
|
|
28
|
+
await fromPackageJson(),
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
const owner = sources.map((s) => s.owner).find((v) => v !== undefined);
|
|
32
|
+
|
|
33
|
+
if (owner === undefined) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
[
|
|
36
|
+
'owner を特定できませんでした。次のいずれかで指定してください:',
|
|
37
|
+
' --owner <owner> (コマンドライン引数)',
|
|
38
|
+
' OWNER=<owner> (環境変数)',
|
|
39
|
+
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
40
|
+
].join('\n'),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const repo = sources.map((s) => s.repo).find((v) => v !== undefined);
|
|
45
|
+
|
|
46
|
+
if (repo === undefined) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
[
|
|
49
|
+
'repository 名を特定できませんでした。次のいずれかで指定してください:',
|
|
50
|
+
' --repo <repo> (コマンドライン引数)',
|
|
51
|
+
' REPO_NAME=<repo> (環境変数)',
|
|
52
|
+
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
53
|
+
].join('\n'),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return { owner, repo };
|
|
58
|
+
};
|
|
59
|
+
|
|
13
60
|
/** `strict: false` の解析結果は string | boolean | 配列 になりうるため絞り込む。 */
|
|
14
61
|
const pickString = (value: unknown): string | undefined =>
|
|
15
62
|
value !== '' && isString(value) ? value : undefined;
|
|
@@ -95,50 +142,3 @@ const fromPackageJson = async (): Promise<Partial<TargetRepo>> => {
|
|
|
95
142
|
return {};
|
|
96
143
|
}
|
|
97
144
|
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 操作対象の repository を決める。
|
|
101
|
-
*
|
|
102
|
-
* 優先順位は以下の通り。
|
|
103
|
-
*
|
|
104
|
-
* 1. コマンドライン引数 `--owner` / `--repo`
|
|
105
|
-
* 2. 環境変数 `OWNER` / `REPO_NAME`
|
|
106
|
-
* 3. `git remote get-url origin`
|
|
107
|
-
* 4. `package.json` の `name` ( repo のみ )
|
|
108
|
-
*/
|
|
109
|
-
export const resolveTargetRepo = async (): Promise<TargetRepo> => {
|
|
110
|
-
const sources: readonly Partial<TargetRepo>[] = [
|
|
111
|
-
fromCliArgs(),
|
|
112
|
-
fromEnv(),
|
|
113
|
-
fromGitRemote(),
|
|
114
|
-
await fromPackageJson(),
|
|
115
|
-
] as const;
|
|
116
|
-
|
|
117
|
-
const owner = sources.map((s) => s.owner).find((v) => v !== undefined);
|
|
118
|
-
|
|
119
|
-
if (owner === undefined) {
|
|
120
|
-
throw new Error(
|
|
121
|
-
[
|
|
122
|
-
'owner を特定できませんでした。次のいずれかで指定してください:',
|
|
123
|
-
' --owner <owner> (コマンドライン引数)',
|
|
124
|
-
' OWNER=<owner> (環境変数)',
|
|
125
|
-
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
126
|
-
].join('\n'),
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const repo = sources.map((s) => s.repo).find((v) => v !== undefined);
|
|
131
|
-
|
|
132
|
-
if (repo === undefined) {
|
|
133
|
-
throw new Error(
|
|
134
|
-
[
|
|
135
|
-
'repository 名を特定できませんでした。次のいずれかで指定してください:',
|
|
136
|
-
' --repo <repo> (コマンドライン引数)',
|
|
137
|
-
' REPO_NAME=<repo> (環境変数)',
|
|
138
|
-
' git remote add origin <URL> ( origin の URL から推測されます)',
|
|
139
|
-
].join('\n'),
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return { owner, repo };
|
|
144
|
-
};
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import type { Dirent } from 'node:fs';
|
|
2
1
|
import * as fs from 'node:fs/promises';
|
|
3
|
-
import * as path from 'node:path';
|
|
4
2
|
import * as t from 'ts-fortress';
|
|
5
3
|
import { isDirectlyExecuted, Result } from 'ts-repo-utils';
|
|
6
4
|
import { rulesetsDir } from '../constants.mjs';
|
|
5
|
+
import { listJsonFilesIn } from '../list-json-files.mjs';
|
|
7
6
|
import { RulesetPicked } from './constants.mjs';
|
|
8
7
|
|
|
9
8
|
export const readRulesetFiles = async (): Promise<readonly RulesetPicked[]> =>
|
|
10
|
-
|
|
9
|
+
readRulesetFilesIn(rulesetsDir);
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
/**
|
|
12
|
+
* `dir` の直下の宣言(`*.json`)を読んで検証する。テストが一時ディレクトリを
|
|
13
|
+
* 渡せるように、ディレクトリを引数に取る。
|
|
14
|
+
*/
|
|
15
|
+
export const readRulesetFilesIn = async (
|
|
16
|
+
dir: string,
|
|
17
|
+
): Promise<readonly RulesetPicked[]> => {
|
|
18
|
+
const files = await listJsonFilesIn(dir);
|
|
17
19
|
|
|
18
20
|
const rulesetFileContents: readonly string[] = await Promise.all(
|
|
19
|
-
files
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
fs.readFile(path.resolve(dir, d.name), {
|
|
24
|
-
encoding: 'utf8',
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
21
|
+
files.map((file) =>
|
|
22
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
23
|
+
fs.readFile(file, { encoding: 'utf8' }),
|
|
24
|
+
),
|
|
27
25
|
);
|
|
28
26
|
|
|
29
27
|
const validationResults = rulesetFileContents.map((rule) =>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as os from 'node:os';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { readRulesetFilesIn } from './read-rule-set-contents.mjs';
|
|
5
|
+
|
|
6
|
+
// This repository's own declarations, as a known-valid fixture.
|
|
7
|
+
const rulesetsDir = path.resolve(
|
|
8
|
+
import.meta.dirname,
|
|
9
|
+
'../../../../../repo-settings/rulesets',
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
describe(readRulesetFilesIn, () => {
|
|
13
|
+
test('reads the declarations and ignores a README beside them', async () => {
|
|
14
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'read-rulesets-'));
|
|
15
|
+
|
|
16
|
+
const declarations = await fs
|
|
17
|
+
.readdir(rulesetsDir)
|
|
18
|
+
.then((names) => names.filter((n) => n.endsWith('.json')));
|
|
19
|
+
|
|
20
|
+
for (const name of declarations) {
|
|
21
|
+
await fs.copyFile(path.join(rulesetsDir, name), path.join(dir, name));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
25
|
+
await fs.writeFile(path.join(dir, 'README.md'), '# notes');
|
|
26
|
+
|
|
27
|
+
const values = await readRulesetFilesIn(dir);
|
|
28
|
+
|
|
29
|
+
expect(values).toHaveLength(declarations.length);
|
|
30
|
+
});
|
|
31
|
+
});
|