Skip to content

Commit

Permalink
Merge pull request #27 from Microsoft/nturinski/bug22
Browse files Browse the repository at this point in the history
Nturinski/bug22
  • Loading branch information
nturinski authored Nov 27, 2017
2 parents a7c51b6 + 73f0a8f commit e83153b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
13 changes: 13 additions & 0 deletions appservice/src/DialogResponses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { MessageItem } from 'vscode';
import { localize } from './localize';

export namespace DialogResponses {
export const yes: MessageItem = { title: localize('Yes', 'Yes') };
export const no: MessageItem = { title: localize('No', 'No') };
export const cancel: MessageItem = { title: localize('Cancel', 'Cancel'), isCloseAffordance: true };
}
24 changes: 11 additions & 13 deletions appservice/src/SiteWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import * as git from 'simple-git/promise';
import * as vscode from 'vscode';
import KuduClient from 'vscode-azurekudu';
import { DeployResult } from 'vscode-azurekudu/lib/models';
import { DialogResponses} from './DialogResponses';
import { ArgumentError } from './errors';
import * as FileUtilities from './FileUtilities';
import { localize } from './localize';

// Deployment sources supported by Web Apps
const SCM_TYPES: vscode.QuickPickItem[] = [
{ label: 'None', description: ''}, // default scmType config
{ label: 'LocalGit', description: ''}
{ label: 'None', description: '' }, // default scmType config
{ label: 'LocalGit', description: '' }
];

export class SiteWrapper {
Expand All @@ -33,9 +34,6 @@ export class SiteWrapper {
public readonly id: string;
private readonly _gitUrl: string;

private readonly _yes: string = localize('Yes', 'Yes');
private readonly _no: string = localize('No', 'No');

constructor(site: Site) {
const matches: RegExpMatchArray | null = site.serverFarmId.match(/\/subscriptions\/(.*)\/resourceGroups\/(.*)\/providers\/Microsoft.Web\/serverfarms\/(.*)/);
if (!site.id || !site.name || !site.resourceGroup || !site.type || matches === null || matches.length < 4) {
Expand Down Expand Up @@ -107,7 +105,7 @@ export class SiteWrapper {

public async deleteSite(client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<void> {
const confirmMessage: string = localize('deleteConfirmation', 'Are you sure you want to delete "{0}"?', this.appName);
if (await vscode.window.showWarningMessage(confirmMessage, this._yes) !== this._yes) {
if (await vscode.window.showWarningMessage(confirmMessage, DialogResponses.yes, DialogResponses.cancel) !== DialogResponses.yes) {
return;
}

Expand All @@ -121,11 +119,11 @@ export class SiteWrapper {

if (!this.slotName && plan.numberOfSites < 2) {
const message: string = localize('deleteLastServicePlan', 'This is the last app in the App Service plan "{0}". Do you want to delete this App Service plan to prevent unexpected charges?', plan.name);
const input: string | undefined = await vscode.window.showWarningMessage(message, this._yes, this._no);
const input: vscode.MessageItem | undefined = await vscode.window.showWarningMessage(message, DialogResponses.yes, DialogResponses.no, DialogResponses.cancel);
if (input === undefined) {
return;
} else {
deletePlan = input === this._yes;
deletePlan = input === DialogResponses.yes;
}
}

Expand All @@ -141,7 +139,7 @@ export class SiteWrapper {

public async deployZip(fsPath: string, client: WebSiteManagementClient, outputChannel: vscode.OutputChannel): Promise<void> {
const warning: string = localize('zipWarning', 'Are you sure you want to deploy to "{0}"? This will overwrite any previous deployment and cannot be undone.', this.appName);
if (await vscode.window.showWarningMessage(warning, this._yes) !== this._yes) {
if (await vscode.window.showWarningMessage(warning, DialogResponses.yes, DialogResponses.cancel) !== DialogResponses.yes) {
return;
}

Expand Down Expand Up @@ -206,8 +204,8 @@ export class SiteWrapper {
await this.showInstallPrompt();
return undefined;
} else if (err.message.indexOf('error: failed to push') >= 0) { // tslint:disable-line:no-unsafe-any
const input: string | undefined = await vscode.window.showErrorMessage(pushReject, this._yes);
if (input === this._yes) {
const input: vscode.MessageItem | undefined = await vscode.window.showErrorMessage(pushReject, DialogResponses.yes, DialogResponses.cancel);
if (input === DialogResponses.yes) {
await (<(remote: string, branch: string, options: object) => Promise<void>>localGit.push)(remote, 'HEAD:master', { '-f': true });
// Ugly casting neccessary due to bug in simple-git. Issue filed:
// https://github.com/steveukx/git-js/issues/218
Expand Down Expand Up @@ -257,11 +255,11 @@ export class SiteWrapper {
return new KuduClient(cred, `https://${this.appName}.scm.azurewebsites.net`);
}

public async editScmType(client: WebSiteManagementClient): Promise<string> {
public async editScmType(client: WebSiteManagementClient): Promise<string | undefined> {
const config: SiteConfigResource = await this.getSiteConfig(client);
const newScmType: string = await this.showScmPrompt(config.scmType);
// returns the updated scmType
return await this.updateScmType(client, config, newScmType);
return newScmType ? await this.updateScmType(client, config, newScmType) : undefined;
}

private async showScmPrompt(currentScmType: string): Promise<string | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion appservice/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class WizardFailedError extends Error {

export class ArgumentError extends Error {
constructor(obj: object) {
super(localize('azFunc.argumentError', 'Invalid {0}.', obj.constructor.name));
super(localize('argumentError', 'Invalid {0}.', obj.constructor.name));
}
}

0 comments on commit e83153b

Please sign in to comment.