@speedkit/cli 4.35.1 → 4.36.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +42 -7
  3. package/dist/commands/bulk-deploy.d.ts +19 -0
  4. package/dist/commands/bulk-deploy.js +52 -0
  5. package/dist/commands/deploy.d.ts +2 -0
  6. package/dist/commands/deploy.js +32 -2
  7. package/dist/services/cli/cli-service.js +42 -2
  8. package/dist/services/cli/cli-service.spec.js +41 -0
  9. package/dist/services/deploy/bulk/bulk-deploy-model.d.ts +46 -0
  10. package/dist/services/deploy/bulk/bulk-deploy-model.js +27 -0
  11. package/dist/services/deploy/bulk/bulk-deploy-service-factory.d.ts +11 -0
  12. package/dist/services/deploy/bulk/bulk-deploy-service-factory.js +24 -0
  13. package/dist/services/deploy/bulk/bulk-deploy-service.d.ts +47 -0
  14. package/dist/services/deploy/bulk/bulk-deploy-service.js +201 -0
  15. package/dist/services/deploy/bulk/bulk-deploy-service.spec.d.ts +1 -0
  16. package/dist/services/deploy/bulk/bulk-deploy-service.spec.js +146 -0
  17. package/dist/services/deploy/bulk/config-deploy-factory.d.ts +13 -0
  18. package/dist/services/deploy/bulk/config-deploy-factory.js +20 -0
  19. package/dist/services/deploy/bulk/index.d.ts +5 -0
  20. package/dist/services/deploy/bulk/index.js +5 -0
  21. package/dist/services/deploy/bulk/touched-configs.d.ts +12 -0
  22. package/dist/services/deploy/bulk/touched-configs.js +54 -0
  23. package/dist/services/deploy/bulk/touched-configs.spec.d.ts +1 -0
  24. package/dist/services/deploy/bulk/touched-configs.spec.js +77 -0
  25. package/dist/services/deploy/checks/activation/customer-approval-check.d.ts +3 -1
  26. package/dist/services/deploy/checks/activation/customer-approval-check.js +5 -2
  27. package/dist/services/deploy/checks/activation/customer-approval-check.spec.js +18 -15
  28. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +3 -1
  29. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +6 -3
  30. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +3 -1
  31. package/dist/services/deploy/checks/post-deploy/save-files-check.js +5 -2
  32. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.d.ts +3 -1
  33. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +9 -5
  34. package/dist/services/deploy/checks/pre-deploy/split-change-check.d.ts +3 -1
  35. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +8 -5
  36. package/dist/services/deploy/checks/pre-deploy/split-change-check.spec.d.ts +1 -0
  37. package/dist/services/deploy/checks/pre-deploy/split-change-check.spec.js +55 -0
  38. package/dist/services/deploy/context/deploy-context.d.ts +21 -1
  39. package/dist/services/deploy/context/deploy-context.js +30 -1
  40. package/dist/services/deploy/deploy-service-factory.d.ts +13 -1
  41. package/dist/services/deploy/deploy-service-factory.js +36 -15
  42. package/dist/services/deploy/error/deploy-aborted-error.d.ts +12 -0
  43. package/dist/services/deploy/error/deploy-aborted-error.js +16 -0
  44. package/dist/services/deploy/handler/customer-config-handler.d.ts +3 -1
  45. package/dist/services/deploy/handler/customer-config-handler.js +11 -7
  46. package/dist/services/deploy/handler/install-resource-handler.d.ts +3 -1
  47. package/dist/services/deploy/handler/install-resource-handler.js +12 -7
  48. package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.d.ts +3 -1
  49. package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.js +5 -2
  50. package/dist/services/deploy/handler/module-handler.d.ts +3 -1
  51. package/dist/services/deploy/handler/module-handler.js +7 -4
  52. package/dist/services/deploy/handler/module-handler.spec.d.ts +1 -0
  53. package/dist/services/deploy/handler/module-handler.spec.js +49 -0
  54. package/dist/services/deploy/handler/server-config-handler.d.ts +3 -1
  55. package/dist/services/deploy/handler/server-config-handler.js +6 -3
  56. package/dist/services/deploy/mr/base-config-reader.d.ts +25 -0
  57. package/dist/services/deploy/mr/base-config-reader.js +52 -0
  58. package/dist/services/deploy/mr/index.d.ts +6 -0
  59. package/dist/services/deploy/mr/index.js +6 -0
  60. package/dist/services/deploy/mr/live-state-check.d.ts +38 -0
  61. package/dist/services/deploy/mr/live-state-check.js +81 -0
  62. package/dist/services/deploy/mr/live-state-check.spec.d.ts +1 -0
  63. package/dist/services/deploy/mr/live-state-check.spec.js +74 -0
  64. package/dist/services/deploy/mr/merge-request-deploy-model.d.ts +59 -0
  65. package/dist/services/deploy/mr/merge-request-deploy-model.js +50 -0
  66. package/dist/services/deploy/mr/merge-request-deploy-service-factory.d.ts +20 -0
  67. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +46 -0
  68. package/dist/services/deploy/mr/merge-request-deploy-service.d.ts +61 -0
  69. package/dist/services/deploy/mr/merge-request-deploy-service.js +189 -0
  70. package/dist/services/deploy/mr/merge-request-description.d.ts +16 -0
  71. package/dist/services/deploy/mr/merge-request-description.js +27 -0
  72. package/dist/services/deploy/mr/merge-request-description.spec.d.ts +1 -0
  73. package/dist/services/deploy/mr/merge-request-description.spec.js +55 -0
  74. package/dist/services/deploy/policy/auto-deploy-policy.d.ts +43 -0
  75. package/dist/services/deploy/policy/auto-deploy-policy.js +77 -0
  76. package/dist/services/deploy/policy/auto-deploy-policy.spec.d.ts +1 -0
  77. package/dist/services/deploy/policy/auto-deploy-policy.spec.js +83 -0
  78. package/dist/services/deploy/policy/deploy-policy-model.d.ts +61 -0
  79. package/dist/services/deploy/policy/deploy-policy-model.js +41 -0
  80. package/dist/services/deploy/policy/index.d.ts +2 -0
  81. package/dist/services/deploy/policy/index.js +2 -0
  82. package/dist/services/deploy/policy/interactive-deploy-policy.d.ts +15 -0
  83. package/dist/services/deploy/policy/interactive-deploy-policy.js +16 -0
  84. package/dist/services/diff/diff-model.d.ts +5 -1
  85. package/dist/services/diff/diff-model.js +5 -1
  86. package/dist/services/diff/diff-service-factory.js +1 -1
  87. package/dist/services/diff/diff-service.d.ts +2 -1
  88. package/dist/services/diff/diff-service.js +6 -4
  89. package/dist/services/git/git-repository-model.d.ts +13 -0
  90. package/dist/services/git/git-repository-model.js +1 -0
  91. package/dist/services/git/git-repository.d.ts +35 -0
  92. package/dist/services/git/git-repository.js +120 -0
  93. package/dist/services/git/git-repository.spec.d.ts +1 -0
  94. package/dist/services/git/git-repository.spec.js +87 -0
  95. package/dist/services/git/index.d.ts +2 -0
  96. package/dist/services/git/index.js +2 -0
  97. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +1 -1
  98. package/oclif.manifest.json +140 -34
  99. package/package.json +1 -1
@@ -0,0 +1,50 @@
1
+ /** What `sk deploy --mr` is asked to deploy. */
2
+ export class MergeRequestDeployContext {
3
+ customerPath;
4
+ configName;
5
+ iid;
6
+ approval;
7
+ description;
8
+ dryRun;
9
+ skipPostDeployChecks;
10
+ interactive;
11
+ constructor(customerPath, configName,
12
+ /** The number of the merged merge request. */
13
+ iid, approval,
14
+ /** The description of the installations. It is asked while it is left out. */
15
+ description, dryRun = false,
16
+ /** Leave out the checks that run after the upload, as a bulk run does. */
17
+ skipPostDeployChecks = false,
18
+ /**
19
+ * Whether a person watches this deploy.
20
+ *
21
+ * They get the diff of every file the merge request changed, in the diff
22
+ * tool they use for every other deploy, and they confirm the upload.
23
+ */
24
+ interactive = false) {
25
+ this.customerPath = customerPath;
26
+ this.configName = configName;
27
+ this.iid = iid;
28
+ this.approval = approval;
29
+ this.description = description;
30
+ this.dryRun = dryRun;
31
+ this.skipPostDeployChecks = skipPostDeployChecks;
32
+ this.interactive = interactive;
33
+ }
34
+ }
35
+ /** What a deploy of one configuration ended with, or would end with. */
36
+ export var DeployOutcome;
37
+ (function (DeployOutcome) {
38
+ /** A plan only: the live installation is the state before the merge request. */
39
+ DeployOutcome["Deployable"] = "deployable";
40
+ /** The merge request changes nothing this configuration deploys. */
41
+ DeployOutcome["Unchanged"] = "unchanged";
42
+ /** The configuration was deployed. */
43
+ DeployOutcome["Applied"] = "applied";
44
+ /** The configuration was left to a developer. */
45
+ DeployOutcome["Skipped"] = "skipped";
46
+ /** The live installation already carried the merge request. */
47
+ DeployOutcome["AlreadyDeployed"] = "alreadyDeployed";
48
+ /** The deploy of the configuration failed. */
49
+ DeployOutcome["Failed"] = "failed";
50
+ })(DeployOutcome || (DeployOutcome = {}));
@@ -0,0 +1,20 @@
1
+ import { UserCliConfig } from "../../../helpers/cli-config.js";
2
+ import { GitRepository, MergedRequest } from "../../git/index.js";
3
+ import { MergeRequestDeployContext } from "./merge-request-deploy-model.js";
4
+ import { MergeRequestDeployService } from "./merge-request-deploy-service.js";
5
+ export declare class MergeRequestDeployServiceFactory {
6
+ private readonly context;
7
+ private readonly cliConfig;
8
+ /** The repository of the customer, while a caller resolved it already. */
9
+ private readonly repository?;
10
+ /** The merge request, while a caller looked it up already. */
11
+ private readonly request?;
12
+ private service?;
13
+ constructor(context: MergeRequestDeployContext, cliConfig: UserCliConfig,
14
+ /** The repository of the customer, while a caller resolved it already. */
15
+ repository?: GitRepository,
16
+ /** The merge request, while a caller looked it up already. */
17
+ request?: MergedRequest);
18
+ buildService(): Promise<MergeRequestDeployService>;
19
+ private build;
20
+ }
@@ -0,0 +1,46 @@
1
+ import { CliServiceFactory } from "../../cli/index.js";
2
+ import { DiffContext, DiffServiceFactory } from "../../diff/index.js";
3
+ import { GitRepository } from "../../git/index.js";
4
+ import { CustomerApprovalCheck } from "../checks/activation/customer-approval-check.js";
5
+ import DeployContext from "../context/deploy-context.js";
6
+ import DeployServiceFactory from "../deploy-service-factory.js";
7
+ import { AutoDeployPolicy } from "../policy/auto-deploy-policy.js";
8
+ import { BaseConfigReader } from "./base-config-reader.js";
9
+ import { LiveStateCheck } from "./live-state-check.js";
10
+ import { MergeRequestDeployService } from "./merge-request-deploy-service.js";
11
+ import { resolveDescription } from "./merge-request-description.js";
12
+ export class MergeRequestDeployServiceFactory {
13
+ context;
14
+ cliConfig;
15
+ repository;
16
+ request;
17
+ service = undefined;
18
+ constructor(context, cliConfig,
19
+ /** The repository of the customer, while a caller resolved it already. */
20
+ repository,
21
+ /** The merge request, while a caller looked it up already. */
22
+ request) {
23
+ this.context = context;
24
+ this.cliConfig = cliConfig;
25
+ this.repository = repository;
26
+ this.request = request;
27
+ }
28
+ async buildService() {
29
+ if (!(this.service instanceof MergeRequestDeployService)) {
30
+ await this.build();
31
+ }
32
+ return this.service;
33
+ }
34
+ async build() {
35
+ const repository = this.repository ?? GitRepository.at(this.context.customerPath);
36
+ const request = this.request ?? repository.mergeRequest(this.context.iid);
37
+ const cliService = new CliServiceFactory().getService();
38
+ const policy = new AutoDeployPolicy(await resolveDescription(cliService, request, this.context.description), this.context.approval, this.context.interactive ? cliService : undefined);
39
+ const deployFactory = new DeployServiceFactory(new DeployContext(this.context.customerPath, this.context.configName, undefined, this.context.dryRun, false, true, this.context.skipPostDeployChecks, this.context.interactive), this.cliConfig, policy);
40
+ const deployService = await deployFactory.buildService();
41
+ // A deploy that runs without a person never opens a diff tool, so the
42
+ // comparison only tells whether two contents are equal.
43
+ const diffService = new DiffServiceFactory(new DiffContext(null, null, false)).getService();
44
+ this.service = new MergeRequestDeployService(this.context, request, repository, new BaseConfigReader(repository, this.cliConfig), new LiveStateCheck(diffService), new CustomerApprovalCheck(cliService, deployFactory.files.getCustomerConfig().config, policy), deployFactory.configApi, deployFactory.files, deployFactory.configName, deployService);
45
+ }
46
+ }
@@ -0,0 +1,61 @@
1
+ import { ConfigApiService } from "../../config-api/index.js";
2
+ import { GitRepository, MergedRequest } from "../../git/index.js";
3
+ import { FileListInterface } from "../../integration-api/index.js";
4
+ import { CustomerApprovalCheck } from "../checks/activation/customer-approval-check.js";
5
+ import DeployService from "../deploy-service.js";
6
+ import { BaseConfigReader } from "./base-config-reader.js";
7
+ import { LiveStateCheck } from "./live-state-check.js";
8
+ import { MergeRequestDeployContext, MergeRequestDeployResult } from "./merge-request-deploy-model.js";
9
+ /**
10
+ * Deploys one customer configuration of a merged merge request.
11
+ *
12
+ * The deploy runs only while the live installation still is the state before
13
+ * the merge request. The merge request is then the only change it applies, and
14
+ * a reviewer has seen all of it. Every other case ends as a skip with a reason,
15
+ * so a developer can take the configuration over.
16
+ */
17
+ export declare class MergeRequestDeployService {
18
+ private readonly context;
19
+ private readonly request;
20
+ private readonly repository;
21
+ private readonly baseReader;
22
+ private readonly liveStateCheck;
23
+ private readonly approvalCheck;
24
+ private readonly configApi;
25
+ private readonly files;
26
+ private readonly configName;
27
+ private readonly deployService;
28
+ constructor(context: MergeRequestDeployContext, request: MergedRequest, repository: GitRepository, baseReader: BaseConfigReader, liveStateCheck: LiveStateCheck, approvalCheck: CustomerApprovalCheck, configApi: ConfigApiService, files: FileListInterface, configName: string, deployService: DeployService);
29
+ /** Plans the deploy and runs it while the plan allows it. */
30
+ run(): Promise<MergeRequestDeployResult>;
31
+ /**
32
+ * What a deploy of this configuration would do, without writing anything.
33
+ *
34
+ * An outcome of `deployable` means the live installation still is the state
35
+ * before the merge request. Every other outcome carries its reason.
36
+ */
37
+ plan(): Promise<MergeRequestDeployResult>;
38
+ /** The reason that stops the deploy before it writes anything, if any. */
39
+ private blockingState;
40
+ /** How the live installation relates to the merge request. */
41
+ private liveState;
42
+ /** Runs the deploy itself and turns its outcome into a result. */
43
+ private deploy;
44
+ /**
45
+ * Whether the activation is settled for a customer that approves rollouts.
46
+ *
47
+ * The question is answered before the deploy writes anything, so a
48
+ * configuration that has to wait for the customer stays untouched.
49
+ */
50
+ private isApprovalSettled;
51
+ /**
52
+ * The files of the merge request that this deploy never uploads.
53
+ *
54
+ * Modules and the server config are two of them, and so is a file of another
55
+ * environment than the one this deploy runs. Files that no deploy ever
56
+ * uploads, such as a test or the page examples, are left out.
57
+ */
58
+ private notDeployed;
59
+ private skip;
60
+ private result;
61
+ }
@@ -0,0 +1,189 @@
1
+ import { DEFAULT_BLOCKED_FILES, DEFAULT_BLOCKED_FOLDERS, } from "../../integration-api/index.js";
2
+ import { DeployAbortedError } from "../error/deploy-aborted-error.js";
3
+ import { ApprovalAnswer } from "../policy/auto-deploy-policy.js";
4
+ import { LiveState } from "./live-state-check.js";
5
+ import { DeployOutcome, } from "./merge-request-deploy-model.js";
6
+ /** The install resource key that holds config_SpeedKit.js. */
7
+ const SPEED_KIT_CONFIG_KEY = "config";
8
+ /** The extensions a customer configuration is written in. */
9
+ const DEPLOYABLE_EXTENSIONS = new Set(["js", "es6", "json", "css"]);
10
+ /** Whether any deploy of this repository would ever upload the file. */
11
+ function isDeployable(filePath) {
12
+ const segments = filePath.split("/");
13
+ const fileName = segments.pop();
14
+ if (segments.some((segment) => DEFAULT_BLOCKED_FOLDERS.includes(segment))) {
15
+ return false;
16
+ }
17
+ if (DEFAULT_BLOCKED_FILES.some((blocked) => fileName.includes(blocked))) {
18
+ return false;
19
+ }
20
+ return DEPLOYABLE_EXTENSIONS.has(fileName.split(".").pop());
21
+ }
22
+ /**
23
+ * Deploys one customer configuration of a merged merge request.
24
+ *
25
+ * The deploy runs only while the live installation still is the state before
26
+ * the merge request. The merge request is then the only change it applies, and
27
+ * a reviewer has seen all of it. Every other case ends as a skip with a reason,
28
+ * so a developer can take the configuration over.
29
+ */
30
+ export class MergeRequestDeployService {
31
+ context;
32
+ request;
33
+ repository;
34
+ baseReader;
35
+ liveStateCheck;
36
+ approvalCheck;
37
+ configApi;
38
+ files;
39
+ configName;
40
+ deployService;
41
+ constructor(context, request, repository, baseReader, liveStateCheck, approvalCheck, configApi, files, configName, deployService) {
42
+ this.context = context;
43
+ this.request = request;
44
+ this.repository = repository;
45
+ this.baseReader = baseReader;
46
+ this.liveStateCheck = liveStateCheck;
47
+ this.approvalCheck = approvalCheck;
48
+ this.configApi = configApi;
49
+ this.files = files;
50
+ this.configName = configName;
51
+ this.deployService = deployService;
52
+ }
53
+ /** Plans the deploy and runs it while the plan allows it. */
54
+ async run() {
55
+ const plan = await this.plan();
56
+ if (plan.outcome !== DeployOutcome.Deployable) {
57
+ return plan;
58
+ }
59
+ return this.deploy(plan.notDeployed);
60
+ }
61
+ /**
62
+ * What a deploy of this configuration would do, without writing anything.
63
+ *
64
+ * An outcome of `deployable` means the live installation still is the state
65
+ * before the merge request. Every other outcome carries its reason.
66
+ */
67
+ async plan() {
68
+ const directory = this.repository.relative(this.context.customerPath);
69
+ const changedPaths = this.repository
70
+ .changedPaths(this.request)
71
+ .filter((path) => path.startsWith(`${directory}/`));
72
+ if (changedPaths.length === 0) {
73
+ return this.skip(`!${this.request.iid} changes nothing in ${directory}`);
74
+ }
75
+ const notDeployed = this.notDeployed(changedPaths);
76
+ const blocked = await this.blockingState(directory);
77
+ return blocked
78
+ ? { ...blocked, notDeployed }
79
+ : { ...this.result(DeployOutcome.Deployable), notDeployed };
80
+ }
81
+ /** The reason that stops the deploy before it writes anything, if any. */
82
+ async blockingState(directory) {
83
+ const uncommitted = this.repository.uncommittedChanges(directory);
84
+ if (uncommitted.length > 0) {
85
+ return this.skip(`the working tree changes ${uncommitted.join(", ")}`);
86
+ }
87
+ const laterChanges = this.repository.changesSince(this.request.sha, directory);
88
+ if (laterChanges.length > 0) {
89
+ return this.skip(`commits after !${this.request.iid} change ${laterChanges.join(", ")}`);
90
+ }
91
+ if (!(await this.isApprovalSettled())) {
92
+ return this.skip("the customer approves every rollout themselves");
93
+ }
94
+ return this.liveState(directory);
95
+ }
96
+ /** How the live installation relates to the merge request. */
97
+ async liveState(directory) {
98
+ const base = await this.baseReader.read(this.context.customerPath, this.context.configName, this.request.baseSha);
99
+ if (!base) {
100
+ return this.skip(`!${this.request.iid} creates ${directory}`);
101
+ }
102
+ if (this.liveStateCheck.isUnchanged(base, this.files)) {
103
+ return {
104
+ ...this.result(DeployOutcome.Unchanged),
105
+ reason: `!${this.request.iid} changes nothing of ${this.configName}`,
106
+ };
107
+ }
108
+ const install = await this.configApi.getActiveInstall(this.configName);
109
+ const { state, driftedFiles } = this.liveStateCheck.compare(base, this.files, install);
110
+ switch (state) {
111
+ case LiveState.Reviewed: {
112
+ return null;
113
+ }
114
+ case LiveState.AlreadyDeployed: {
115
+ return {
116
+ ...this.result(DeployOutcome.AlreadyDeployed),
117
+ reason: `!${this.request.iid} is live already`,
118
+ };
119
+ }
120
+ case LiveState.Missing: {
121
+ return this.skip(`no active installation named ${this.configName}`);
122
+ }
123
+ default: {
124
+ return this.skip(`live changes that never reached git: ${driftedFiles.join(", ")}`);
125
+ }
126
+ }
127
+ }
128
+ /** Runs the deploy itself and turns its outcome into a result. */
129
+ async deploy(notDeployed) {
130
+ try {
131
+ await this.deployService.run();
132
+ }
133
+ catch (error) {
134
+ if (error instanceof DeployAbortedError) {
135
+ return { ...this.skip(error.reason), notDeployed };
136
+ }
137
+ return {
138
+ ...this.result(DeployOutcome.Failed),
139
+ reason: error.message,
140
+ notDeployed,
141
+ };
142
+ }
143
+ return { ...this.result(DeployOutcome.Applied), notDeployed };
144
+ }
145
+ /**
146
+ * Whether the activation is settled for a customer that approves rollouts.
147
+ *
148
+ * The question is answered before the deploy writes anything, so a
149
+ * configuration that has to wait for the customer stays untouched.
150
+ */
151
+ async isApprovalSettled() {
152
+ if (this.context.approval !== ApprovalAnswer.Skip) {
153
+ return true;
154
+ }
155
+ const speedKitConfig = this.files
156
+ .getInstallResources()
157
+ .find((file) => file.remoteKey === SPEED_KIT_CONFIG_KEY);
158
+ const local = {
159
+ domain: this.configName,
160
+ [SPEED_KIT_CONFIG_KEY]: speedKitConfig?.getContent(),
161
+ };
162
+ return this.approvalCheck.isActivationApproved(local);
163
+ }
164
+ /**
165
+ * The files of the merge request that this deploy never uploads.
166
+ *
167
+ * Modules and the server config are two of them, and so is a file of another
168
+ * environment than the one this deploy runs. Files that no deploy ever
169
+ * uploads, such as a test or the page examples, are left out.
170
+ */
171
+ notDeployed(changedPaths) {
172
+ // A virtual file has no path, and no deploy reads it from the repository.
173
+ const deployed = new Set(this.files.files
174
+ .map((file) => file.path)
175
+ .filter(Boolean)
176
+ .map((filePath) => this.repository.relative(filePath)));
177
+ return changedPaths.filter((path) => isDeployable(path) && !deployed.has(path));
178
+ }
179
+ skip(reason) {
180
+ return { ...this.result(DeployOutcome.Skipped), reason };
181
+ }
182
+ result(outcome) {
183
+ return {
184
+ customerPath: this.context.customerPath,
185
+ configName: this.configName,
186
+ outcome,
187
+ };
188
+ }
189
+ }
@@ -0,0 +1,16 @@
1
+ import { CliServiceInterface } from "../../cli/index.js";
2
+ import { MergedRequest } from "../../git/index.js";
3
+ /**
4
+ * The title of the merge request, as a description of the installation.
5
+ *
6
+ * The type and the component say what the change is for the repository, not
7
+ * what the installation holds, so they are left out.
8
+ */
9
+ export declare function defaultDescription(request: MergedRequest): string;
10
+ /**
11
+ * The description every installation of this run gets.
12
+ *
13
+ * The flag answers for a run that nobody watches. Without it the description
14
+ * is asked once, with the title of the merge request as the default.
15
+ */
16
+ export declare function resolveDescription(cli: CliServiceInterface, request: MergedRequest, description?: string): Promise<string>;
@@ -0,0 +1,27 @@
1
+ /** The type and the component a conventional commit starts with. */
2
+ const CONVENTIONAL_PREFIX = /^\w+(\([^)]*\))?!?:\s*/;
3
+ /**
4
+ * The title of the merge request, as a description of the installation.
5
+ *
6
+ * The type and the component say what the change is for the repository, not
7
+ * what the installation holds, so they are left out.
8
+ */
9
+ export function defaultDescription(request) {
10
+ const title = request.title.replace(CONVENTIONAL_PREFIX, "").trim();
11
+ return title.length > 0 ? title : `!${request.iid}`;
12
+ }
13
+ /**
14
+ * The description every installation of this run gets.
15
+ *
16
+ * The flag answers for a run that nobody watches. Without it the description
17
+ * is asked once, with the title of the merge request as the default.
18
+ */
19
+ export async function resolveDescription(cli, request, description) {
20
+ if (description?.trim()) {
21
+ return description.trim();
22
+ }
23
+ return cli.prompt("Describe new configuration:", {
24
+ defaultAnswer: defaultDescription(request),
25
+ validator: (input) => input.trim() ? "" : "Please enter something",
26
+ });
27
+ }
@@ -0,0 +1,55 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { defaultDescription, resolveDescription, } from "./merge-request-description.js";
4
+ function request(title) {
5
+ return { iid: 8009, sha: "3aaa523", baseSha: "83d9d58", title };
6
+ }
7
+ /** Records every question and answers it with its own default. */
8
+ function cliAnswering() {
9
+ const questions = [];
10
+ const cli = {
11
+ prompt: async (message, options) => {
12
+ questions.push({ message, defaultAnswer: options.defaultAnswer });
13
+ return options.defaultAnswer;
14
+ },
15
+ };
16
+ return { cli, questions };
17
+ }
18
+ describe("defaultDescription", () => {
19
+ it("leaves out the type and the component", () => {
20
+ expect(defaultDescription(request("chore(gohaus): update from production"))).to.equal("update from production");
21
+ });
22
+ it("leaves out a type that marks a breaking change", () => {
23
+ expect(defaultDescription(request("feat!: drop the loader"))).to.equal("drop the loader");
24
+ });
25
+ it("keeps a title that is no conventional commit", () => {
26
+ expect(defaultDescription(request("chore/haar-shop_update-from-prod"))).to.equal("chore/haar-shop_update-from-prod");
27
+ });
28
+ it("falls back to the number of an empty title", () => {
29
+ expect(defaultDescription(request("fix: "))).to.equal("!8009");
30
+ });
31
+ });
32
+ describe("resolveDescription", () => {
33
+ it("takes the flag without asking", async () => {
34
+ const { cli, questions } = cliAnswering();
35
+ const description = await resolveDescription(cli, request("chore(gohaus): update from production"), " the rollout of the new handler ");
36
+ expect(description).to.equal("the rollout of the new handler");
37
+ expect(questions).to.deep.equal([]);
38
+ });
39
+ it("asks once while the flag is left out", async () => {
40
+ const { cli, questions } = cliAnswering();
41
+ const description = await resolveDescription(cli, request("chore(gohaus): update from production"));
42
+ expect(description).to.equal("update from production");
43
+ expect(questions).to.deep.equal([
44
+ {
45
+ message: "Describe new configuration:",
46
+ defaultAnswer: "update from production",
47
+ },
48
+ ]);
49
+ });
50
+ it("asks while the flag holds nothing but spaces", async () => {
51
+ const { cli, questions } = cliAnswering();
52
+ await resolveDescription(cli, request("fix(gohaus): a fix"), " ");
53
+ expect(questions).to.have.length(1);
54
+ });
55
+ });
@@ -0,0 +1,43 @@
1
+ import { CliServiceInterface } from "../../cli/index.js";
2
+ import { DeployPolicyInterface, DeployQuestion } from "./deploy-policy-model.js";
3
+ /** What the operator answered for the customers that approve their rollouts. */
4
+ export declare enum ApprovalAnswer {
5
+ /** The customers approved this change, so the installation goes live. */
6
+ Approved = "approved",
7
+ /** The installation goes live under the debug parameter only. */
8
+ Testing = "testing",
9
+ /** The configurations that need an approval are not deployed at all. */
10
+ Skip = "skip"
11
+ }
12
+ /**
13
+ * The policy of a deploy that runs without a person.
14
+ *
15
+ * Every question that the merge request already answers is confirmed: the live
16
+ * installation was compared with the state before the merge request, so the
17
+ * deploy applies exactly the reviewed change. Every question that the merge
18
+ * request cannot answer is declined, which stops this configuration and leaves
19
+ * it to a developer.
20
+ */
21
+ export declare class AutoDeployPolicy implements DeployPolicyInterface {
22
+ private readonly description;
23
+ private readonly approval;
24
+ /**
25
+ * The person who watches this deploy, if any.
26
+ *
27
+ * The diff of every changed file opens for them, so the upload itself is
28
+ * theirs to confirm. Without them the upload needs no question, because
29
+ * the merge request already answers it.
30
+ */
31
+ private readonly cli?;
32
+ constructor(description: string, approval: ApprovalAnswer,
33
+ /**
34
+ * The person who watches this deploy, if any.
35
+ *
36
+ * The diff of every changed file opens for them, so the upload itself is
37
+ * theirs to confirm. Without them the upload needs no question, because
38
+ * the merge request already answers it.
39
+ */
40
+ cli?: CliServiceInterface);
41
+ confirm(question: DeployQuestion, message?: string): Promise<boolean>;
42
+ text(question: DeployQuestion): Promise<string>;
43
+ }
@@ -0,0 +1,77 @@
1
+ import { DeployQuestion, } from "./deploy-policy-model.js";
2
+ /** What the operator answered for the customers that approve their rollouts. */
3
+ export var ApprovalAnswer;
4
+ (function (ApprovalAnswer) {
5
+ /** The customers approved this change, so the installation goes live. */
6
+ ApprovalAnswer["Approved"] = "approved";
7
+ /** The installation goes live under the debug parameter only. */
8
+ ApprovalAnswer["Testing"] = "testing";
9
+ /** The configurations that need an approval are not deployed at all. */
10
+ ApprovalAnswer["Skip"] = "skip";
11
+ })(ApprovalAnswer || (ApprovalAnswer = {}));
12
+ /**
13
+ * The policy of a deploy that runs without a person.
14
+ *
15
+ * Every question that the merge request already answers is confirmed: the live
16
+ * installation was compared with the state before the merge request, so the
17
+ * deploy applies exactly the reviewed change. Every question that the merge
18
+ * request cannot answer is declined, which stops this configuration and leaves
19
+ * it to a developer.
20
+ */
21
+ export class AutoDeployPolicy {
22
+ description;
23
+ approval;
24
+ cli;
25
+ constructor(description, approval,
26
+ /**
27
+ * The person who watches this deploy, if any.
28
+ *
29
+ * The diff of every changed file opens for them, so the upload itself is
30
+ * theirs to confirm. Without them the upload needs no question, because
31
+ * the merge request already answers it.
32
+ */
33
+ cli) {
34
+ this.description = description;
35
+ this.approval = approval;
36
+ this.cli = cli;
37
+ }
38
+ async confirm(question, message) {
39
+ switch (question) {
40
+ // The one question a watching person answers, after the diffs.
41
+ case DeployQuestion.UploadInstallResource: {
42
+ return this.cli
43
+ ? this.cli.confirm(message ?? "Upload the new installation?", true)
44
+ : true;
45
+ }
46
+ // The reviewed change itself.
47
+ case DeployQuestion.UpdateFile:
48
+ case DeployQuestion.UpdateOrigins:
49
+ case DeployQuestion.DeleteInstallResourceKey:
50
+ case DeployQuestion.UploadModules:
51
+ case DeployQuestion.UploadServerConfig: {
52
+ return true;
53
+ }
54
+ // A reviewed change goes live. A customer who approves every rollout
55
+ // is asked first, and the answer decides for that customer alone.
56
+ case DeployQuestion.Activate: {
57
+ return true;
58
+ }
59
+ case DeployQuestion.CustomerApproval: {
60
+ return this.approval === ApprovalAnswer.Approved;
61
+ }
62
+ case DeployQuestion.ActivateAsTesting: {
63
+ return this.approval === ApprovalAnswer.Testing;
64
+ }
65
+ // Decisions a merge request never carries.
66
+ default: {
67
+ return false;
68
+ }
69
+ }
70
+ }
71
+ async text(question) {
72
+ if (question === DeployQuestion.Description) {
73
+ return this.description;
74
+ }
75
+ return "";
76
+ }
77
+ }