@@ -7,13 +7,13 @@ import {
77 workspace ,
88} from 'vscode' ;
99import * as path from 'path' ;
10- import * as vscode from 'vscode' ;
11- import * as fs from 'fs-extra' ;
1210
1311import { tmpDir } from '../run-queries' ;
1412import {
1513 ToRemoteQueriesMessage ,
1614 FromRemoteQueriesMessage ,
15+ RemoteQueryDownloadAnalysisResultsMessage ,
16+ RemoteQueryDownloadAllAnalysesResultsMessage ,
1717} from '../pure/interface-types' ;
1818import { Logger } from '../logging' ;
1919import { getHtmlForWebview } from '../interface-utils' ;
@@ -22,21 +22,21 @@ import { AnalysisSummary, RemoteQueryResult } from './remote-query-result';
2222import { RemoteQuery } from './remote-query' ;
2323import { RemoteQueryResult as RemoteQueryResultViewModel } from './shared/remote-query-result' ;
2424import { AnalysisSummary as AnalysisResultViewModel } from './shared/remote-query-result' ;
25- import { downloadArtifactFromLink } from './gh-actions-api-client' ;
26- import { Credentials } from '../authentication' ;
27- import { showAndLogWarningMessage , showInformationMessageWithAction } from '../helpers' ;
25+ import { showAndLogWarningMessage } from '../helpers' ;
2826import { URLSearchParams } from 'url' ;
2927import { SHOW_QUERY_TEXT_MSG } from '../query-history' ;
30- import { DownloadLink } from './download-link' ;
28+ import { AnalysesResultsManager } from './analyses-results-manager' ;
29+ import { AnalysisResults } from './shared/analysis-result' ;
3130
3231export class RemoteQueriesInterfaceManager {
3332 private panel : WebviewPanel | undefined ;
3433 private panelLoaded = false ;
3534 private panelLoadedCallBacks : ( ( ) => void ) [ ] = [ ] ;
3635
3736 constructor (
38- private ctx : ExtensionContext ,
39- private logger : Logger ,
37+ private readonly ctx : ExtensionContext ,
38+ private readonly logger : Logger ,
39+ private readonly analysesResultsManager : AnalysesResultsManager
4040 ) {
4141 this . panelLoadedCallBacks . push ( ( ) => {
4242 void logger . log ( 'Remote queries view loaded' ) ;
@@ -190,32 +190,31 @@ export class RemoteQueriesInterfaceManager {
190190 await this . openVirtualFile ( msg . queryText ) ;
191191 break ;
192192 case 'remoteQueryDownloadAnalysisResults' :
193- await this . handleDownloadLinkClicked ( msg . downloadLink ) ;
193+ await this . downloadAnalysisResults ( msg ) ;
194194 break ;
195195 case 'remoteQueryDownloadAllAnalysesResults' :
196- await this . handleDownloadLinkClicked ( msg . downloadLink ) ;
196+ await this . downloadAllAnalysesResults ( msg ) ;
197197 break ;
198198 default :
199199 assertNever ( msg ) ;
200200 }
201201 }
202202
203- private async handleDownloadLinkClicked ( downloadLink : DownloadLink ) : Promise < void > {
204- const credentials = await Credentials . initialize ( this . ctx ) ;
203+ private async downloadAnalysisResults ( msg : RemoteQueryDownloadAnalysisResultsMessage ) : Promise < void > {
204+ await this . analysesResultsManager . downloadAnalysisResults ( msg . analysisSummary ) ;
205+ await this . setAnalysisResults ( this . analysesResultsManager . getAnalysesResults ( ) ) ;
206+ }
205207
206- const filePath = await downloadArtifactFromLink ( credentials , downloadLink ) ;
207- const isDir = ( await fs . stat ( filePath ) ) . isDirectory ( ) ;
208- const message = `Result file saved at ${ filePath } ` ;
209- if ( isDir ) {
210- await vscode . window . showInformationMessage ( message ) ;
211- }
212- else {
213- const shouldOpenResults = await showInformationMessageWithAction ( message , 'Open' ) ;
214- if ( shouldOpenResults ) {
215- const textDocument = await vscode . workspace . openTextDocument ( filePath ) ;
216- await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
217- }
218- }
208+ private async downloadAllAnalysesResults ( msg : RemoteQueryDownloadAllAnalysesResultsMessage ) : Promise < void > {
209+ await this . analysesResultsManager . downloadAllResults ( msg . analysisSummaries ) ;
210+ await this . setAnalysisResults ( this . analysesResultsManager . getAnalysesResults ( ) ) ;
211+ }
212+
213+ private async setAnalysisResults ( analysesResults : AnalysisResults [ ] ) : Promise < void > {
214+ await this . postMessage ( {
215+ t : 'setAnalysesResults' ,
216+ analysesResults : analysesResults
217+ } ) ;
219218 }
220219
221220 private postMessage ( msg : ToRemoteQueriesMessage ) : Thenable < boolean > {
0 commit comments