import * as path from "path" ; import * as fs from "fs-extra" ; import * as tl from "azure-pipelines-task-lib/task" ; import * as azdoApiUtils from "./../helpers/azdo-api-utils" ; export function publishBuildSummary ( summary , endpointType = "SonarQube" ) { uploadBuildSummary ( saveBuildSummary ( summary ) , `${ endpointType } Analysis Report` ) ; } export function saveBuildSummary ( summary ) { const filePath = path . join ( getStagingDirectory ( ) , "SonarQubeBuildSummary.md" ) ; fs . writeFileSync ( filePath , summary ) ; tl . debug ( `[SQ] Summary saved at: ${ filePath }` ) ; return filePath ; } export function getStagingDirectory ( ) { const dir = path . join ( tl . getVariable ( "build.artifactStagingDirectory" ) , ".sqAnalysis" ) ; fs . ensureDirSync ( dir ) ; return dir ; } export function uploadBuildSummary ( summaryPath , title ) { tl . debug ( `[SQ] Uploading build summary from ${ summaryPath }` ) ; tl . command ( "task.addattachment" , { type : "Distributedtask.Core.Summary" , name : title , } , summaryPath ) ; } export async function fillBuildProperty ( sonarQualityGateStatus ) { const properties = [ ] ; properties . push ( { propertyName : "sonarglobalqualitygate" , propertyValue : sonarQualityGateStatus , } ) ; await azdoApiUtils . addBuildProperty ( properties ) ; }