Skip to content

Commit d208636

Browse files
authored
Update disconnectRepo and add a new confirm prompt step (#434)
1 parent d92f0d2 commit d208636

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { gitHubUrlParse } from "@microsoft/vscode-azext-github";
7+
import { AzureWizardPromptStep, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
8+
import { localize } from "../../../utils/localize";
9+
import type { IDisconnectRepoContext } from "./IDisconnectRepoContext";
10+
11+
export class DisconnectRepositoryConfirmStep extends AzureWizardPromptStep<IDisconnectRepoContext> {
12+
public async prompt(context: IDisconnectRepoContext): Promise<void> {
13+
const { ownerOrOrganization: owner, repositoryName: repo } = gitHubUrlParse(nonNullValueAndProp(context.sourceControl, 'repoUrl'));
14+
15+
await context.ui.showWarningMessage(
16+
localize('disconnectRepositoryWarning', 'Disconnect from GitHub repository "{0}"? \n\nThis will not affect your container app\'s active deployment. You may reconnect a repository at any time.', `${owner}/${repo}`),
17+
{ modal: true },
18+
{ title: localize('continue', 'Continue') }
19+
);
20+
}
21+
22+
public shouldPrompt(context: IDisconnectRepoContext): boolean {
23+
return !!context.sourceControl;
24+
}
25+
}

src/commands/gitHub/disconnectRepo/GitHubRepositoryDisconnectStep.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,22 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import type { ContainerAppsAPIClient, SourceControl } from "@azure/arm-appcontainers";
6+
import type { ContainerAppsAPIClient } from "@azure/arm-appcontainers";
77
import { gitHubUrlParse } from "@microsoft/vscode-azext-github";
8-
import { AzureWizardExecuteStep, nonNullProp, nonNullValue } from "@microsoft/vscode-azext-utils";
8+
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
99
import type { Progress } from "vscode";
1010
import { ext } from "../../../extensionVariables";
1111
import { createContainerAppsClient } from "../../../utils/azureClients";
1212
import { localize } from "../../../utils/localize";
13-
import { getContainerAppSourceControl } from "../connectToGitHub/getContainerAppSourceControl";
1413
import type { IDisconnectRepoContext } from "./IDisconnectRepoContext";
1514

1615
export class GitHubRepositoryDisconnectStep extends AzureWizardExecuteStep<IDisconnectRepoContext> {
1716
public priority: number = 300;
1817

1918
public async execute(context: IDisconnectRepoContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
2019
const client: ContainerAppsAPIClient = await createContainerAppsClient(context, context.subscription);
21-
const sourceControl: SourceControl | undefined = await getContainerAppSourceControl(context, context.subscription, context.containerApp);
2220

23-
const { ownerOrOrganization: owner, repositoryName: repo } = gitHubUrlParse(nonNullValue(sourceControl?.repoUrl));
21+
const { ownerOrOrganization: owner, repositoryName: repo } = gitHubUrlParse(nonNullValueAndProp(context.sourceControl, 'repoUrl'));
2422

2523
const rgName: string = context.containerApp.resourceGroup;
2624
const caName: string = context.containerApp.name;
@@ -42,7 +40,7 @@ export class GitHubRepositoryDisconnectStep extends AzureWizardExecuteStep<IDisc
4240
ext.outputChannel.appendLog(disconnected);
4341
}
4442

45-
public shouldExecute(): boolean {
46-
return true;
43+
public shouldExecute(context: IDisconnectRepoContext): boolean {
44+
return !!context.sourceControl;
4745
}
4846
}

src/commands/gitHub/disconnectRepo/IDisconnectRepoContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import type { SourceControl } from "@azure/arm-appcontainers";
67
import type { GitHubContext } from "@microsoft/vscode-azext-github";
78
import type { ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
89
import type { ContainerAppModel } from "../../../tree/ContainerAppItem";
@@ -11,4 +12,5 @@ import type { IContainerAppContext } from "../../IContainerAppContext";
1112
export interface IDisconnectRepoContext extends IContainerAppContext, GitHubContext, ExecuteActivityContext {
1213
// Make containerApp _required_
1314
containerApp: ContainerAppModel;
15+
sourceControl?: SourceControl;
1416
}

src/commands/gitHub/disconnectRepo/disconnectRepo.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { getGitHubAccessToken } from "@microsoft/vscode-azext-github";
7-
import { AzureWizard, AzureWizardExecuteStep, ITreeItemPickerContext, createSubscriptionContext } from "@microsoft/vscode-azext-utils";
7+
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, ITreeItemPickerContext, createSubscriptionContext } from "@microsoft/vscode-azext-utils";
88
import { ContainerAppsItem } from "../../../tree/ContainerAppsBranchDataProvider";
99
import { ActionsItem } from "../../../tree/configurations/ActionsItem";
1010
import { createActivityContext } from "../../../utils/activityUtils";
1111
import { localize } from "../../../utils/localize";
1212
import { pickContainerApp } from "../../../utils/pickItem/pickContainerApp";
13-
import { isGitHubConnected } from "../connectToGitHub/isGitHubConnected";
13+
import { getContainerAppSourceControl } from "../connectToGitHub/getContainerAppSourceControl";
14+
import { DisconnectRepositoryConfirmStep } from "./DisconnectRepositoryConfirmStep";
1415
import { GitHubRepositoryDisconnectStep } from "./GitHubRepositoryDisconnectStep";
1516
import { IDisconnectRepoContext } from "./IDisconnectRepoContext";
1617

17-
export async function disconnectRepo(context: ITreeItemPickerContext & Partial<IDisconnectRepoContext>, node?: ContainerAppsItem | ActionsItem): Promise<void> {
18+
export async function disconnectRepo(context: ITreeItemPickerContext, node?: ContainerAppsItem | ActionsItem): Promise<void> {
1819
if (!node) {
1920
context.suppressCreatePick = true;
2021
node = await pickContainerApp(context);
@@ -28,27 +29,30 @@ export async function disconnectRepo(context: ITreeItemPickerContext & Partial<I
2829
...await createActivityContext(),
2930
subscription,
3031
containerApp,
31-
gitHubAccessToken: await getGitHubAccessToken()
32+
gitHubAccessToken: await getGitHubAccessToken(),
33+
sourceControl: await getContainerAppSourceControl(context, subscription, containerApp)
3234
};
3335

34-
if (!await isGitHubConnected(wizardContext)) {
36+
if (!wizardContext.sourceControl) {
3537
throw new Error(localize('repositoryNotConnected', '"{0}" is not connected to a GitHub repository.', containerApp.name));
3638
}
3739

38-
const title: string = localize('disconnectRepository', 'Disconnect "{0}" from a GitHub repository', containerApp.name);
40+
const promptSteps: AzureWizardPromptStep<IDisconnectRepoContext>[] = [
41+
new DisconnectRepositoryConfirmStep()
42+
];
3943

4044
const executeSteps: AzureWizardExecuteStep<IDisconnectRepoContext>[] = [
4145
new GitHubRepositoryDisconnectStep()
4246
];
4347

4448
const wizard: AzureWizard<IDisconnectRepoContext> = new AzureWizard(wizardContext, {
45-
title,
49+
title: localize('disconnectRepository', 'Disconnect "{0}" from a GitHub repository', containerApp.name),
50+
promptSteps,
4651
executeSteps,
4752
showLoadingPrompt: true
4853
});
4954

50-
// Title normally gets set during prompt phase... since no prompt steps are provided we must set the 'activityTitle' manually
51-
wizardContext.activityTitle = title;
55+
await wizard.prompt();
5256
await wizard.execute();
5357
}
5458

0 commit comments

Comments
 (0)