github-settings-as-code 4.0.4 → 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.
Files changed (53) hide show
  1. package/dist/github/actions-settings/constants.d.mts +14 -0
  2. package/dist/github/actions-settings/constants.d.mts.map +1 -1
  3. package/dist/github/clear-json-files.d.mts.map +1 -1
  4. package/dist/github/clear-json-files.mjs +3 -7
  5. package/dist/github/clear-json-files.mjs.map +1 -1
  6. package/dist/github/environments/api/get-environments.d.mts.map +1 -1
  7. package/dist/github/environments/api/get-environments.mjs +5 -5
  8. package/dist/github/environments/api/get-environments.mjs.map +1 -1
  9. package/dist/github/environments/constants.d.mts +10 -0
  10. package/dist/github/environments/constants.d.mts.map +1 -1
  11. package/dist/github/environments/read-environment-contents.d.mts +5 -0
  12. package/dist/github/environments/read-environment-contents.d.mts.map +1 -1
  13. package/dist/github/environments/read-environment-contents.mjs +9 -10
  14. package/dist/github/environments/read-environment-contents.mjs.map +1 -1
  15. package/dist/github/index.d.mts +1 -0
  16. package/dist/github/index.d.mts.map +1 -1
  17. package/dist/github/index.mjs +1 -0
  18. package/dist/github/index.mjs.map +1 -1
  19. package/dist/github/list-json-files.d.mts +11 -0
  20. package/dist/github/list-json-files.d.mts.map +1 -0
  21. package/dist/github/list-json-files.mjs +19 -0
  22. package/dist/github/list-json-files.mjs.map +1 -0
  23. package/dist/github/pages/constants.d.mts +4 -0
  24. package/dist/github/pages/constants.d.mts.map +1 -1
  25. package/dist/github/repository/constants.d.mts +2 -0
  26. package/dist/github/repository/constants.d.mts.map +1 -1
  27. package/dist/github/resolve-target-repo.d.mts.map +1 -1
  28. package/dist/github/resolve-target-repo.mjs +37 -37
  29. package/dist/github/resolve-target-repo.mjs.map +1 -1
  30. package/dist/github/ruleset/constants.d.mts +2 -0
  31. package/dist/github/ruleset/constants.d.mts.map +1 -1
  32. package/dist/github/ruleset/read-rule-set-contents.d.mts +5 -0
  33. package/dist/github/ruleset/read-rule-set-contents.d.mts.map +1 -1
  34. package/dist/github/ruleset/read-rule-set-contents.mjs +9 -12
  35. package/dist/github/ruleset/read-rule-set-contents.mjs.map +1 -1
  36. package/dist/github/variables/constants.d.mts +2 -0
  37. package/dist/github/variables/constants.d.mts.map +1 -1
  38. package/dist/github/vulnerability-alerts/constants.d.mts +4 -0
  39. package/dist/github/vulnerability-alerts/constants.d.mts.map +1 -1
  40. package/package.json +24 -24
  41. package/src/github/clear-json-files.mts +3 -8
  42. package/src/github/environments/api/get-environments.mts +9 -9
  43. package/src/github/environments/read-environment-contents.mts +12 -14
  44. package/src/github/environments/read-environment-contents.test.mts +31 -0
  45. package/src/github/index.mts +1 -0
  46. package/src/github/list-json-files.mts +22 -0
  47. package/src/github/list-json-files.test.mts +45 -0
  48. package/src/github/resolve-target-repo.mts +47 -47
  49. package/src/github/ruleset/read-rule-set-contents.mts +14 -16
  50. package/src/github/ruleset/read-rule-set-contents.test.mts +31 -0
  51. package/src/github/ruleset/schema.test.mts +2 -2
  52. package/src/github/settings-file-path.test.mts +11 -14
  53. package/src/github/variables/constants.test.mts +8 -8
@@ -46,6 +46,8 @@ export declare const VulnerabilityAlertsSettings: Readonly<{
46
46
  typeName: string;
47
47
  details?: t.ValidationErrorDetails | undefined;
48
48
  }>[]>;
49
+ structure?: t.TypeStructure;
50
+ annotations?: t.TypeAnnotations;
49
51
  optional?: true;
50
52
  }> & Readonly<{
51
53
  shape: {
@@ -64,6 +66,8 @@ export declare const VulnerabilityAlertsSettings: Readonly<{
64
66
  typeName: string;
65
67
  details?: t.ValidationErrorDetails | undefined;
66
68
  }>[]>;
69
+ structure?: t.TypeStructure;
70
+ annotations?: t.TypeAnnotations;
67
71
  optional?: true;
68
72
  }>;
69
73
  };
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/github/vulnerability-alerts/constants.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEtC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAChD,OAAO,2BAA2B,CACnC,CAAC"}
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/github/vulnerability-alerts/constants.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEtC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,MAAM,CAChD,OAAO,2BAA2B,CACnC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-settings-as-code",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "github",
@@ -27,39 +27,39 @@
27
27
  "dependencies": {
28
28
  "@octokit/core": "^7.0.8",
29
29
  "dedent": "^1.7.2",
30
- "dotenv": "^18.0.6",
30
+ "dotenv": "^18.0.8",
31
31
  "octokit-safe-types": "^1.2.28",
32
- "ts-data-forge": "^14.7.1",
33
- "ts-fortress": "^12.2.0",
34
- "ts-repo-utils": "^10.7.1",
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": {
38
- "@types/node": "26.6.4",
39
- "@vitest/coverage-v8": "5.0.3",
40
- "@vitest/ui": "5.0.3",
41
- "cspell": "10.3.6",
42
- "eslint": "10.12.0",
43
- "eslint-config-typed": "5.17.3",
44
- "eslint-plugin-ts-data-forge": "0.8.5",
45
- "eslint-plugin-ts-fortress": "1.3.2",
46
- "eslint-plugin-ts-type-forge": "0.8.7",
38
+ "@types/node": "26.6.5",
39
+ "@vitest/coverage-v8": "5.0.5",
40
+ "@vitest/ui": "5.0.5",
41
+ "cspell": "10.4.0",
42
+ "eslint": "10.13.0",
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.3",
49
- "prettier": "3.9.9",
48
+ "npm-run-all2": "9.0.4",
49
+ "prettier": "3.9.10",
50
50
  "prettier-plugin-organize-imports": "4.3.0",
51
51
  "prettier-plugin-packagejson": "3.0.2",
52
52
  "tsx": "4.23.15",
53
53
  "typescript": "6.0.3",
54
54
  "typescript-native": "npm:typescript@7.0.2",
55
- "vitest": "5.0.3"
55
+ "vitest": "5.0.5"
56
56
  },
57
57
  "engines": {
58
- "node": ">=22.22.2",
58
+ "node": ">=22.23.4",
59
59
  "pnpm": ">=9.0.0"
60
60
  },
61
61
  "volta": {
62
- "node": "26.11.1"
62
+ "node": "26.12.1"
63
63
  },
64
64
  "publishConfig": {
65
65
  "access": "public",
@@ -69,10 +69,10 @@
69
69
  "build": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/build.mts",
70
70
  "check:cspell": "cspell \"**\" --gitignore --gitignore-root ../../ --no-progress",
71
71
  "check:ext": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/check-ext.mts",
72
- "check:lint": "oxlint . && eslint .",
73
- "check:test": "pnpm run z:vitest:node run",
74
- "check:test:cov": "pnpm run z:vitest:node run --coverage",
75
- "check:types": "node ../../node_modules/typescript-native/bin/tsc --noEmit",
72
+ "check:lint": "node ../../tools/scripts/cmd/assert-deps-built.mts && oxlint . && eslint .",
73
+ "check:test": "node ../../tools/scripts/cmd/assert-deps-built.mts && pnpm run z:vitest:node run",
74
+ "check:test:cov": "node ../../tools/scripts/cmd/assert-deps-built.mts && pnpm run z:vitest:node run --coverage",
75
+ "check:types": "node ../../tools/scripts/cmd/assert-deps-built.mts && node ../../node_modules/typescript-native/bin/tsc --noEmit",
76
76
  "check-all": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/check-all.mts",
77
77
  "doc": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ./scripts/cmd/gen-docs.mts",
78
78
  "fix:codemod": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-codemod-cli/src/cmd/ts-codemod.mts --uncommitted --transformer append-as-const --transformer convert-to-readonly '{src,scripts,samples}/**/*.mts' && pnpm run fix:fmt",
@@ -81,7 +81,7 @@
81
81
  "fix:fmt": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-repo-utils/src/cmd/format-uncommitted.mts --cwd .",
82
82
  "fix:fmt:diff": "tsx --tsconfig ../../tools/configs/tsconfig.tsx.json ../../libs/ts-repo-utils/src/cmd/format-diff-from.mts origin/main --cwd .",
83
83
  "fix:fmt:full": "prettier --write .",
84
- "fix:lint": "oxlint . --fix && eslint . --fix",
84
+ "fix:lint": "node ../../tools/scripts/cmd/assert-deps-built.mts && oxlint . --fix && eslint . --fix",
85
85
  "fmt": "pnpm run fix:fmt",
86
86
  "gen": "run-s gen:index",
87
87
  "gen:index": "run-s gen:index:src fix:fmt",
@@ -1,5 +1,5 @@
1
1
  import * as fs from 'node:fs/promises';
2
- import * as path from 'node:path';
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
- // eslint-disable-next-line security/detect-non-literal-fs-filename
24
- const entries = await fs.readdir(dir, { withFileTypes: true });
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
- > => readFilesIn(environmentsDir);
10
+ > => readEnvironmentFilesIn(environmentsDir);
12
11
 
13
- const readFilesIn = async (
12
+ /**
13
+ * `dir` の直下の宣言(`*.json`)を読んで検証する。テストが一時ディレクトリを
14
+ * 渡せるように、ディレクトリを引数に取る。
15
+ */
16
+ export const readEnvironmentFilesIn = async (
14
17
  dir: string,
15
18
  ): Promise<readonly EnvironmentSettings[]> => {
16
- // eslint-disable-next-line security/detect-non-literal-fs-filename
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
- .filter((d) => d.isFile())
24
- .map((d) =>
25
- // eslint-disable-next-line security/detect-non-literal-fs-filename
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
+ });
@@ -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
- readFilesIn(rulesetsDir);
9
+ readRulesetFilesIn(rulesetsDir);
11
10
 
12
- const readFilesIn = async (dir: string): Promise<readonly RulesetPicked[]> => {
13
- // eslint-disable-next-line security/detect-non-literal-fs-filename
14
- const files: readonly Dirent<string>[] = await fs.readdir(dir, {
15
- withFileTypes: true,
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
- .filter((d) => d.isFile())
21
- .map((d) =>
22
- // eslint-disable-next-line security/detect-non-literal-fs-filename
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
+ });
@@ -70,7 +70,7 @@ describe('the ruleset schema', () => {
70
70
  assert.isTrue(Arr.isNonEmpty(files));
71
71
 
72
72
  for (const [name, content] of files) {
73
- assert.deepStrictEqual(
73
+ assert.strictEqual(
74
74
  outcomeOf(name, RulesetPicked.validate(content)),
75
75
  name,
76
76
  );
@@ -84,7 +84,7 @@ describe('the ruleset schema', () => {
84
84
 
85
85
  const declared = RulesetPicked.validate(files[0][1]);
86
86
 
87
- assert.deepStrictEqual(outcomeOf(files[0][0], declared), files[0][0]);
87
+ assert.strictEqual(outcomeOf(files[0][0], declared), files[0][0]);
88
88
 
89
89
  if (Result.isErr(declared)) {
90
90
  return;
@@ -13,47 +13,44 @@ const outcomeOf = (name: string): string => {
13
13
 
14
14
  describe(settingsFilePath, () => {
15
15
  test('names a file directly under the directory it was given', () => {
16
- assert.deepStrictEqual(
16
+ assert.strictEqual(
17
17
  settingsFilePath(dir, 'release'),
18
18
  path.join(dir, 'release.json'),
19
19
  );
20
20
  });
21
21
 
22
22
  test('keeps the characters a name is allowed to carry', () => {
23
- assert.deepStrictEqual(
23
+ assert.strictEqual(
24
24
  settingsFilePath(dir, 'main-no-bypass'),
25
25
  path.join(dir, 'main-no-bypass.json'),
26
26
  );
27
27
 
28
- assert.deepStrictEqual(
28
+ assert.strictEqual(
29
29
  settingsFilePath(dir, 'Production (US East)'),
30
30
  path.join(dir, 'Production (US East).json'),
31
31
  );
32
32
  });
33
33
 
34
34
  test('rejects a name that would resolve above the directory', () => {
35
- assert.deepStrictEqual(outcomeOf('../release'), 'rejected');
35
+ assert.strictEqual(outcomeOf('../release'), 'rejected');
36
36
 
37
- assert.deepStrictEqual(outcomeOf('../../../../tmp/elsewhere'), 'rejected');
37
+ assert.strictEqual(outcomeOf('../../../../tmp/elsewhere'), 'rejected');
38
38
  });
39
39
 
40
40
  test('rejects a name carrying a separator, rather than nesting it', () => {
41
- assert.deepStrictEqual(outcomeOf('production/us-east'), 'rejected');
41
+ assert.strictEqual(outcomeOf('production/us-east'), 'rejected');
42
42
 
43
- assert.deepStrictEqual(
44
- outcomeOf(String.raw`production\us-east`),
45
- 'rejected',
46
- );
43
+ assert.strictEqual(outcomeOf(String.raw`production\us-east`), 'rejected');
47
44
  });
48
45
 
49
46
  test('rejects the names that are not file names at all', () => {
50
- assert.deepStrictEqual(outcomeOf(''), 'rejected');
47
+ assert.strictEqual(outcomeOf(''), 'rejected');
51
48
 
52
- assert.deepStrictEqual(outcomeOf('.'), 'rejected');
49
+ assert.strictEqual(outcomeOf('.'), 'rejected');
53
50
 
54
- assert.deepStrictEqual(outcomeOf('..'), 'rejected');
51
+ assert.strictEqual(outcomeOf('..'), 'rejected');
55
52
 
56
- assert.deepStrictEqual(outcomeOf('release\u{0}'), 'rejected');
53
+ assert.strictEqual(outcomeOf('release\u{0}'), 'rejected');
57
54
  });
58
55
 
59
56
  test('says which name it refused', () => {
@@ -55,7 +55,7 @@ describe('the repository-variables schema', () => {
55
55
 
56
56
  describe(assertVariableNamesAreValid, () => {
57
57
  test('accepts the names GitHub accepts', () => {
58
- assert.deepStrictEqual(
58
+ assert.strictEqual(
59
59
  outcomeOf({
60
60
  REPO_AUTOMATION_BOT_CLIENT_ID: 'x',
61
61
  lowercase_is_allowed: 'x',
@@ -67,25 +67,25 @@ describe(assertVariableNamesAreValid, () => {
67
67
  });
68
68
 
69
69
  test('rejects a name starting with a digit', () => {
70
- assert.deepStrictEqual(outcomeOf({ '1ST_PLACE': 'x' }), 'rejected');
70
+ assert.strictEqual(outcomeOf({ '1ST_PLACE': 'x' }), 'rejected');
71
71
  });
72
72
 
73
73
  test('rejects a name carrying a character GitHub does not allow', () => {
74
- assert.deepStrictEqual(outcomeOf({ 'WITH-HYPHEN': 'x' }), 'rejected');
74
+ assert.strictEqual(outcomeOf({ 'WITH-HYPHEN': 'x' }), 'rejected');
75
75
 
76
- assert.deepStrictEqual(outcomeOf({ 'WITH SPACE': 'x' }), 'rejected');
76
+ assert.strictEqual(outcomeOf({ 'WITH SPACE': 'x' }), 'rejected');
77
77
 
78
- assert.deepStrictEqual(outcomeOf({ 'WITH.DOT': 'x' }), 'rejected');
78
+ assert.strictEqual(outcomeOf({ 'WITH.DOT': 'x' }), 'rejected');
79
79
  });
80
80
 
81
81
  test('rejects the reserved GITHUB_ prefix, in any case', () => {
82
- assert.deepStrictEqual(outcomeOf({ GITHUB_TOKEN: 'x' }), 'rejected');
82
+ assert.strictEqual(outcomeOf({ GITHUB_TOKEN: 'x' }), 'rejected');
83
83
 
84
- assert.deepStrictEqual(outcomeOf({ github_token: 'x' }), 'rejected');
84
+ assert.strictEqual(outcomeOf({ github_token: 'x' }), 'rejected');
85
85
  });
86
86
 
87
87
  test('rejects an empty name', () => {
88
- assert.deepStrictEqual(outcomeOf({ '': 'x' }), 'rejected');
88
+ assert.strictEqual(outcomeOf({ '': 'x' }), 'rejected');
89
89
  });
90
90
 
91
91
  test('names every offender, so one run fixes the file', () => {