fabrique 2.0.30 → 2.0.31

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 (23) hide show
  1. package/CONTRIBUTING.md +1 -1
  2. package/README.md +29 -0
  3. package/package.json +1 -1
  4. package/src/cli/actions.private/setup-github-repository/setup-github-repository.d.ts +15 -0
  5. package/src/cli/actions.private/setup-github-repository/setup-github-repository.js +112 -0
  6. package/src/cli/actions.private/setup-github-repository/setup-github-repository.js.map +1 -0
  7. package/src/cli/cli.js +21 -0
  8. package/src/cli/cli.js.map +1 -1
  9. package/src/helpers.private/cmd/exec-command.js +8 -7
  10. package/src/helpers.private/cmd/exec-command.js.map +1 -1
  11. package/src/helpers.private/cmd/quote-shell-argument/quote-shell-argument.d.ts +8 -0
  12. package/src/helpers.private/cmd/quote-shell-argument/quote-shell-argument.js +11 -0
  13. package/src/helpers.private/cmd/quote-shell-argument/quote-shell-argument.js.map +1 -0
  14. package/src/helpers.private/github/github-ruleset/build-branch-ruleset-payload/build-branch-ruleset-payload.d.ts +12 -0
  15. package/src/helpers.private/github/github-ruleset/build-branch-ruleset-payload/build-branch-ruleset-payload.js +45 -0
  16. package/src/helpers.private/github/github-ruleset/build-branch-ruleset-payload/build-branch-ruleset-payload.js.map +1 -0
  17. package/src/helpers.private/github/github-ruleset/build-tag-ruleset-payload/build-tag-ruleset-payload.d.ts +8 -0
  18. package/src/helpers.private/github/github-ruleset/build-tag-ruleset-payload/build-tag-ruleset-payload.js +20 -0
  19. package/src/helpers.private/github/github-ruleset/build-tag-ruleset-payload/build-tag-ruleset-payload.js.map +1 -0
  20. package/src/helpers.private/github/github-ruleset/github-ruleset.d.ts +59 -0
  21. package/src/helpers.private/github/github-ruleset/github-ruleset.js +15 -0
  22. package/src/helpers.private/github/github-ruleset/github-ruleset.js.map +1 -0
  23. package/static/templates/lib/.github/workflows/auto-assign-author-and-reviewers.yml +3 -0
package/CONTRIBUTING.md CHANGED
@@ -56,7 +56,7 @@ yarn install
56
56
 
57
57
  1. fork the repository
58
58
  1. add the feature/fix by modifying the code in the `src/` directory
59
- 1. add/write some tests until 100% code coverage is reached (run the tests with `yarn fb:test:coverage`)
59
+ 1. add/write some tests with good code coverage (run the tests with `yarn fb:test:coverage`)
60
60
  1. format the code, using the command `yarn fb:format`
61
61
  1. commit and push your work following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) convention
62
62
  1. create a PR from your repository to the upstream repository, explaining clearly what was added/fixed.
package/README.md CHANGED
@@ -282,6 +282,35 @@ It preserves the case of the names (ex: `dash-case`, or `cameCase`).
282
282
  - `--dry` (default: false): runs without modifying the files. This is useful to check if your refactoring is safe or not.
283
283
  - `--cwd` (default: current folder): specifies the directory to start from.
284
284
 
285
+ #### \[cmd\]: setup-github-repository
286
+
287
+ ```shell
288
+ # from the root of a "fabrique" project
289
+ npx fabrique setup-github-repository
290
+ ```
291
+
292
+ ##### action
293
+
294
+ This command configures the basic rules of the GitHub repository of the current project, using the [GitHub CLI](https://cli.github.com) (`gh`):
295
+
296
+ - repository settings:
297
+ - merge commits are allowed, while rebase and squash merges are disabled
298
+ - head branches are deleted when pull requests are merged
299
+ - a branch ruleset on `main` and `develop`:
300
+ - push, force-push and deletion are forbidden: changes must go through a pull request
301
+ - the CI check (`Check`) must pass, with an up-to-date branch, to allow the merge
302
+ - a tag ruleset on release tags (`v*`): deletion and force-push are forbidden
303
+
304
+ > INFO: requires the GitHub CLI (`gh`) to be installed and authenticated, with **administrator** permission on the repository.
305
+ > The command is idempotent: it updates the existing rules instead of duplicating them.
306
+
307
+ ##### options
308
+
309
+ - `--dry` (default: false): runs without applying the changes. Useful to preview the `gh` commands.
310
+ - `--cwd` (default: current folder): the repository directory.
311
+ - `--required-checks <names>` (default: `Check`): comma-separated list of CI checks required to merge.
312
+ - `--approvals <count>` (default: 0): number of approving reviews required to merge (0 = pull request only).
313
+
285
314
  #### --version
286
315
 
287
316
  ```shell
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fabrique",
3
- "version": "2.0.30",
3
+ "version": "2.0.31",
4
4
  "type": "module",
5
5
  "description": "CLI to build a library",
6
6
  "keywords": [],
@@ -0,0 +1,15 @@
1
+ import type { Logger } from '../../../helpers.private/log/logger.ts';
2
+ export interface SetupGithubRepositoryOptions {
3
+ readonly dry?: boolean;
4
+ readonly cwd?: string;
5
+ readonly requiredChecks?: readonly string[];
6
+ readonly approvals?: number;
7
+ readonly logger: Logger;
8
+ }
9
+ /**
10
+ * Configures the basic rules of the GitHub repository of the current project, using the GitHub CLI:
11
+ * - repository settings: merge commits only, head branches deleted on merge
12
+ * - a ruleset protecting the release branches: no push, force-push or deletion, required CI checks
13
+ * - a ruleset protecting the release tags: no deletion, no force-push
14
+ */
15
+ export declare function setupGithubRepository({ dry, cwd, requiredChecks, approvals, logger, }: SetupGithubRepositoryOptions): Promise<void>;
@@ -0,0 +1,112 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { rm, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { execCommand } from '../../../helpers.private/cmd/exec-command.js';
6
+ import { buildBranchRulesetPayload } from '../../../helpers.private/github/github-ruleset/build-branch-ruleset-payload/build-branch-ruleset-payload.js';
7
+ import { buildTagRulesetPayload } from '../../../helpers.private/github/github-ruleset/build-tag-ruleset-payload/build-tag-ruleset-payload.js';
8
+ import {} from '../../../helpers.private/github/github-ruleset/github-ruleset.js';
9
+ const PROTECTED_BRANCHES = ['main', 'develop'];
10
+ const RELEASE_TAG_PATTERN = 'v*';
11
+ const DEFAULT_REQUIRED_CHECKS = ['Check'];
12
+ /**
13
+ * Configures the basic rules of the GitHub repository of the current project, using the GitHub CLI:
14
+ * - repository settings: merge commits only, head branches deleted on merge
15
+ * - a ruleset protecting the release branches: no push, force-push or deletion, required CI checks
16
+ * - a ruleset protecting the release tags: no deletion, no force-push
17
+ */
18
+ export function setupGithubRepository({ dry = false, cwd = process.cwd(), requiredChecks = DEFAULT_REQUIRED_CHECKS, approvals = 0, logger, }) {
19
+ return logger.asyncTask('setup-github-repository', async (logger) => {
20
+ verifyApprovals(approvals);
21
+ verifyRequiredChecks(requiredChecks);
22
+ const repository = await readGithubRepository({ cwd, logger });
23
+ if (repository.visibility !== 'PUBLIC') {
24
+ logger.warn(`Rulesets are a paid feature on ${repository.visibility.toLowerCase()} repositories: some rules may not be applied.`);
25
+ }
26
+ await updateRepositorySettings({ repository, dry, cwd, logger });
27
+ await upsertRuleset({
28
+ repository,
29
+ dry,
30
+ cwd,
31
+ logger,
32
+ payload: buildBranchRulesetPayload({
33
+ branches: PROTECTED_BRANCHES,
34
+ requiredChecks,
35
+ approvals,
36
+ }),
37
+ });
38
+ await upsertRuleset({
39
+ repository,
40
+ dry,
41
+ cwd,
42
+ logger,
43
+ payload: buildTagRulesetPayload({ pattern: RELEASE_TAG_PATTERN }),
44
+ });
45
+ });
46
+ }
47
+ function verifyApprovals(approvals) {
48
+ if (!Number.isInteger(approvals) || approvals < 0) {
49
+ throw new Error(`"approvals" must be a positive integer (got ${approvals}).`);
50
+ }
51
+ }
52
+ function verifyRequiredChecks(requiredChecks) {
53
+ if (requiredChecks.length === 0) {
54
+ throw new Error(`"requiredChecks" must contain at least one check name.`);
55
+ }
56
+ }
57
+ async function readGithubRepository({ cwd, logger, }) {
58
+ const output = await execCommand(logger, 'gh', ['repo', 'view', '--json', 'nameWithOwner,viewerPermission,visibility'], { cwd });
59
+ const repository = JSON.parse(output);
60
+ if (repository.viewerPermission !== 'ADMIN') {
61
+ throw new Error(`Administrator permission required on ${repository.nameWithOwner} (got "${repository.viewerPermission}").`);
62
+ }
63
+ return repository;
64
+ }
65
+ async function updateRepositorySettings({ repository, dry, cwd, logger, }) {
66
+ const args = [
67
+ 'repo',
68
+ 'edit',
69
+ repository.nameWithOwner,
70
+ '--delete-branch-on-merge=true',
71
+ '--enable-merge-commit=true',
72
+ '--enable-rebase-merge=false',
73
+ '--enable-squash-merge=false',
74
+ ];
75
+ if (dry) {
76
+ logger.debug(`(dry) gh ${args.join(' ')}`);
77
+ }
78
+ else {
79
+ await execCommand(logger, 'gh', args, { cwd });
80
+ }
81
+ }
82
+ async function upsertRuleset({ repository, dry, cwd, logger, payload, }) {
83
+ const rulesets = await listRulesets({ repository, cwd, logger });
84
+ const existing = rulesets.find((ruleset) => ruleset.name === payload.name);
85
+ const method = existing === undefined ? 'POST' : 'PUT';
86
+ const url = existing === undefined
87
+ ? `repos/${repository.nameWithOwner}/rulesets`
88
+ : `repos/${repository.nameWithOwner}/rulesets/${existing.id}`;
89
+ if (dry) {
90
+ logger.debug(`(dry) gh api --method ${method} ${url} --input <${payload.name} payload>`);
91
+ return;
92
+ }
93
+ const payloadFile = await writePayloadFile(payload);
94
+ try {
95
+ await execCommand(logger, 'gh', ['api', '--method', method, url, '--input', payloadFile], {
96
+ cwd,
97
+ });
98
+ }
99
+ finally {
100
+ await rm(payloadFile, { force: true });
101
+ }
102
+ }
103
+ async function listRulesets({ repository, cwd, logger, }) {
104
+ const output = await execCommand(logger, 'gh', ['api', `repos/${repository.nameWithOwner}/rulesets?per_page=100`], { cwd });
105
+ return JSON.parse(output);
106
+ }
107
+ async function writePayloadFile(payload) {
108
+ const payloadFile = join(tmpdir(), `fabrique-github-ruleset-${randomUUID()}.json`);
109
+ await writeFile(payloadFile, JSON.stringify(payload, null, 2));
110
+ return payloadFile;
111
+ }
112
+ //# sourceMappingURL=setup-github-repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-github-repository.js","sourceRoot":"","sources":["../../../../../src/cli/actions.private/setup-github-repository/setup-github-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE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G,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE;YACxF,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;AACH,CAAC;AAQD,KAAK,UAAU,YAAY,CAAC,EAC1B,UAAU,EACV,GAAG,EACH,MAAM,GACc;IACpB,MAAM,MAAM,GAAW,MAAM,WAAW,CACtC,MAAM,EACN,IAAI,EACJ,CAAC,KAAK,EAAE,SAAS,UAAU,CAAC,aAAa,wBAAwB,CAAC,EAClE,EAAE,GAAG,EAAE,CACR,CAAC;IAEF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,OAA6B;IAC3D,MAAM,WAAW,GAAW,IAAI,CAAC,MAAM,EAAE,EAAE,2BAA2B,UAAU,EAAE,OAAO,CAAC,CAAC;IAE3F,MAAM,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAE/D,OAAO,WAAW,CAAC;AACrB,CAAC"}
package/src/cli/cli.js CHANGED
@@ -10,6 +10,7 @@ import { ciWorkflow } from './actions.private/ci-workflow/ci-workflow.js';
10
10
  import { createProject } from './actions.private/create-project/create-project.js';
11
11
  import { refactor } from './actions.private/refactor/refactor.js';
12
12
  import { releaseProject } from './actions.private/release-project/release-project.js';
13
+ import { setupGithubRepository } from './actions.private/setup-github-repository/setup-github-repository.js';
13
14
  import { upgradeProject } from './actions.private/upgrade-project/upgrade-project.js';
14
15
  // tuto: https://medium.com/nmc-techblog/building-a-cli-with-node-js-in-2024-c278802a3ef5
15
16
  const logger = Logger.root({ logLevel: DEFAULT_LOG_LEVEL });
@@ -93,5 +94,25 @@ program
93
94
  ...options,
94
95
  });
95
96
  });
97
+ // CMD: setup-github-repository
98
+ program
99
+ .command('setup-github-repository')
100
+ .description('configures the GitHub repository rules (branches, tags, merges) using gh')
101
+ .option('--dry', 'runs without applying the changes', false)
102
+ .option('--cwd <cwd>', 'working directory of the repository', process.cwd)
103
+ .option('--required-checks <names>', 'comma-separated list of CI checks required to merge', 'Check')
104
+ .option('--approvals <count>', 'number of approving reviews required to merge (0 = PR only)', '0')
105
+ .action((options) => {
106
+ return setupGithubRepository({
107
+ dry: options.dry,
108
+ cwd: options.cwd,
109
+ requiredChecks: options.requiredChecks
110
+ .split(',')
111
+ .map((name) => name.trim())
112
+ .filter((name) => name.length > 0),
113
+ approvals: Number(options.approvals),
114
+ logger,
115
+ });
116
+ });
96
117
  program.parse();
97
118
  //# sourceMappingURL=cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,GAAG,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0DAA0D,CAAC;AAE3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,gEAAgE,CAAC;AACnG,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gEAAgE,CAAC;AAEnG,OAAO,EAAE,YAAY,EAAE,MAAM,kDAAkD,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,sDAAsD,CAAC;AAEtF,yFAAyF;AAEzF,MAAM,MAAM,GAAG,MAAM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AC,GAAG,CAAC;KACzE,MAAM,CACL,2BAA2B,EAC3B,qDAAqD,EACrD,OAAO,CACR;KACA,MAAM,CAAC,qBAAqB,EAAE,6DAA6D,EAAE,GAAG,CAAC;KACjG,MAAM,CACL,CAAC,OAKA,EAAiB,EAAE;IAClB,OAAO,qBAAqB,CAAC;QAC3B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,cAAc,EAAE,OAAO,CAAC,cAAc;aACnC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;aAC1C,MAAM,CAAC,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACrD,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;QACpC,MAAM;KACP,CAAC,CAAC;AACL,CAAC,CACF,CAAC;AAEJ,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import process from 'node:process';
3
3
  import { Readable } from 'node:stream';
4
4
  import { Logger } from '../log/logger.js';
5
+ import { quoteShellArgument } from './quote-shell-argument/quote-shell-argument.js';
5
6
  export class ExecCommandError extends Error {
6
7
  command;
7
8
  stderr;
@@ -15,15 +16,15 @@ export class ExecCommandError extends Error {
15
16
  }
16
17
  export function execCommand(logger, command, args = [], options) {
17
18
  return new Promise((resolve, reject) => {
18
- const fullCommand = `${command} ${args
19
- .map((arg) => {
20
- return !arg.startsWith('"') && arg.includes(' ') ? JSON.stringify(arg) : arg;
21
- })
22
- .join(' ')}`;
19
+ const shell = options?.shell ?? process.platform === 'win32';
20
+ // when a shell is used, the command and its arguments are joined into a single command line
21
+ // and parsed by the shell: arguments containing spaces must be quoted
22
+ const quotedArgs = shell ? args.map(quoteShellArgument) : args;
23
+ const fullCommand = `${command} ${quotedArgs.join(' ')}`;
23
24
  logger.log(fullCommand);
24
- const childProcess = spawn(command, args, {
25
+ const childProcess = spawn(command, [...quotedArgs], {
25
26
  cwd: process.cwd(),
26
- shell: process.platform === 'win32',
27
+ shell,
27
28
  detached: false,
28
29
  stdio: 'pipe',
29
30
  ...options,
@@ -1 +1 @@
1
- {"version":3,"file":"exec-command.js","sourceRoot":"","sources":["../../../../src/helpers.private/cmd/exec-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AACjF,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAS1C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,OAAO,CAAS;IAChB,MAAM,CAAS;IACf,QAAQ,CAAS,CAAC,gBAAgB;IAE3C,YAAY,EACV,OAAO,EACP,MAAM,GAAG,EAAE,EACX,QAAQ,EACR,OAAO,GAAG,aAAa,OAAO,aAAa,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,kBAAkB,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,EAC7I,GAAG,OAAO,EACc;QACxB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CACzB,MAAc,EACd,OAAe,EACf,IAAI,GAAa,EAAE,EACnB,OAAsB;IAEtB,OAAO,IAAI,OAAO,CAChB,CAAC,OAAiC,EAAE,MAAkC,EAAQ,EAAE;QAC9E,MAAM,WAAW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gBACd,CAAC;qBAAM,CAAC;oBACN,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,YAAY,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;oBACjC,MAAM,CAAC,IAAI,gBAAgB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;gBACtD,CAAC;qBAAM,CAAC;oBACN,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CACvC,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,gBAAgB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,EAC/E,MAAM,CACP,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAQ,EAAE;YAC5C,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,+BAA+B;QAC/B,iCAAiC;QACjC,MAAM;QACN,EAAE;QACF,gCAAgC;QAChC,kCAAkC;QAClC,MAAM;QACN,EAAE;QACF,iCAAiC;QACjC,mCAAmC;QACnC,MAAM;IACR,CAAC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,OAAe,EACf,IAAI,GAAa,EAAE,EACnB,OAAsB;IAEtB,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QACxC,KAAK,EAAE,SAAS;QAChB,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"exec-command.js","sourceRoot":"","sources":["../../../../src/helpers.private/cmd/exec-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,EAAqB,MAAM,oBAAoB,CAAC;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BACtD,CAAC;qBAAM,CAAC;oBACN,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CACvC,CAAC,MAAc,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,gBAAgB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,EAC/E,MAAM,CACP,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAQ,EAAE;YAC5C,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,+BAA+B;QAC/B,iCAAiC;QACjC,MAAM;QACN,EAAE;QACF,gCAAgC;QAChC,kCAAkC;QAClC,MAAM;QACN,EAAE;QACF,iCAAiC;QACjC,mCAAmC;QACnC,MAAM;IACR,CAAC,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,MAAc,EACd,OAAe,EACf,IAAI,GAAa,EAAE,EACnB,OAAsB;IAEtB,OAAO,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;QACxC,KAAK,EAAE,SAAS;QAChB,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Quotes a command argument so that it survives being passed through a shell (ex: Windows `cmd.exe`
3
+ * when `spawn` is used with `shell: true`): without quotes, an argument containing spaces is split
4
+ * into multiple arguments by the shell.
5
+ *
6
+ * Only spaces are handled: other shell metacharacters are left untouched.
7
+ */
8
+ export declare function quoteShellArgument(argument: string): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Quotes a command argument so that it survives being passed through a shell (ex: Windows `cmd.exe`
3
+ * when `spawn` is used with `shell: true`): without quotes, an argument containing spaces is split
4
+ * into multiple arguments by the shell.
5
+ *
6
+ * Only spaces are handled: other shell metacharacters are left untouched.
7
+ */
8
+ export function quoteShellArgument(argument) {
9
+ return argument.includes(' ') && !argument.startsWith('"') ? `"${argument}"` : argument;
10
+ }
11
+ //# sourceMappingURL=quote-shell-argument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quote-shell-argument.js","sourceRoot":"","sources":["../../../../../src/helpers.private/cmd/quote-shell-argument/quote-shell-argument.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC1F,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type GithubRulesetPayload } from '../github-ruleset.ts';
2
+ export interface BuildBranchRulesetPayloadOptions {
3
+ readonly branches: readonly string[];
4
+ readonly requiredChecks: readonly string[];
5
+ readonly approvals: number;
6
+ }
7
+ /**
8
+ * Builds the payload of a ruleset protecting the release branches:
9
+ * no direct push (a pull request is required), no force-push, no deletion,
10
+ * and the required CI checks must pass with an up-to-date branch.
11
+ */
12
+ export declare function buildBranchRulesetPayload({ branches, requiredChecks, approvals, }: BuildBranchRulesetPayloadOptions): GithubRulesetPayload;
@@ -0,0 +1,45 @@
1
+ import { BRANCH_RULES_RULESET_NAME, GITHUB_ACTIONS_APP_ID, } from '../github-ruleset.js';
2
+ /**
3
+ * Builds the payload of a ruleset protecting the release branches:
4
+ * no direct push (a pull request is required), no force-push, no deletion,
5
+ * and the required CI checks must pass with an up-to-date branch.
6
+ */
7
+ export function buildBranchRulesetPayload({ branches, requiredChecks, approvals, }) {
8
+ return {
9
+ name: BRANCH_RULES_RULESET_NAME,
10
+ target: 'branch',
11
+ enforcement: 'active',
12
+ bypass_actors: [],
13
+ conditions: {
14
+ ref_name: {
15
+ include: branches.map((branch) => `refs/heads/${branch}`),
16
+ exclude: [],
17
+ },
18
+ },
19
+ rules: [
20
+ { type: 'deletion' },
21
+ { type: 'non_fast_forward' },
22
+ {
23
+ type: 'pull_request',
24
+ parameters: {
25
+ required_approving_review_count: approvals,
26
+ dismiss_stale_reviews_on_push: approvals > 0,
27
+ require_code_owner_review: false,
28
+ require_last_push_approval: approvals > 0,
29
+ required_review_thread_resolution: false,
30
+ },
31
+ },
32
+ {
33
+ type: 'required_status_checks',
34
+ parameters: {
35
+ strict_required_status_checks_policy: true,
36
+ required_status_checks: requiredChecks.map((checkName) => ({
37
+ context: checkName,
38
+ integration_id: GITHUB_ACTIONS_APP_ID,
39
+ })),
40
+ },
41
+ },
42
+ ],
43
+ };
44
+ }
45
+ //# sourceMappingURL=build-branch-ruleset-payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-branch-ruleset-payload.js","sourceRoot":"","sources":["../../../../../../src/helpers.private/github/github-ruleset/build-branch-ruleset-payload/build-branch-ruleset-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC;AAQ9B;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,EACxC,QAAQ,EACR,cAAc,EACd,SAAS,GACwB;IACjC,OAAO;QACL,IAAI,EAAE,yBAAyB;QAC/B,MAAM,EAAE,QAAQ;QAChB,WAAW,EAAE,QAAQ;QACrB,aAAa,EAAE,EAAE;QACjB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAc,EAAU,EAAE,CAAC,cAAc,MAAM,EAAE,CAAC;gBACzE,OAAO,EAAE,EAAE;aACZ;SACF;QACD,KAAK,EAAE;YACL,EAAE,IAAI,EAAE,UAAU,EAAE;YACpB,EAAE,IAAI,EAAE,kBAAkB,EAAE;YAC5B;gBACE,IAAI,EAAE,cAAc;gBACpB,UAAU,EAAE;oBACV,+BAA+B,EAAE,SAAS;oBAC1C,6BAA6B,EAAE,SAAS,GAAG,CAAC;oBAC5C,yBAAyB,EAAE,KAAK;oBAChC,0BAA0B,EAAE,SAAS,GAAG,CAAC;oBACzC,iCAAiC,EAAE,KAAK;iBACzC;aACF;YACD;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,UAAU,EAAE;oBACV,oCAAoC,EAAE,IAAI;oBAC1C,sBAAsB,EAAE,cAAc,CAAC,GAAG,CACxC,CAAC,SAAiB,EAAiE,EAAE,CAAC,CAAC;wBACrF,OAAO,EAAE,SAAS;wBAClB,cAAc,EAAE,qBAAqB;qBACtC,CAAC,CACH;iBACF;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type GithubRulesetPayload } from '../github-ruleset.ts';
2
+ export interface BuildTagRulesetPayloadOptions {
3
+ readonly pattern: string;
4
+ }
5
+ /**
6
+ * Builds the payload of a ruleset protecting the release tags: no deletion, no force-push.
7
+ */
8
+ export declare function buildTagRulesetPayload({ pattern, }: BuildTagRulesetPayloadOptions): GithubRulesetPayload;
@@ -0,0 +1,20 @@
1
+ import { TAG_RULES_RULESET_NAME } from '../github-ruleset.js';
2
+ /**
3
+ * Builds the payload of a ruleset protecting the release tags: no deletion, no force-push.
4
+ */
5
+ export function buildTagRulesetPayload({ pattern, }) {
6
+ return {
7
+ name: TAG_RULES_RULESET_NAME,
8
+ target: 'tag',
9
+ enforcement: 'active',
10
+ bypass_actors: [],
11
+ conditions: {
12
+ ref_name: {
13
+ include: [`refs/tags/${pattern}`],
14
+ exclude: [],
15
+ },
16
+ },
17
+ rules: [{ type: 'deletion' }, { type: 'non_fast_forward' }],
18
+ };
19
+ }
20
+ //# sourceMappingURL=build-tag-ruleset-payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-tag-ruleset-payload.js","sourceRoot":"","sources":["../../../../../../src/helpers.private/github/github-ruleset/build-tag-ruleset-payload/build-tag-ruleset-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAMzF;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,EACrC,OAAO,GACuB;IAC9B,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,QAAQ;QACrB,aAAa,EAAE,EAAE;QACjB,UAAU,EAAE;YACV,QAAQ,EAAE;gBACR,OAAO,EAAE,CAAC,aAAa,OAAO,EAAE,CAAC;gBACjC,OAAO,EAAE,EAAE;aACZ;SACF;QACD,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC;KAC5D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The GitHub app id of GitHub Actions: required to declare a required check as a GitHub Actions check.
3
+ */
4
+ export declare const GITHUB_ACTIONS_APP_ID = 15368;
5
+ /**
6
+ * The name of the ruleset protecting the release branches (`main` and `develop`).
7
+ * The name is used to identify the ruleset on updates: it must remain stable.
8
+ */
9
+ export declare const BRANCH_RULES_RULESET_NAME = "Fabrique: branch rules";
10
+ /**
11
+ * The name of the ruleset protecting the release tags (`v*`).
12
+ * The name is used to identify the ruleset on updates: it must remain stable.
13
+ */
14
+ export declare const TAG_RULES_RULESET_NAME = "Fabrique: tag rules";
15
+ export type GithubRulesetTarget = 'branch' | 'push' | 'tag';
16
+ export type GithubRulesetEnforcement = 'active' | 'evaluate' | 'disabled';
17
+ export type GithubRulesetRule = {
18
+ readonly type: 'deletion';
19
+ } | {
20
+ readonly type: 'non_fast_forward';
21
+ } | {
22
+ readonly type: 'pull_request';
23
+ readonly parameters: {
24
+ readonly required_approving_review_count: number;
25
+ readonly dismiss_stale_reviews_on_push: boolean;
26
+ readonly require_code_owner_review: boolean;
27
+ readonly require_last_push_approval: boolean;
28
+ readonly required_review_thread_resolution: boolean;
29
+ };
30
+ } | {
31
+ readonly type: 'required_status_checks';
32
+ readonly parameters: {
33
+ readonly strict_required_status_checks_policy: boolean;
34
+ readonly required_status_checks: readonly {
35
+ readonly context: string;
36
+ readonly integration_id: number;
37
+ }[];
38
+ };
39
+ };
40
+ export interface GithubRulesetPayload {
41
+ readonly name: string;
42
+ readonly target: GithubRulesetTarget;
43
+ readonly enforcement: GithubRulesetEnforcement;
44
+ /**
45
+ * Always empty: nobody bypasses the rules, not even repository administrators.
46
+ */
47
+ readonly bypass_actors: readonly [];
48
+ readonly conditions: {
49
+ readonly ref_name: {
50
+ readonly include: readonly string[];
51
+ readonly exclude: readonly string[];
52
+ };
53
+ };
54
+ readonly rules: readonly GithubRulesetRule[];
55
+ }
56
+ export interface GithubRulesetSummary {
57
+ readonly id: number;
58
+ readonly name: string;
59
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The GitHub app id of GitHub Actions: required to declare a required check as a GitHub Actions check.
3
+ */
4
+ export const GITHUB_ACTIONS_APP_ID = 15368;
5
+ /**
6
+ * The name of the ruleset protecting the release branches (`main` and `develop`).
7
+ * The name is used to identify the ruleset on updates: it must remain stable.
8
+ */
9
+ export const BRANCH_RULES_RULESET_NAME = 'Fabrique: branch rules';
10
+ /**
11
+ * The name of the ruleset protecting the release tags (`v*`).
12
+ * The name is used to identify the ruleset on updates: it must remain stable.
13
+ */
14
+ export const TAG_RULES_RULESET_NAME = 'Fabrique: tag rules';
15
+ //# sourceMappingURL=github-ruleset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-ruleset.js","sourceRoot":"","sources":["../../../../../src/helpers.private/github/github-ruleset/github-ruleset.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,wBAAwB,CAAC;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,qBAAqB,CAAC"}
@@ -9,5 +9,8 @@ on:
9
9
  jobs:
10
10
  auto-assign-author-and-reviewers:
11
11
  runs-on: ubuntu-latest
12
+ permissions:
13
+ issues: write # add assignees
14
+ pull-requests: write # request reviewers
12
15
  steps:
13
16
  - uses: kentaro-m/auto-assign-action@v2.0.2