-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathShouldSaveDeploySettingsPromptStep.ts
More file actions
74 lines (61 loc) · 4.14 KB
/
ShouldSaveDeploySettingsPromptStep.ts
File metadata and controls
74 lines (61 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzureWizardPromptStep, nonNullProp } from "@microsoft/vscode-azext-utils";
import * as path from "path";
import { type WorkspaceFolder } from "vscode";
import { localize } from "../../../utils/localize";
import { type DeploymentConfigurationSettings } from "../settings/DeployWorkspaceProjectSettingsV2";
import { dwpSettingUtilsV2 } from "../settings/dwpSettingUtilsV2";
import { type DeployWorkspaceProjectInternalContext } from "./DeployWorkspaceProjectInternalContext";
export class ShouldSaveDeploySettingsPromptStep extends AzureWizardPromptStep<DeployWorkspaceProjectInternalContext> {
public async prompt(context: DeployWorkspaceProjectInternalContext): Promise<void> {
if (context.configurationIdx !== undefined) {
const rootFolder: WorkspaceFolder = nonNullProp(context, 'rootFolder');
const rootPath: string = rootFolder.uri.fsPath;
const settings: DeploymentConfigurationSettings[] | undefined = await dwpSettingUtilsV2.getWorkspaceDeploymentConfigurations(rootFolder);
const setting: DeploymentConfigurationSettings | undefined = settings?.[context.configurationIdx];
const hasNewResourceGroupSetting: boolean = (!!context.newResourceGroupName && setting?.resourceGroup !== context.newResourceGroupName) ||
(!!context.resourceGroup && setting?.resourceGroup !== context.resourceGroup.name);
const hasNewContainerAppSetting: boolean = (!!context.newContainerAppName && setting?.containerApp !== context.newContainerAppName) ||
(!!context.containerApp && setting?.containerApp !== context.containerApp.name);
const hasNewRegistrySetting: boolean = (!!context.newRegistryName && setting?.containerRegistry !== context.newRegistryName) ||
(!!context.registry && setting?.containerRegistry !== context.registry.name);
const hasNewSettings: boolean =
!setting?.label ||
setting?.type !== 'AcrDockerBuildRequest' ||
(context.dockerfilePath && convertRelativeToAbsolutePath(rootPath, setting?.dockerfilePath) !== context.dockerfilePath) ||
(context.envPath && convertRelativeToAbsolutePath(rootPath, setting?.envPath) !== context.envPath) ||
(context.srcPath && convertRelativeToAbsolutePath(rootPath, setting?.srcPath) !== context.srcPath) ||
hasNewResourceGroupSetting ||
hasNewContainerAppSetting ||
hasNewRegistrySetting;
if (!hasNewSettings) {
context.telemetry.properties.hasNewSettings = 'false';
return;
}
}
context.telemetry.properties.hasNewSettings = 'true';
const saveOrOverwrite: string = context.configurationIdx ? localize('overwrite', 'overwrite') : localize('save', 'save');
const saveItem = { title: localize('saveItem', 'Save') };
const dontSaveItem = { title: localize('dontSaveItem', 'Don\'t Save') };
const userResponse = await context.ui.showWarningMessage(
localize('saveWorkspaceSettings', `Would you like to ${saveOrOverwrite} your deployment configuration in local project settings?`),
{ modal: true },
saveItem,
dontSaveItem
);
context.shouldSaveDeploySettings = userResponse === saveItem;
context.telemetry.properties.shouldSaveDeploySettings = context.shouldSaveDeploySettings ? 'true' : 'false';
}
public shouldPrompt(context: DeployWorkspaceProjectInternalContext): boolean {
return context.shouldSaveDeploySettings === undefined;
}
}
function convertRelativeToAbsolutePath(rootPath: string, relativePath: string | undefined): string | undefined {
if (!relativePath) {
return undefined;
}
return path.join(rootPath, relativePath);
}