-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for Logic Apps extension. #907
base: main
Are you sure you want to change the base?
Changes from 10 commits
b1b2865
08c4d5f
f7662ed
e11f13c
687a1ce
c7ed450
9600e20
819390f
b5ca08a
c3b2c38
fb9a53a
23c8b80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,9 @@ export interface IStaticWebAppWizardContext extends IResourceGroupWizardContext, | |
|
||
// created when the wizard is done executing | ||
staticWebApp?: StaticSiteARMResource; | ||
|
||
// logic app | ||
logicApp?: {backendResourceId: string, region: string, name: string}; | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove extra lines |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = { | ||
|
@@ -32,14 +66,43 @@ export class StaticWebAppCreateStep extends AzureWizardExecuteStep<IStaticWebApp | |
location: (await LocationListStep.getLocation(context)).name | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove extra line |
||
|
||
|
||
|
||
} |
There was a problem hiding this comment.
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