import * as retry from 'p-retry' ; import { MessageItem , window , WorkspaceFolder } from 'vscode' ; import { AzExtTreeItem , callWithTelemetryAndErrorHandling , IActionContext } from 'vscode-azureextensionui' ; import { ext } from '../../extensionVariables' ; import { localize } from '../../localize' ; import { RemoteFunctionsTreeItem } from '../../tree/remoteProject/RemoteFunctionsTreeItem' ; import { RemoteFunctionTreeItem } from '../../tree/remoteProject/RemoteFunctionTreeItem' ; import { SlotTreeItemBase } from '../../tree/SlotTreeItemBase' ; import { nonNullValue } from '../../utils/nonNull' ; import { uploadAppSettings } from '../appSettings/uploadAppSettings' ; import { startStreamingLogs } from '../logstream/startStreamingLogs' ; export async function notifyDeployComplete ( context , node , workspaceFolder ) { const deployComplete = localize ( 'deployComplete' , 'Deployment to "{0}" completed.' , node . site . fullName ) ; const viewOutput = { title : localize ( 'viewOutput' , 'View output' ) } ; const streamLogs = { title : localize ( 'streamLogs' , 'Stream logs' ) } ; const uploadSettings = { title : localize ( 'uploadAppSettings' , 'Upload settings' ) } ; void window . showInformationMessage ( deployComplete , streamLogs , uploadSettings , viewOutput ) . then ( async ( result ) => { await callWithTelemetryAndErrorHandling ( 'postDeploy' , async ( postDeployContext ) => { postDeployContext . telemetry . properties . dialogResult = result && result . title ; postDeployContext . valuesToMask . push ( ... context . valuesToMask ) ; context . telemetry . eventVersion = 2 ; if ( result === viewOutput ) { ext . outputChannel . show ( ) ; } else if ( result === streamLogs ) { await startStreamingLogs ( postDeployContext , node ) ; } else if ( result === uploadSettings ) { await uploadAppSettings ( postDeployContext , node . appSettingsTreeItem , workspaceFolder ) ; } } ) ; } ) ; try { const retries = 4 ; await retry ( async ( currentAttempt ) => { context . telemetry . properties . queryTriggersAttempt = currentAttempt . toString ( ) ; const message = currentAttempt === 1 ? localize ( 'queryingTriggers' , 'Querying triggers...' ) : localize ( 'queryingTriggersAttempt' , 'Querying triggers (Attempt {0}/{1})...' , currentAttempt , retries + 1 ) ; ext . outputChannel . appendLog ( message , { resourceName : node . site . fullName } ) ; await listHttpTriggerUrls ( context , node ) ; } , { retries , minTimeout : 2 * 1000 } ) ; } catch ( error ) { context . errorHandling . suppressDisplay = true ; ext . outputChannel . appendLog ( localize ( 'failedToList' , 'WARNING: Deployment succeeded, but failed to list http trigger urls.' ) ) ; throw error ; } } async function listHttpTriggerUrls ( context , node ) { const children = await node . getCachedChildren ( context ) ; const functionsNode = < RemoteFunctionsTreeItem > children . find ( n => n instanceof RemoteFunctionsTreeItem ) ; await node . treeDataProvider . refresh ( context , functionsNode ) ; const logOptions = { resourceName : node . site . fullName } ; let hasHttpTriggers = false ; const functions = await functionsNode . getCachedChildren ( context ) ; const anonFunctions = < RemoteFunctionTreeItem [ ] > functions . filter ( f => f instanceof RemoteFunctionTreeItem && f . isHttpTrigger && f . isAnonymous ) ; if ( anonFunctions . length > 0 ) { hasHttpTriggers = true ; ext . outputChannel . appendLog ( localize ( 'anonymousFunctionUrls' , 'HTTP Trigger Urls:' ) , logOptions ) ; for ( const func of anonFunctions ) { const triggerRequest = nonNullValue ( await func . getTriggerRequest ( context ) , 'triggerRequest' ) ; ext . outputChannel . appendLine ( `  ${ func . label }: ${ triggerRequest . url }` ) ; } } if ( functions . find ( f => f instanceof RemoteFunctionTreeItem && f . isHttpTrigger && ! f . isAnonymous ) ) { hasHttpTriggers = true ; ext . outputChannel . appendLog ( localize ( 'nonAnonymousWarning' , 'WARNING: Some http trigger urls cannot be displayed in the output window because they require an authentication token. Instead, you may copy them from the Azure Functions explorer.' ) , logOptions ) ; } if ( ! hasHttpTriggers ) { ext . outputChannel . appendLog ( localize ( 'noHttpTriggers' , 'No HTTP triggers found.' ) , logOptions ) ; } }