import type { WebSiteManagementModels } from '@azure/arm-appservice' ; import { window } from 'vscode' ; import { IActionContext , IAzureQuickPickItem , IAzureQuickPickOptions , ISubscriptionContext , UserCancelledError } from 'vscode-azureextensionui' ; import { ext } from './extensionVariables' ; import { connectToGitHub } from './github/connectToGitHub' ; import { localize } from './localize' ; import { ScmType } from './ScmType' ; import { ParsedSite } from './SiteClient' ; import { nonNullProp } from './utils/nonNull' ; export async function editScmType ( context , site , subscriptionContext , newScmType ? , showToast = true ) { const client = await site . createClient ( context ) ; if ( site . isLinux && await client . getIsConsumption ( context ) ) { context . errorHandling . suppressReportIssue = true ; throw new Error ( localize ( 'noEditScmOnLinuxCons' , 'Linux consumption plans only support zip deploy. See [here](https://aka.ms/AA7avjx) for more information.' ) ) ; } const config = await client . getSiteConfig ( ) ; newScmType = newScmType ? newScmType : await showScmPrompt ( context , nonNullProp ( config , 'scmType' ) ) ; if ( newScmType === ScmType . GitHub ) { if ( config . scmType !== ScmType . None ) { await editScmType ( context , site , subscriptionContext , ScmType . None , false ) ; } await connectToGitHub ( site , Object . assign ( context , subscriptionContext ) ) ; } else { config . scmType = newScmType ; await client . updateConfiguration ( config ) ; } if ( showToast ) { const scmTypeUpdated = localize ( 'deploymentSourceUpdated,' , 'Deployment source for "{0}" has been updated to "{1}".' , site . fullName , newScmType ) ; ext . outputChannel . appendLog ( scmTypeUpdated ) ; void window . showInformationMessage ( scmTypeUpdated ) ; } if ( newScmType === ScmType . LocalGit ) { const user = await client . getPublishingUser ( ) ; if ( user . publishingUserName ) { const gitCloneUri = `https://${ user . publishingUserName }@${ site . gitUrl }` ; ext . outputChannel . appendLog ( localize ( 'gitCloneUri' , 'Git Clone Uri for "{0}": "{1}"' , site . fullName , gitCloneUri ) ) ; } } return newScmType ; } async function showScmPrompt ( context , currentScmType ) { const currentSource = localize ( 'currentSource' , '(Current source)' ) ; const scmQuickPicks = [ ] ; for ( const key of Object . keys ( ScmType ) ) { const scmType = < ScmType > ScmType [ key ] ; if ( scmType === currentScmType ) { scmQuickPicks . unshift ( { label : scmType , description : currentSource , data : undefined } ) ; } else { scmQuickPicks . push ( { label : scmType , description : '' , data : scmType } ) ; } } const options = { placeHolder : localize ( 'scmPrompt' , 'Select a new source.' ) , suppressPersistence : true , stepName : 'editScmType' } ; const newScmType = ( await context . ui . showQuickPick ( scmQuickPicks , options ) ) . data ; if ( newScmType === undefined ) { throw new UserCancelledError ( 'scmTypeAlreadyMatches' ) ; } else { return newScmType ; } }