github-settings-as-code 1.2.10 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -9
- package/dist/cmd/{gh-apply-all.d.mts → repo-settings.d.mts} +1 -1
- package/dist/cmd/repo-settings.d.mts.map +1 -0
- package/dist/cmd/repo-settings.mjs +118 -0
- package/dist/cmd/repo-settings.mjs.map +1 -0
- package/dist/github/actions-settings/api/get-actions-settings.d.mts +8 -0
- package/dist/github/actions-settings/api/get-actions-settings.d.mts.map +1 -0
- package/dist/github/actions-settings/api/get-actions-settings.mjs +25 -0
- package/dist/github/actions-settings/api/get-actions-settings.mjs.map +1 -0
- package/dist/github/actions-settings/api/index.d.mts +3 -0
- package/dist/github/actions-settings/api/index.d.mts.map +1 -0
- package/dist/github/actions-settings/api/index.mjs +3 -0
- package/dist/github/actions-settings/api/index.mjs.map +1 -0
- package/dist/github/actions-settings/api/set-actions-settings.d.mts +4 -0
- package/dist/github/actions-settings/api/set-actions-settings.d.mts.map +1 -0
- package/dist/github/actions-settings/api/set-actions-settings.mjs +27 -0
- package/dist/github/actions-settings/api/set-actions-settings.mjs.map +1 -0
- package/dist/github/actions-settings/apply.d.mts +5 -0
- package/dist/github/actions-settings/apply.d.mts.map +1 -0
- package/dist/github/actions-settings/apply.mjs +39 -0
- package/dist/github/actions-settings/apply.mjs.map +1 -0
- package/dist/github/actions-settings/backup.d.mts +5 -0
- package/dist/github/actions-settings/backup.d.mts.map +1 -0
- package/dist/github/actions-settings/backup.mjs +22 -0
- package/dist/github/actions-settings/backup.mjs.map +1 -0
- package/dist/github/actions-settings/constants.d.mts +69 -0
- package/dist/github/actions-settings/constants.d.mts.map +1 -0
- package/dist/github/actions-settings/constants.mjs +42 -0
- package/dist/github/actions-settings/constants.mjs.map +1 -0
- package/dist/github/actions-settings/index.d.mts +5 -0
- package/dist/github/actions-settings/index.d.mts.map +1 -0
- package/dist/github/actions-settings/index.mjs +5 -0
- package/dist/github/actions-settings/index.mjs.map +1 -0
- package/dist/github/constants.d.mts +3 -1
- package/dist/github/constants.d.mts.map +1 -1
- package/dist/github/constants.mjs +7 -31
- package/dist/github/constants.mjs.map +1 -1
- package/dist/github/index.d.mts +4 -0
- package/dist/github/index.d.mts.map +1 -1
- package/dist/github/index.mjs +4 -0
- package/dist/github/index.mjs.map +1 -1
- package/dist/github/octokit.d.mts.map +1 -1
- package/dist/github/octokit.mjs +39 -3
- package/dist/github/octokit.mjs.map +1 -1
- package/dist/github/pages/api/get-pages-settings.d.mts +8 -0
- package/dist/github/pages/api/get-pages-settings.d.mts.map +1 -0
- package/dist/github/pages/api/get-pages-settings.mjs +26 -0
- package/dist/github/pages/api/get-pages-settings.mjs.map +1 -0
- package/dist/github/pages/api/index.d.mts +3 -0
- package/dist/github/pages/api/index.d.mts.map +1 -0
- package/dist/github/pages/api/index.mjs +3 -0
- package/dist/github/pages/api/index.mjs.map +1 -0
- package/dist/github/pages/api/set-pages-settings.d.mts +9 -0
- package/dist/github/pages/api/set-pages-settings.d.mts.map +1 -0
- package/dist/github/pages/api/set-pages-settings.mjs +33 -0
- package/dist/github/pages/api/set-pages-settings.mjs.map +1 -0
- package/dist/github/pages/apply.d.mts +10 -0
- package/dist/github/pages/apply.d.mts.map +1 -0
- package/dist/github/pages/apply.mjs +49 -0
- package/dist/github/pages/apply.mjs.map +1 -0
- package/dist/github/pages/backup.d.mts +5 -0
- package/dist/github/pages/backup.d.mts.map +1 -0
- package/dist/github/pages/backup.mjs +26 -0
- package/dist/github/pages/backup.mjs.map +1 -0
- package/dist/github/pages/constants.d.mts +42 -0
- package/dist/github/pages/constants.d.mts.map +1 -0
- package/dist/github/pages/constants.mjs +14 -0
- package/dist/github/pages/constants.mjs.map +1 -0
- package/dist/github/pages/index.d.mts +5 -0
- package/dist/github/pages/index.d.mts.map +1 -0
- package/dist/github/pages/index.mjs +5 -0
- package/dist/github/pages/index.mjs.map +1 -0
- package/dist/github/repository/apply.d.mts.map +1 -1
- package/dist/github/repository/apply.mjs +4 -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 +2 -2
- package/dist/github/repository/backup.mjs.map +1 -1
- package/dist/github/repository/constants.d.mts +3259 -2024
- package/dist/github/repository/constants.d.mts.map +1 -1
- package/dist/github/repository/constants.mjs +2 -1
- package/dist/github/repository/constants.mjs.map +1 -1
- package/dist/github/resolve-target-repo.d.mts +16 -0
- package/dist/github/resolve-target-repo.d.mts.map +1 -0
- package/dist/github/resolve-target-repo.mjs +113 -0
- package/dist/github/resolve-target-repo.mjs.map +1 -0
- package/dist/github/ruleset/api/get-all-rulesets.d.mts.map +1 -1
- package/dist/github/ruleset/api/get-all-rulesets.mjs.map +1 -1
- package/dist/github/ruleset/constants.d.mts +750 -267
- package/dist/github/ruleset/constants.d.mts.map +1 -1
- package/dist/github/ruleset/constants.mjs +2 -1
- package/dist/github/ruleset/constants.mjs.map +1 -1
- package/dist/github/upgrade-stale-codec.d.mts +19 -0
- package/dist/github/upgrade-stale-codec.d.mts.map +1 -0
- package/dist/github/upgrade-stale-codec.mjs +20 -0
- package/dist/github/upgrade-stale-codec.mjs.map +1 -0
- package/dist/github/variables/apply.d.mts.map +1 -1
- package/dist/github/variables/apply.mjs +9 -6
- package/dist/github/variables/apply.mjs.map +1 -1
- package/package.json +41 -50
- package/src/cmd/repo-settings.mts +153 -0
- package/src/github/actions-settings/api/get-actions-settings.mts +38 -0
- package/src/github/actions-settings/api/index.mts +2 -0
- package/src/github/actions-settings/api/set-actions-settings.mts +39 -0
- package/src/github/actions-settings/apply.mts +63 -0
- package/src/github/actions-settings/backup.mts +36 -0
- package/src/github/actions-settings/constants.mts +50 -0
- package/src/github/actions-settings/index.mts +4 -0
- package/src/github/constants.mts +9 -42
- package/src/github/index.mts +4 -0
- package/src/github/octokit.mts +47 -3
- package/src/github/pages/api/get-pages-settings.mts +35 -0
- package/src/github/pages/api/index.mts +2 -0
- package/src/github/pages/api/set-pages-settings.mts +47 -0
- package/src/github/pages/apply.mts +73 -0
- package/src/github/pages/backup.mts +44 -0
- package/src/github/pages/constants.mts +16 -0
- package/src/github/pages/index.mts +4 -0
- package/src/github/repository/apply.mts +4 -7
- package/src/github/repository/backup.mts +2 -5
- package/src/github/repository/constants.mts +5 -1
- package/src/github/resolve-target-repo.mts +144 -0
- package/src/github/ruleset/api/get-all-rulesets.mts +3 -6
- package/src/github/ruleset/constants.mts +5 -1
- package/src/github/upgrade-stale-codec.mts +29 -0
- package/src/github/variables/apply.mts +9 -6
- package/dist/cmd/gh-apply-all.d.mts.map +0 -1
- package/dist/cmd/gh-apply-all.mjs +0 -10
- package/dist/cmd/gh-apply-all.mjs.map +0 -1
- package/dist/cmd/gh-backup-all.d.mts +0 -3
- package/dist/cmd/gh-backup-all.d.mts.map +0 -1
- package/dist/cmd/gh-backup-all.mjs +0 -9
- package/dist/cmd/gh-backup-all.mjs.map +0 -1
- package/src/cmd/gh-apply-all.mts +0 -18
- package/src/cmd/gh-backup-all.mts +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/github/ruleset/constants.mts"],"names":[],"mappings":"AAMA,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/github/ruleset/constants.mts"],"names":[],"mappings":"AAMA,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AAGjC,eAAO,MAAM,iBAAiB,0FAQ2B,CAAC;AAQ1D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGzB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { RepositoryRuleset, } from 'octokit-safe-types';
|
|
2
2
|
import { expectType } from 'ts-data-forge';
|
|
3
3
|
import * as t from 'ts-fortress';
|
|
4
|
+
import { upgradeStaleCodec } from '../upgrade-stale-codec.mjs';
|
|
4
5
|
export const rulesetKeysToPick = [
|
|
5
6
|
'id',
|
|
6
7
|
'name',
|
|
@@ -12,5 +13,5 @@ export const rulesetKeysToPick = [
|
|
|
12
13
|
];
|
|
13
14
|
expectType('=');
|
|
14
15
|
expectType('=');
|
|
15
|
-
export const RulesetPicked = t.pick(RepositoryRuleset, rulesetKeysToPick);
|
|
16
|
+
export const RulesetPicked = t.pick(upgradeStaleCodec(RepositoryRuleset), rulesetKeysToPick);
|
|
16
17
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/github/ruleset/constants.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/github/ruleset/constants.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,CAAC,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,aAAa;IACb,eAAe;IACf,YAAY;IACZ,OAAO;CACgD,CAAC;AAI1D,UAAU,CAAgD,GAAG,CAAC,CAAC;AAE/D,UAAU,CAAyD,GAAG,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CACjC,iBAAiB,CAAC,iBAAiB,CAAC,EACpC,iBAAiB,CAClB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Type } from 'ts-fortress';
|
|
2
|
+
import { type StrictOmit } from 'ts-type-forge';
|
|
3
|
+
/**
|
|
4
|
+
* Restores the full ts-fortress `Type` interface for codecs imported from
|
|
5
|
+
* octokit-safe-types@1.2.19, whose declaration files were generated against
|
|
6
|
+
* ts-fortress 7 (whose `Type` lacked the `prune` member). The pnpm override in
|
|
7
|
+
* `pnpm-workspace.yaml` resolves ts-fortress >= 11 at runtime, so the codec
|
|
8
|
+
* object itself does have `prune`; only its declared type is stale. This
|
|
9
|
+
* verifies `prune` exists at runtime and rebuilds the codec with the correct
|
|
10
|
+
* type, without unsafe type assertions.
|
|
11
|
+
*
|
|
12
|
+
* TODO: Remove this helper once octokit-safe-types is rebuilt against
|
|
13
|
+
* ts-fortress >= 11.
|
|
14
|
+
*/
|
|
15
|
+
export declare const upgradeStaleCodec: <A>(codec: Readonly<{
|
|
16
|
+
defaultValue: A;
|
|
17
|
+
prune?: Type<A>['prune'];
|
|
18
|
+
}> & StrictOmit<Type<A>, 'defaultValue' | 'prune'>) => Type<A>;
|
|
19
|
+
//# sourceMappingURL=upgrade-stale-codec.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade-stale-codec.d.mts","sourceRoot":"","sources":["../../src/github/upgrade-stale-codec.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAC1B,QAAQ,CAAC;IAAE,YAAY,EAAE,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC,GAC5D,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,KAC9C,IAAI,CAAC,CAAC,CAUR,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restores the full ts-fortress `Type` interface for codecs imported from
|
|
3
|
+
* octokit-safe-types@1.2.19, whose declaration files were generated against
|
|
4
|
+
* ts-fortress 7 (whose `Type` lacked the `prune` member). The pnpm override in
|
|
5
|
+
* `pnpm-workspace.yaml` resolves ts-fortress >= 11 at runtime, so the codec
|
|
6
|
+
* object itself does have `prune`; only its declared type is stale. This
|
|
7
|
+
* verifies `prune` exists at runtime and rebuilds the codec with the correct
|
|
8
|
+
* type, without unsafe type assertions.
|
|
9
|
+
*
|
|
10
|
+
* TODO: Remove this helper once octokit-safe-types is rebuilt against
|
|
11
|
+
* ts-fortress >= 11.
|
|
12
|
+
*/
|
|
13
|
+
export const upgradeStaleCodec = (codec) => {
|
|
14
|
+
const { prune } = codec;
|
|
15
|
+
if (prune === undefined) {
|
|
16
|
+
throw new Error(`The codec "${codec.typeName}" has no prune function at runtime. octokit-safe-types is probably resolving an old ts-fortress version; check the pnpm overrides.`);
|
|
17
|
+
}
|
|
18
|
+
return { ...codec, prune };
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=upgrade-stale-codec.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade-stale-codec.mjs","sourceRoot":"","sources":["../../src/github/upgrade-stale-codec.mts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,KAC+C,EACtC,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAExB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,cAAc,KAAK,CAAC,QAAQ,oIAAoI,CACjK,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.mts","sourceRoot":"","sources":["../../../src/github/variables/apply.mts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AAQvB,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"apply.d.mts","sourceRoot":"","sources":["../../../src/github/variables/apply.mts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AAQvB,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,IAAI,CA8BnD,CAAC"}
|
|
@@ -5,16 +5,19 @@ import { createRepoVariable, listRepoVariables, updateRepoVariable, } from './ap
|
|
|
5
5
|
export const applyVariables = async () => {
|
|
6
6
|
const variables = [
|
|
7
7
|
{
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// noshiro-semantic-release-bot (App ID: 1442563)
|
|
9
|
+
name: 'SEMANTIC_RELEASE_BOT_CLIENT_ID',
|
|
10
|
+
value: 'Iv23liAmv2bgTYTkv2pt',
|
|
10
11
|
},
|
|
11
12
|
{
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
// noshiro-changesets-release-bot (App ID: 1576218)
|
|
14
|
+
name: 'CHANGESETS_RELEASE_BOT_CLIENT_ID',
|
|
15
|
+
value: 'Iv23limuZKrTEcXmN0lp',
|
|
14
16
|
},
|
|
15
17
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
// noshiro-repo-settings-bot (App ID: 4476573)
|
|
19
|
+
name: 'REPO_SETTINGS_BOT_CLIENT_ID',
|
|
20
|
+
value: 'Iv23ctr4Lq9H3wOYRQrD',
|
|
18
21
|
},
|
|
19
22
|
];
|
|
20
23
|
const variableListSaved = await listRepoVariables();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.mjs","sourceRoot":"","sources":["../../../src/github/variables/apply.mts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAAmB,EAAE;IACtD,MAAM,SAAS,GAAG;QAChB;YACE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"apply.mjs","sourceRoot":"","sources":["../../../src/github/variables/apply.mts"],"names":[],"mappings":";AACA,OAAO,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAAmB,EAAE;IACtD,MAAM,SAAS,GAAG;QAChB;YACE,iDAAiD;YACjD,IAAI,EAAE,gCAAgC;YACtC,KAAK,EAAE,sBAAsB;SAC9B;QACD;YACE,mDAAmD;YACnD,IAAI,EAAE,kCAAkC;YACxC,KAAK,EAAE,sBAAsB;SAC9B;QACD;YACE,8CAA8C;YAC9C,IAAI,EAAE,6BAA6B;YACnC,KAAK,EAAE,sBAAsB;SAC9B;KACO,CAAC;IAEX,MAAM,iBAAiB,GAAG,MAAM,iBAAiB,EAAE,CAAC;IAEpD,MAAM,cAAc,GAAwB,IAAI,GAAG,CACjD,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CACrC,CAAC;IAEF,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEhD,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC,CAAC;AAEF,IAAI,kBAAkB,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACxC,MAAM,cAAc,EAAE,CAAC;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "github-settings-as-code",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"github",
|
|
@@ -15,13 +15,7 @@
|
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"type": "module",
|
|
17
17
|
"bin": {
|
|
18
|
-
"
|
|
19
|
-
"gh-apply-repository-settings": "./dist/github/repository/apply.mjs",
|
|
20
|
-
"gh-apply-rulesets": "./dist/github/ruleset/apply.mjs",
|
|
21
|
-
"gh-apply-variables": "./dist/github/variables/apply.mjs",
|
|
22
|
-
"gh-backup-all": "./dist/cmd/gh-backup-all.mjs",
|
|
23
|
-
"gh-backup-repository-settings": "./dist/github/repository/backup.mjs",
|
|
24
|
-
"gh-backup-rulesets": "./dist/github/ruleset/backup.mjs"
|
|
18
|
+
"repo-settings": "./dist/cmd/repo-settings.mjs"
|
|
25
19
|
},
|
|
26
20
|
"files": [
|
|
27
21
|
"src",
|
|
@@ -37,28 +31,26 @@
|
|
|
37
31
|
"check:ext": "tsx ./scripts/cmd/check-ext.mts",
|
|
38
32
|
"check-all": "tsx ./scripts/cmd/check-all.mts",
|
|
39
33
|
"codemod": "run-s codemod:uncommitted:as-const fmt codemod:uncommitted:readonly fmt",
|
|
34
|
+
"codemod:diff": "run-s codemod:diff:as-const fmt codemod:diff:readonly fmt",
|
|
35
|
+
"codemod:diff:as-const": "append-as-const --diff-from origin/main '{src,scripts,samples}/**/*.mts'",
|
|
36
|
+
"codemod:diff:readonly": "convert-to-readonly --diff-from origin/main '{src,scripts,samples}/**/*.mts'",
|
|
40
37
|
"codemod:full": "run-s codemod:full:as-const fmt codemod:full:readonly fmt",
|
|
41
|
-
"codemod:full:as-const": "append-as-const '{src,scripts,samples}/**/*.
|
|
42
|
-
"codemod:full:readonly": "convert-to-readonly '{src,scripts,samples}/**/*.
|
|
43
|
-
"codemod:uncommitted:as-const": "append-as-const --uncommitted '{src,scripts,samples}/**/*.
|
|
44
|
-
"codemod:uncommitted:readonly": "convert-to-readonly --uncommitted '{src,scripts,samples}/**/*.
|
|
45
|
-
"cspell": "cspell \"
|
|
38
|
+
"codemod:full:as-const": "append-as-const '{src,scripts,samples}/**/*.mts'",
|
|
39
|
+
"codemod:full:readonly": "convert-to-readonly '{src,scripts,samples}/**/*.mts'",
|
|
40
|
+
"codemod:uncommitted:as-const": "append-as-const --uncommitted '{src,scripts,samples}/**/*.mts'",
|
|
41
|
+
"codemod:uncommitted:readonly": "convert-to-readonly --uncommitted '{src,scripts,samples}/**/*.mts'",
|
|
42
|
+
"cspell": "cspell \"{**,.changeset/**/*,.github/**/*}\" --gitignore --gitignore-root ./ --no-progress",
|
|
46
43
|
"doc": "tsx ./scripts/cmd/gen-docs.mts",
|
|
47
44
|
"fmt": "format-uncommitted",
|
|
48
45
|
"fmt:diff": "format-diff-from origin/main",
|
|
49
46
|
"fmt:full": "prettier --write .",
|
|
50
|
-
"gh:apply-all": "tsx ./src/cmd/gh-apply-all.mts",
|
|
51
|
-
"gh:apply-repository-settings": "tsx ./src/github/repository/apply.mts",
|
|
52
|
-
"gh:apply-rulesets": "tsx ./src/github/ruleset/apply.mts",
|
|
53
|
-
"gh:apply-variables": "tsx ./src/github/variables/apply.mts",
|
|
54
|
-
"gh:backup-all": "tsx ./src/cmd/gh-backup-all.mts",
|
|
55
|
-
"gh:backup-repository-settings": "tsx ./src/github/repository/backup.mts",
|
|
56
|
-
"gh:backup-rulesets": "tsx ./src/github/ruleset/backup.mts",
|
|
57
47
|
"gi": "run-s gi:src fmt",
|
|
58
48
|
"gi:src": "gen-index-ts ./src/github --index-ext .mts --export-ext .mjs --target-ext .mts --exclude cmd --exclude octokit.mts",
|
|
59
49
|
"lint": "eslint .",
|
|
60
50
|
"lint:fix": "eslint . --fix",
|
|
61
51
|
"md": "markdownlint-cli2",
|
|
52
|
+
"repo-settings:apply": "tsx ./src/cmd/repo-settings.mts apply",
|
|
53
|
+
"repo-settings:backup": "tsx ./src/cmd/repo-settings.mts backup",
|
|
62
54
|
"test": "pnpm run z:vitest:node run",
|
|
63
55
|
"test:cov": "pnpm run z:vitest:node run --coverage",
|
|
64
56
|
"test:cov:ui": "vite preview --outDir ./coverage",
|
|
@@ -67,52 +59,51 @@
|
|
|
67
59
|
"tsc": "node ./node_modules/typescript-native/bin/tsc --noEmit",
|
|
68
60
|
"tscw": "node ./node_modules/typescript-native/bin/tsc --noEmit --watch -p ./tsconfig.json",
|
|
69
61
|
"type-check": "node ./node_modules/typescript-native/bin/tsc --noEmit",
|
|
70
|
-
"update-packages": "pnpm update --latest",
|
|
71
62
|
"z:vitest": "vitest --config ./configs/vitest.config.mts",
|
|
72
63
|
"z:vitest:node": "pnpm run z:vitest --project='Node.js'"
|
|
73
64
|
},
|
|
74
65
|
"dependencies": {
|
|
75
66
|
"@octokit/core": "^7.0.6",
|
|
76
67
|
"dotenv": "^17.4.2",
|
|
77
|
-
"octokit-safe-types": "^1.2.
|
|
78
|
-
"ts-data-forge": "^
|
|
79
|
-
"ts-fortress": "^
|
|
80
|
-
"ts-type-forge": "^
|
|
68
|
+
"octokit-safe-types": "^1.2.19",
|
|
69
|
+
"ts-data-forge": "^12.2.2",
|
|
70
|
+
"ts-fortress": "^11.2.0",
|
|
71
|
+
"ts-type-forge": "^9.1.1"
|
|
81
72
|
},
|
|
82
73
|
"devDependencies": {
|
|
83
|
-
"@semantic-release/changelog": "
|
|
74
|
+
"@semantic-release/changelog": "7.0.0",
|
|
84
75
|
"@semantic-release/commit-analyzer": "13.0.1",
|
|
85
76
|
"@semantic-release/exec": "7.1.0",
|
|
86
|
-
"@semantic-release/git": "
|
|
87
|
-
"@semantic-release/github": "12.0.
|
|
77
|
+
"@semantic-release/git": "11.0.1",
|
|
78
|
+
"@semantic-release/github": "12.0.9",
|
|
88
79
|
"@semantic-release/npm": "13.1.5",
|
|
89
|
-
"@semantic-release/release-notes-generator": "14.1.
|
|
90
|
-
"@types/node": "
|
|
91
|
-
"@vitest/coverage-v8": "4.1.
|
|
92
|
-
"@vitest/ui": "4.1.
|
|
93
|
-
"conventional-changelog-conventionalcommits": "
|
|
94
|
-
"cspell": "10.0.
|
|
95
|
-
"eslint": "10.
|
|
96
|
-
"eslint-config-typed": "
|
|
97
|
-
"jiti": "2.
|
|
98
|
-
"markdownlint": "0.
|
|
99
|
-
"markdownlint-cli2": "0.
|
|
100
|
-
"npm-run-all2": "
|
|
101
|
-
"playwright": "1.
|
|
102
|
-
"prettier": "3.
|
|
80
|
+
"@semantic-release/release-notes-generator": "14.1.1",
|
|
81
|
+
"@types/node": "26.1.2",
|
|
82
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
83
|
+
"@vitest/ui": "4.1.10",
|
|
84
|
+
"conventional-changelog-conventionalcommits": "10.2.1",
|
|
85
|
+
"cspell": "10.0.1",
|
|
86
|
+
"eslint": "10.8.0",
|
|
87
|
+
"eslint-config-typed": "5.8.2",
|
|
88
|
+
"jiti": "2.7.0",
|
|
89
|
+
"markdownlint": "0.41.1",
|
|
90
|
+
"markdownlint-cli2": "0.23.2",
|
|
91
|
+
"npm-run-all2": "9.0.2",
|
|
92
|
+
"playwright": "1.62.0",
|
|
93
|
+
"prettier": "3.9.6",
|
|
103
94
|
"prettier-plugin-organize-imports": "4.3.0",
|
|
104
95
|
"prettier-plugin-packagejson": "3.0.2",
|
|
105
|
-
"semantic-release": "25.0.
|
|
106
|
-
"ts-codemod-lib": "2.
|
|
107
|
-
"ts-repo-utils": "10.
|
|
108
|
-
"tsx": "4.
|
|
109
|
-
"typedoc": "0.28.
|
|
96
|
+
"semantic-release": "25.0.8",
|
|
97
|
+
"ts-codemod-lib": "2.2.3",
|
|
98
|
+
"ts-repo-utils": "10.1.6",
|
|
99
|
+
"tsx": "4.23.1",
|
|
100
|
+
"typedoc": "0.28.20",
|
|
110
101
|
"typedoc-github-theme": "0.4.0",
|
|
111
102
|
"typescript": "6.0.3",
|
|
112
|
-
"typescript-native": "npm:typescript@7.0.
|
|
113
|
-
"vitest": "4.1.
|
|
103
|
+
"typescript-native": "npm:typescript@7.0.2",
|
|
104
|
+
"vitest": "4.1.10"
|
|
114
105
|
},
|
|
115
|
-
"packageManager": "pnpm@11.
|
|
106
|
+
"packageManager": "pnpm@11.20.0",
|
|
116
107
|
"engines": {
|
|
117
108
|
"node": ">=22.22.2",
|
|
118
109
|
"pnpm": ">=9.0.0"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import 'dotenv/config';
|
|
4
|
+
import * as util from 'node:util';
|
|
5
|
+
|
|
6
|
+
const HELP = `
|
|
7
|
+
Usage: repo-settings <command> [target] [options]
|
|
8
|
+
|
|
9
|
+
GitHub の repository 設定を JSON ファイルで管理する。
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
apply [target] ローカルの設定ファイルを GitHub に反映する
|
|
13
|
+
backup [target] GitHub の現在値をローカルの bk/ に保存する
|
|
14
|
+
|
|
15
|
+
Targets:
|
|
16
|
+
all すべて(既定)
|
|
17
|
+
repository github/repository-settings/settings.json
|
|
18
|
+
rulesets github/rulesets/*.json
|
|
19
|
+
variables repository variables ( apply のみ )
|
|
20
|
+
actions github/actions-settings/settings.json
|
|
21
|
+
pages github/pages/settings.json
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--owner <owner> 対象の owner
|
|
25
|
+
--repo <repo> 対象の repository 名
|
|
26
|
+
-h, --help このヘルプを表示する
|
|
27
|
+
|
|
28
|
+
owner / repo は「コマンドライン引数 → 環境変数 OWNER / REPO_NAME →
|
|
29
|
+
git remote origin → package.json の name 」の順で解決される。
|
|
30
|
+
通常は git remote から決まるため、どちらの指定も不要。
|
|
31
|
+
|
|
32
|
+
認証は「環境変数 GITHUB_APP_TOKEN / GH_TOKEN / PERSONAL_ACCESS_TOKEN →
|
|
33
|
+
gh CLI ( gh auth token )」の順で解決される。ローカルでは gh auth login
|
|
34
|
+
だけで動く。
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
repo-settings apply
|
|
38
|
+
repo-settings apply rulesets
|
|
39
|
+
repo-settings backup
|
|
40
|
+
repo-settings apply --owner noshiro-pf --repo ts-repo-utils
|
|
41
|
+
`.trim();
|
|
42
|
+
|
|
43
|
+
const COMMANDS = ['apply', 'backup'] as const;
|
|
44
|
+
|
|
45
|
+
type Command = (typeof COMMANDS)[number];
|
|
46
|
+
|
|
47
|
+
const TARGETS = [
|
|
48
|
+
'all',
|
|
49
|
+
'repository',
|
|
50
|
+
'rulesets',
|
|
51
|
+
'variables',
|
|
52
|
+
'actions',
|
|
53
|
+
'pages',
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
type Target = (typeof TARGETS)[number];
|
|
57
|
+
|
|
58
|
+
const COMMAND_SET: ReadonlySet<string> = new Set(COMMANDS);
|
|
59
|
+
|
|
60
|
+
const isCommand = (value: string): value is Command => COMMAND_SET.has(value);
|
|
61
|
+
|
|
62
|
+
const TARGET_SET: ReadonlySet<string> = new Set(TARGETS);
|
|
63
|
+
|
|
64
|
+
const isTarget = (value: string): value is Target => TARGET_SET.has(value);
|
|
65
|
+
|
|
66
|
+
// NOTE: 明示的な型注釈を変数側に付けることで、呼び出し後に制御フローが到達
|
|
67
|
+
// しないことを TypeScript に認識させる( narrowing のために必要 )。
|
|
68
|
+
const fail: (message: string) => never = (message) => {
|
|
69
|
+
console.error(`❌ ${message}`);
|
|
70
|
+
|
|
71
|
+
console.error('');
|
|
72
|
+
|
|
73
|
+
console.error(HELP);
|
|
74
|
+
|
|
75
|
+
process.exit(1);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const { values, positionals } = util.parseArgs({
|
|
79
|
+
args: process.argv.slice(2),
|
|
80
|
+
options: {
|
|
81
|
+
owner: { type: 'string' },
|
|
82
|
+
repo: { type: 'string' },
|
|
83
|
+
help: { type: 'boolean', short: 'h', default: false },
|
|
84
|
+
},
|
|
85
|
+
strict: false,
|
|
86
|
+
allowPositionals: true,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (values.help === true || positionals.length === 0) {
|
|
90
|
+
console.log(HELP);
|
|
91
|
+
|
|
92
|
+
process.exit(positionals.length === 0 ? 1 : 0);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const [commandArg, targetArg = 'all'] = positionals;
|
|
96
|
+
|
|
97
|
+
if (commandArg === undefined || !isCommand(commandArg)) {
|
|
98
|
+
fail(`Unknown command: "${commandArg ?? ''}"`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!isTarget(targetArg)) {
|
|
102
|
+
fail(`Unknown target: "${targetArg}"`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// NOTE: ここで初めて設定モジュールを読み込む。 owner / repo の解決は import 時に
|
|
106
|
+
// 走るため、 --help や引数エラーの時点では評価させたくない。
|
|
107
|
+
const github = await import('../github/index.mjs');
|
|
108
|
+
|
|
109
|
+
const runners: Readonly<
|
|
110
|
+
Record<Command, Partial<Record<Target, () => Promise<void>>>>
|
|
111
|
+
> = {
|
|
112
|
+
apply: {
|
|
113
|
+
all: async () => {
|
|
114
|
+
await github.applyVariables();
|
|
115
|
+
|
|
116
|
+
await github.applyRulesets();
|
|
117
|
+
|
|
118
|
+
await github.applyRepositorySettings();
|
|
119
|
+
|
|
120
|
+
await github.applyActionsSettings();
|
|
121
|
+
|
|
122
|
+
await github.applyPagesSettings();
|
|
123
|
+
},
|
|
124
|
+
repository: github.applyRepositorySettings,
|
|
125
|
+
rulesets: github.applyRulesets,
|
|
126
|
+
variables: github.applyVariables,
|
|
127
|
+
actions: github.applyActionsSettings,
|
|
128
|
+
pages: github.applyPagesSettings,
|
|
129
|
+
},
|
|
130
|
+
backup: {
|
|
131
|
+
all: async () => {
|
|
132
|
+
await github.backupRulesets();
|
|
133
|
+
|
|
134
|
+
await github.backupRepositorySettings();
|
|
135
|
+
|
|
136
|
+
await github.backupActionsSettings();
|
|
137
|
+
|
|
138
|
+
await github.backupPagesSettings();
|
|
139
|
+
},
|
|
140
|
+
repository: github.backupRepositorySettings,
|
|
141
|
+
rulesets: github.backupRulesets,
|
|
142
|
+
actions: github.backupActionsSettings,
|
|
143
|
+
pages: github.backupPagesSettings,
|
|
144
|
+
},
|
|
145
|
+
} as const;
|
|
146
|
+
|
|
147
|
+
const runner = runners[commandArg][targetArg];
|
|
148
|
+
|
|
149
|
+
if (runner === undefined) {
|
|
150
|
+
fail(`"${commandArg}" does not support the target "${targetArg}"`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
await runner();
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type EndpointKeys } from 'octokit-safe-types';
|
|
2
|
+
import { octokitHeaders, OWNER, REPO } from '../../constants.mjs';
|
|
3
|
+
import { octokit } from '../../octokit.mjs';
|
|
4
|
+
import { ActionsSettings } from '../constants.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Settings > Actions > General の現在値を取得する。
|
|
8
|
+
*
|
|
9
|
+
* 2 つのエンドポイントの結果を 1 つのオブジェクトにまとめる。
|
|
10
|
+
*/
|
|
11
|
+
export const getActionsSettings = async (): Promise<ActionsSettings> => {
|
|
12
|
+
// https://docs.github.com/rest/actions/permissions#get-github-actions-permissions-for-a-repository
|
|
13
|
+
const permissions = await octokit.request(
|
|
14
|
+
'GET /repos/{owner}/{repo}/actions/permissions' satisfies EndpointKeys,
|
|
15
|
+
{ owner: OWNER, repo: REPO, headers: octokitHeaders },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// https://docs.github.com/rest/actions/permissions#get-fork-pr-contributor-approval-permissions-for-a-repository
|
|
19
|
+
const forkPrApproval = await octokit.request(
|
|
20
|
+
'GET /repos/{owner}/{repo}/actions/permissions/fork-pr-contributor-approval' satisfies EndpointKeys,
|
|
21
|
+
{ owner: OWNER, repo: REPO, headers: octokitHeaders },
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// sha_pinning_required は @octokit/types v16 の型に無いため、レスポンスから
|
|
25
|
+
// 直接読まずに validate 側の既定値へフォールバックさせる。
|
|
26
|
+
const shaPinningRequired: unknown = (
|
|
27
|
+
permissions.data as Readonly<Record<string, unknown>>
|
|
28
|
+
)['sha_pinning_required'];
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line unicorn/no-array-fill-with-reference-type
|
|
31
|
+
return ActionsSettings.fill({
|
|
32
|
+
enabled: permissions.data.enabled,
|
|
33
|
+
allowed_actions: permissions.data.allowed_actions,
|
|
34
|
+
sha_pinning_required:
|
|
35
|
+
typeof shaPinningRequired === 'boolean' ? shaPinningRequired : undefined,
|
|
36
|
+
fork_pr_contributor_approval_policy: forkPrApproval.data.approval_policy,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type EndpointKeys } from 'octokit-safe-types';
|
|
2
|
+
import { octokitHeaders, OWNER, REPO } from '../../constants.mjs';
|
|
3
|
+
import { octokit } from '../../octokit.mjs';
|
|
4
|
+
import { type ActionsSettings } from '../constants.mjs';
|
|
5
|
+
|
|
6
|
+
/** Settings > Actions > General を JSON の内容に合わせる。 */
|
|
7
|
+
export const setActionsSettings = async (
|
|
8
|
+
settings: ActionsSettings,
|
|
9
|
+
): Promise<void> => {
|
|
10
|
+
// https://docs.github.com/rest/actions/permissions#set-github-actions-permissions-for-a-repository
|
|
11
|
+
//
|
|
12
|
+
// NOTE: sha_pinning_required は @octokit/types v16 の型定義にまだ無い。 API は
|
|
13
|
+
// 受け付けるので、いったん変数に束縛して渡している(オブジェクトリテラルを直接
|
|
14
|
+
// 渡すと excess property check に引っかかるため)。型が追随したら不要になる。
|
|
15
|
+
const permissionsParams = {
|
|
16
|
+
owner: OWNER,
|
|
17
|
+
repo: REPO,
|
|
18
|
+
headers: octokitHeaders,
|
|
19
|
+
enabled: settings.enabled,
|
|
20
|
+
allowed_actions: settings.allowed_actions,
|
|
21
|
+
sha_pinning_required: settings.sha_pinning_required,
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
await octokit.request(
|
|
25
|
+
'PUT /repos/{owner}/{repo}/actions/permissions' satisfies EndpointKeys,
|
|
26
|
+
permissionsParams,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// https://docs.github.com/rest/actions/permissions#set-fork-pr-contributor-approval-permissions-for-a-repository
|
|
30
|
+
await octokit.request(
|
|
31
|
+
'PUT /repos/{owner}/{repo}/actions/permissions/fork-pr-contributor-approval' satisfies EndpointKeys,
|
|
32
|
+
{
|
|
33
|
+
owner: OWNER,
|
|
34
|
+
repo: REPO,
|
|
35
|
+
headers: octokitHeaders,
|
|
36
|
+
approval_policy: settings.fork_pr_contributor_approval_policy,
|
|
37
|
+
},
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { validationErrorsToMessages } from 'ts-fortress';
|
|
6
|
+
import {
|
|
7
|
+
formatUncommittedFiles,
|
|
8
|
+
isDirectlyExecuted,
|
|
9
|
+
Result,
|
|
10
|
+
} from 'ts-repo-utils';
|
|
11
|
+
import { actionsSettingsDir, settingsJsonName } from '../constants.mjs';
|
|
12
|
+
import { getActionsSettings, setActionsSettings } from './api/index.mjs';
|
|
13
|
+
import { backupActionsSettings } from './backup.mjs';
|
|
14
|
+
import { ActionsSettings } from './constants.mjs';
|
|
15
|
+
|
|
16
|
+
/** `github/actions-settings/settings.json` を Settings > Actions > General に反映する。 */
|
|
17
|
+
export const applyActionsSettings = async (): Promise<void> => {
|
|
18
|
+
await backupActionsSettings(false);
|
|
19
|
+
|
|
20
|
+
const settings = await readSettings();
|
|
21
|
+
|
|
22
|
+
await setActionsSettings(settings);
|
|
23
|
+
|
|
24
|
+
// 反映後の実際の値でローカルのファイルを更新する
|
|
25
|
+
{
|
|
26
|
+
const applied = await getActionsSettings();
|
|
27
|
+
|
|
28
|
+
const str = JSON.stringify(applied, undefined, 2);
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
31
|
+
await fs.writeFile(path.resolve(actionsSettingsDir, settingsJsonName), str);
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
34
|
+
await fs.writeFile(
|
|
35
|
+
path.resolve(actionsSettingsDir, 'bk', settingsJsonName),
|
|
36
|
+
str,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
await formatUncommittedFiles();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const readSettings = async (): Promise<ActionsSettings> => {
|
|
44
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
45
|
+
const settingsText = await fs.readFile(
|
|
46
|
+
path.resolve(actionsSettingsDir, settingsJsonName),
|
|
47
|
+
{ encoding: 'utf8' },
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const validationResult = ActionsSettings.validate(JSON.parse(settingsText));
|
|
51
|
+
|
|
52
|
+
if (Result.isErr(validationResult)) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
validationErrorsToMessages(validationResult.value).join('\n'),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return validationResult.value;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (isDirectlyExecuted(import.meta.url)) {
|
|
62
|
+
await applyActionsSettings();
|
|
63
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'dotenv/config';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
formatUncommittedFiles,
|
|
7
|
+
isDirectlyExecuted,
|
|
8
|
+
makeEmptyDir,
|
|
9
|
+
} from 'ts-repo-utils';
|
|
10
|
+
import { actionsSettingsDir, settingsJsonName } from '../constants.mjs';
|
|
11
|
+
import { getActionsSettings } from './api/index.mjs';
|
|
12
|
+
|
|
13
|
+
const backupDir = path.resolve(actionsSettingsDir, './bk');
|
|
14
|
+
|
|
15
|
+
/** Settings > Actions > General の現在値を `bk/` に保存する。 */
|
|
16
|
+
export const backupActionsSettings = async (
|
|
17
|
+
fmt: boolean = true,
|
|
18
|
+
): Promise<void> => {
|
|
19
|
+
await makeEmptyDir(backupDir);
|
|
20
|
+
|
|
21
|
+
const settings = await getActionsSettings();
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
24
|
+
await fs.writeFile(
|
|
25
|
+
path.resolve(backupDir, settingsJsonName),
|
|
26
|
+
JSON.stringify(settings, undefined, 2),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (fmt) {
|
|
30
|
+
await formatUncommittedFiles();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (isDirectlyExecuted(import.meta.url)) {
|
|
35
|
+
await backupActionsSettings();
|
|
36
|
+
}
|