import type { WebSiteManagementModels } from '@azure/arm-appservice' ; import { ThemeIcon } from 'vscode' ; import { AzExtParentTreeItem , AzExtTreeItem , GenericTreeItem , IActionContext , TreeItemIconPath } from 'vscode-azureextensionui' ; import { KuduModels } from 'vscode-azurekudu' ; import { createKuduClient } from '../createKuduClient' ; import { ext } from '../extensionVariables' ; import { localize } from '../localize' ; import { ScmType } from '../ScmType' ; import { ParsedSite } from '../SiteClient' ; import { retryKuduCall } from '../utils/kuduUtils' ; import { DeploymentTreeItem } from './DeploymentTreeItem' ; /**
 * NOTE: This leverages a command with id `ext.prefix + '.connectToGitHub'` that should be registered by each extension
 */ export class DeploymentsTreeItem extends AzExtParentTreeItem { public static contextValueConnected : string = 'deploymentsConnected' ; public static contextValueUnconnected : string = 'deploymentsUnconnected' ; public readonly label : string = localize ( 'Deployments' , 'Deployments' ) ; public readonly childTypeLabel : string = localize ( 'Deployment' , 'Deployment' ) ; public readonly site : ParsedSite ; public suppressMaskLabel : boolean = true ; private _scmType ? : string ; private _repoUrl ? : string ; public constructor ( parent , site , siteConfig , sourceControl ) { super ( parent ) ; this . site = site ; this . _scmType = siteConfig . scmType ; this . _repoUrl = sourceControl . repoUrl ; } public get iconPath ( ) : TreeItemIconPath { return new ThemeIcon ( 'cloud-upload' ) ; } public get description ( ) : string { switch ( this . _scmType ) { case ScmType . LocalGit : return localize ( 'git' , 'Git' ) ; case ScmType . GitHub : return this . _repoUrl ? this . _repoUrl . substring ( 'https://github.com/' . length ) : localize ( 'gitHub' , 'GitHub' ) ; case ScmType . None : default : return '' ; } } public get contextValue ( ) : string { return this . _scmType === ScmType . None ? DeploymentsTreeItem . contextValueUnconnected : DeploymentsTreeItem . contextValueConnected ; } public hasMoreChildrenImpl ( ) { return false ; } public async loadMoreChildrenImpl ( _clearCache , context ) { const client = await this . site . createClient ( context ) ; const siteConfig = await client . getSiteConfig ( ) ; const kuduClient = await createKuduClient ( context , this . site ) ; const deployments = await retryKuduCall ( context , 'getDeployResults' , async ( ) => { return kuduClient . deployment . getDeployResults ( ) ; } ) ; const children = await this . createTreeItemsWithErrorHandling ( deployments , 'invalidDeployment' , dr => { return new DeploymentTreeItem ( this , dr , siteConfig . scmType ) ; } , dr => { return dr . id ? dr . id . substring ( 0 , 7 ) : undefined ; } ) ; if ( siteConfig . scmType === ScmType . None ) { children . push ( new GenericTreeItem ( this , { commandId : ext . prefix + '.connectToGitHub' , contextValue : 'ConnectToGithub' , label : 'Connect to a GitHub Repository...' } ) ) ; } return children ; } public compareChildrenImpl ( ti1 , ti2 ) { if ( ti1 instanceof GenericTreeItem ) { return 1 ; } else if ( ti2 instanceof GenericTreeItem ) { return - 1 ; } return ti2 . receivedTime . valueOf ( ) - ti1 . receivedTime . valueOf ( ) ; } public async refreshImpl ( context ) { const client = await this . site . createClient ( context ) ; const siteConfig = await client . getSiteConfig ( ) ; const sourceControl = await client . getSourceControl ( ) ; this . _scmType = siteConfig . scmType ; this . _repoUrl = sourceControl . repoUrl ; } }