Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ export interface IStaticWebAppWizardContext extends IResourceGroupWizardContext,

// created when the wizard is done executing
staticWebApp?: StaticSiteARMResource;

// logic app
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the comment does not add any value here

logicApp?: {backendResourceId: string, region: string, name: string};


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra lines

}
73 changes: 68 additions & 5 deletions src/commands/createStaticWebApp/StaticWebAppCreateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,53 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { StaticSiteARMResource } from "@azure/arm-appservice";
import { WebSiteManagementClient, type StaticSiteARMResource } from "@azure/arm-appservice";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate that all these imports are still being used

import { DefaultAzureCredential } from "@azure/identity";
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizardExecuteStep, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import { AppResource } from "@microsoft/vscode-azext-utils/hostapi";
import { Progress } from "vscode";
import type { AppResource } from "@microsoft/vscode-azext-utils/hostapi";
import type { Octokit } from "@octokit/rest";
import type { Progress } from "vscode";
import { ext } from "../../extensionVariables";
import { localize } from "../../utils/localize";
import { IStaticWebAppWizardContext } from "./IStaticWebAppWizardContext";
import { createOctokitClient } from "../github/createOctokitClient";
import type { IStaticWebAppWizardContext } from "./IStaticWebAppWizardContext";


export class StaticWebAppCreateStep extends AzureWizardExecuteStep<IStaticWebAppWizardContext> {
public priority: number = 250;
public priority = 250;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra line


public async execute(context: IStaticWebAppWizardContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {

if(context.logicApp) {
//There was an issue where some fields of context would be lost when SWA called with LA. This is a temporary fix to find the branch data again here because of that. Note this will only work with alain github.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be fixed still?

const octokitClient: Octokit = await createOctokitClient(context);


const owner = "alain-zhiyanov";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extract this to the top of the file and call it template owner

const repo = context.newStaticWebAppName || 'def';

const { data } = await octokitClient.repos.get({ owner, repo });
context.repoHtmlUrl = data.html_url;

const { data: branches } = await octokitClient.repos.listBranches({
owner,
repo
});

const defaultBranch = branches.find(branch => branch.name === 'main');

if (defaultBranch) {
context.branchData = { name: defaultBranch.name };

} else {
context.branchData = {name: branches[0].name };
}
}



//api call to ARM
const newName: string = nonNullProp(context, 'newStaticWebAppName');
const branchData = nonNullProp(context, 'branchData');
const siteEnvelope: StaticSiteARMResource = {
Expand All @@ -32,14 +66,43 @@ export class StaticWebAppCreateStep extends AzureWizardExecuteStep<IStaticWebApp
location: (await LocationListStep.getLocation(context)).name
};





Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove lines




const creatingSwa: string = localize('creatingSwa', 'Creating new static web app "{0}"...', newName);
progress.report({ message: creatingSwa });
ext.outputChannel.appendLog(creatingSwa);
context.staticWebApp = await context.client.staticSites.beginCreateOrUpdateStaticSiteAndWait(nonNullValueAndProp(context.resourceGroup, 'name'), newName, siteEnvelope);
context.activityResult = context.staticWebApp as AppResource;

if (context.logicApp) {
//link backends only if SWA called with LA
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of the comment can we extract the content.logicApp into a varthat is named properly so that thise comment is not needed anymore

const staticSiteLinkedBackendEnvelope = {
backendResourceId: context.logicApp.backendResourceId,
region: context.logicApp.region
};
const credential = new DefaultAzureCredential();
const client = new WebSiteManagementClient(credential, context.subscriptionId);

try{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there should also be a space inbetween the try and the parentheses

const result = await client.staticSites.beginLinkBackendAndWait(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the formatting here is off

nonNullValueAndProp(context.resourceGroup, 'name'), nonNullValueAndProp(context.staticWebApp, "name"), context.logicApp.name, staticSiteLinkedBackendEnvelope);
console.log(result);
} catch(error) {
console.log(error);
}
}
}

public shouldExecute(_wizardContext: IStaticWebAppWizardContext): boolean {
return true;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra line




}
Loading