@@ -652,7 +652,11 @@ export async function runQueries(
652652
653653 for ( const language of config . languages ) {
654654 try {
655- const sarifFile = path . join ( sarifFolder , `${ language } .sarif` ) ;
655+ // If Code Scanning is enabled, then the main SARIF file is always the Code Scanning one.
656+ // Otherwise, only Code Quality is enabled, and the main SARIF file is the Code Quality one.
657+ const sarifFile = configUtils . isCodeScanningEnabled ( config )
658+ ? path . join ( sarifFolder , `${ language } .sarif` )
659+ : path . join ( sarifFolder , `${ language } .quality.sarif` ) ;
656660
657661 // This should be empty to run only the query suite that was generated when
658662 // the database was initialised.
@@ -687,18 +691,43 @@ export async function runQueries(
687691 statusReport [ `analyze_builtin_queries_${ language } _duration_ms` ] =
688692 new Date ( ) . getTime ( ) - startTimeRunQueries ;
689693
690- logger . startGroup ( `Interpreting results for ${ language } ` ) ;
691694 const startTimeInterpretResults = new Date ( ) ;
692- const analysisSummary = await runInterpretResults (
693- language ,
694- undefined ,
695- sarifFile ,
696- config . debugMode ,
697- automationDetailsId ,
698- ) ;
699695
696+ // If only one analysis kind is enabled, then the database is initialised for the
697+ // respective set of queries. Therefore, running `interpret-results` produces the
698+ // SARIF file we want for the one enabled analysis kind.
699+ let analysisSummary : string | undefined ;
700+ if (
701+ configUtils . isCodeScanningEnabled ( config ) ||
702+ configUtils . isCodeQualityEnabled ( config )
703+ ) {
704+ logger . startGroup ( `Interpreting results for ${ language } ` ) ;
705+
706+ // If this is a Code Quality analysis, correct the category to one
707+ // accepted by the Code Quality backend.
708+ let category = automationDetailsId ;
709+ if ( configUtils . isCodeQualityEnabled ( config ) ) {
710+ category = fixCodeQualityCategory ( logger , automationDetailsId ) ;
711+ }
712+
713+ analysisSummary = await runInterpretResults (
714+ language ,
715+ undefined ,
716+ sarifFile ,
717+ config . debugMode ,
718+ category ,
719+ ) ;
720+ }
721+
722+ // This case is only needed if Code Quality is enabled in addition to Code Scanning.
723+ // In this case, we will have run queries for both analysis kinds. The previous call to
724+ // `interpret-results` will have produced a SARIF file for Code Scanning and we now
725+ // need to produce an additional SARIF file for Code Quality.
700726 let qualityAnalysisSummary : string | undefined ;
701- if ( configUtils . isCodeQualityEnabled ( config ) ) {
727+ if (
728+ configUtils . isCodeQualityEnabled ( config ) &&
729+ configUtils . isCodeScanningEnabled ( config )
730+ ) {
702731 logger . info ( `Interpreting quality results for ${ language } ` ) ;
703732 const qualityCategory = fixCodeQualityCategory (
704733 logger ,
@@ -722,8 +751,10 @@ export async function runQueries(
722751 statusReport [ `interpret_results_${ language } _duration_ms` ] =
723752 endTimeInterpretResults . getTime ( ) - startTimeInterpretResults . getTime ( ) ;
724753 logger . endGroup ( ) ;
725- logger . info ( analysisSummary ) ;
726754
755+ if ( analysisSummary ) {
756+ logger . info ( analysisSummary ) ;
757+ }
727758 if ( qualityAnalysisSummary ) {
728759 logger . info ( qualityAnalysisSummary ) ;
729760 }
0 commit comments