@@ -7,13 +7,13 @@ import {
7
7
workspace ,
8
8
} from 'vscode' ;
9
9
import * as path from 'path' ;
10
- import * as vscode from 'vscode' ;
11
- import * as fs from 'fs-extra' ;
12
10
13
11
import { tmpDir } from '../run-queries' ;
14
12
import {
15
13
ToRemoteQueriesMessage ,
16
14
FromRemoteQueriesMessage ,
15
+ RemoteQueryDownloadAnalysisResultsMessage ,
16
+ RemoteQueryDownloadAllAnalysesResultsMessage ,
17
17
} from '../pure/interface-types' ;
18
18
import { Logger } from '../logging' ;
19
19
import { getHtmlForWebview } from '../interface-utils' ;
@@ -22,21 +22,21 @@ import { AnalysisSummary, RemoteQueryResult } from './remote-query-result';
22
22
import { RemoteQuery } from './remote-query' ;
23
23
import { RemoteQueryResult as RemoteQueryResultViewModel } from './shared/remote-query-result' ;
24
24
import { 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' ;
28
26
import { URLSearchParams } from 'url' ;
29
27
import { 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' ;
31
30
32
31
export class RemoteQueriesInterfaceManager {
33
32
private panel : WebviewPanel | undefined ;
34
33
private panelLoaded = false ;
35
34
private panelLoadedCallBacks : ( ( ) => void ) [ ] = [ ] ;
36
35
37
36
constructor (
38
- private ctx : ExtensionContext ,
39
- private logger : Logger ,
37
+ private readonly ctx : ExtensionContext ,
38
+ private readonly logger : Logger ,
39
+ private readonly analysesResultsManager : AnalysesResultsManager
40
40
) {
41
41
this . panelLoadedCallBacks . push ( ( ) => {
42
42
void logger . log ( 'Remote queries view loaded' ) ;
@@ -190,32 +190,31 @@ export class RemoteQueriesInterfaceManager {
190
190
await this . openVirtualFile ( msg . queryText ) ;
191
191
break ;
192
192
case 'remoteQueryDownloadAnalysisResults' :
193
- await this . handleDownloadLinkClicked ( msg . downloadLink ) ;
193
+ await this . downloadAnalysisResults ( msg ) ;
194
194
break ;
195
195
case 'remoteQueryDownloadAllAnalysesResults' :
196
- await this . handleDownloadLinkClicked ( msg . downloadLink ) ;
196
+ await this . downloadAllAnalysesResults ( msg ) ;
197
197
break ;
198
198
default :
199
199
assertNever ( msg ) ;
200
200
}
201
201
}
202
202
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
+ }
205
207
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
+ } ) ;
219
218
}
220
219
221
220
private postMessage ( msg : ToRemoteQueriesMessage ) : Thenable < boolean > {
0 commit comments