@@ -14,16 +14,21 @@ import { RemoteQueryResult } from './remote-query-result';
1414import { DownloadLink } from './download-link' ;
1515import { AnalysesResultsManager } from './analyses-results-manager' ;
1616
17+ const autoDownloadMaxSize = 300 * 1024 ;
18+ const autoDownloadMaxCount = 100 ;
19+
1720export class RemoteQueriesManager {
1821 private readonly remoteQueriesMonitor : RemoteQueriesMonitor ;
1922 private readonly analysesResultsManager : AnalysesResultsManager ;
23+ private readonly interfaceManager : RemoteQueriesInterfaceManager ;
2024
2125 constructor (
2226 private readonly ctx : ExtensionContext ,
23- private readonly logger : Logger ,
24- private readonly cliServer : CodeQLCliServer
27+ private readonly cliServer : CodeQLCliServer ,
28+ logger : Logger ,
2529 ) {
2630 this . analysesResultsManager = new AnalysesResultsManager ( ctx , logger ) ;
31+ this . interfaceManager = new RemoteQueriesInterfaceManager ( ctx , logger , this . analysesResultsManager ) ;
2732 this . remoteQueriesMonitor = new RemoteQueriesMonitor ( ctx , logger ) ;
2833 }
2934
@@ -65,13 +70,16 @@ export class RemoteQueriesManager {
6570
6671 const queryResult = this . mapQueryResult ( executionEndTime , resultIndex ) ;
6772
73+ // Kick off auto-download of results.
74+ void commands . executeCommand ( 'codeQL.autoDownloadRemoteQueryResults' , queryResult ) ;
75+
6876 const totalResultCount = queryResult . analysisSummaries . reduce ( ( acc , cur ) => acc + cur . resultCount , 0 ) ;
6977 const message = `Query "${ query . queryName } " run on ${ query . repositories . length } repositories and returned ${ totalResultCount } results` ;
7078
7179 const shouldOpenView = await showInformationMessageWithAction ( message , 'View' ) ;
7280 if ( shouldOpenView ) {
73- const rqim = new RemoteQueriesInterfaceManager ( this . ctx , this . logger , this . analysesResultsManager ) ;
74- await rqim . showResults ( query , queryResult ) ;
81+ await this . interfaceManager . showResults ( query , queryResult ) ;
82+
7583 }
7684 } else if ( queryResult . status === 'CompletedUnsuccessfully' ) {
7785 await showAndLogErrorMessage ( `Remote query execution failed. Error: ${ queryResult . error } ` ) ;
@@ -81,6 +89,26 @@ export class RemoteQueriesManager {
8189 }
8290 }
8391
92+ public async autoDownloadRemoteQueryResults (
93+ queryResult : RemoteQueryResult ,
94+ token : CancellationToken
95+ ) : Promise < void > {
96+ const analysesToDownload = queryResult . analysisSummaries
97+ . filter ( a => a . fileSizeInBytes < autoDownloadMaxSize )
98+ . slice ( 0 , autoDownloadMaxCount )
99+ . map ( a => ( {
100+ nwo : a . nwo ,
101+ resultCount : a . resultCount ,
102+ downloadLink : a . downloadLink ,
103+ fileSize : String ( a . fileSizeInBytes )
104+ } ) ) ;
105+
106+ await this . analysesResultsManager . downloadAnalysesResults (
107+ analysesToDownload ,
108+ token ,
109+ results => this . interfaceManager . setAnalysisResults ( results ) ) ;
110+ }
111+
84112 private mapQueryResult ( executionEndTime : Date , resultIndex : RemoteQueryResultIndex ) : RemoteQueryResult {
85113 const analysisSummaries = resultIndex . items . map ( item => ( {
86114 nwo : item . nwo ,
0 commit comments