@@ -5,14 +5,14 @@ import * as fs from 'fs-extra';
55
66import { Credentials } from '../authentication' ;
77import { CodeQLCliServer } from '../cli' ;
8- import { ProgressCallback , UserCancellationException } from '../commandRunner' ;
8+ import { ProgressCallback } from '../commandRunner' ;
99import { createTimestampFile , showAndLogErrorMessage , showAndLogInformationMessage , showInformationMessageWithAction } from '../helpers' ;
1010import { Logger } from '../logging' ;
1111import { runRemoteQuery } from './run-remote-query' ;
1212import { RemoteQueriesInterfaceManager } from './remote-queries-interface' ;
1313import { RemoteQuery } from './remote-query' ;
1414import { RemoteQueriesMonitor } from './remote-queries-monitor' ;
15- import { createGist , getRemoteQueryIndex } from './gh-actions-api-client' ;
15+ import { getRemoteQueryIndex } from './gh-actions-api-client' ;
1616import { RemoteQueryResultIndex } from './remote-query-result-index' ;
1717import { RemoteQueryResult } from './remote-query-result' ;
1818import { DownloadLink } from './download-link' ;
@@ -23,7 +23,7 @@ import { QueryHistoryManager } from '../query-history';
2323import { QueryStatus } from '../query-status' ;
2424import { DisposableObject } from '../pure/disposable-object' ;
2525import { QueryHistoryInfo } from '../query-results' ;
26- import { generateMarkdown } from './remote-queries-markdown-generation ' ;
26+ import { AnalysisResults } from './shared/analysis-result ' ;
2727
2828const autoDownloadMaxSize = 300 * 1024 ;
2929const autoDownloadMaxCount = 100 ;
@@ -39,7 +39,7 @@ export class RemoteQueriesManager extends DisposableObject {
3939 private readonly cliServer : CodeQLCliServer ,
4040 private readonly qhm : QueryHistoryManager ,
4141 private readonly storagePath : string ,
42- private readonly logger : Logger ,
42+ logger : Logger ,
4343 ) {
4444 super ( ) ;
4545 this . analysesResultsManager = new AnalysesResultsManager ( ctx , cliServer , storagePath , logger ) ;
@@ -303,64 +303,9 @@ export class RemoteQueriesManager extends DisposableObject {
303303 }
304304 }
305305
306- public async exportVariantAnalysisResults ( ) : Promise < void > {
307- const queryHistoryItem = this . qhm . getCurrentQueryHistoryItem ( ) ;
308-
309- if ( ! queryHistoryItem || queryHistoryItem . t !== 'remote' ) {
310- throw new Error ( 'No variant analysis results currently open. To open results, click an item in the query history view.' ) ;
311- } else if ( ! queryHistoryItem . completed ) {
312- throw new Error ( 'Variant analysis results are not yet available.' ) ;
313- }
314-
315- const queryId = queryHistoryItem . queryId ;
316- void this . logger . log ( `Exporting variant analysis results for query: ${ queryId } ` ) ;
317- const query = queryHistoryItem . remoteQuery ;
318- const analysesResults = this . analysesResultsManager . getAnalysesResults ( queryId ) ;
319-
320- const gistOption = {
321- label : '$(ports-open-browser-icon) Create Gist (GitHub)' ,
322- } ;
323- const localMarkdownOption = {
324- label : '$(markdown) Save as markdown' ,
325- } ;
326-
327- // User selects export format in quick pick
328- const exportFormat = await window . showQuickPick (
329- [ gistOption , localMarkdownOption ] ,
330- {
331- placeHolder : 'Select export format' ,
332- canPickMany : false ,
333- ignoreFocusOut : true ,
334- }
335- ) ;
336-
337- if ( ! exportFormat || ! exportFormat . label ) {
338- throw new UserCancellationException ( 'No export format selected' , true ) ;
339- }
340-
341- if ( exportFormat === gistOption ) {
342- const credentials = await Credentials . initialize ( this . ctx ) ;
343- const description = 'CodeQL Variant Analysis Results' ;
344-
345- const markdownFiles = generateMarkdown ( query , analysesResults , 'gist' ) ;
346-
347- // Convert markdownFiles to the appropriate format for uploading to gist
348- const gistFiles = markdownFiles . reduce ( ( acc , cur ) => {
349- acc [ `${ cur . fileName } .md` ] = { content : cur . content . join ( '\n' ) } ;
350- return acc ;
351- } , { } as { [ key : string ] : { content : string } } ) ;
352-
353- const gistUrl = await createGist ( credentials , description , gistFiles ) ;
354- if ( gistUrl ) {
355- const shouldOpenGist = await showInformationMessageWithAction ( 'Variant analysis results exported to gist.' , 'Open gist' ) ;
356- if ( shouldOpenGist ) {
357- await commands . executeCommand ( 'vscode.open' , Uri . parse ( gistUrl ) ) ;
358- }
359- }
360- } else if ( exportFormat === localMarkdownOption ) {
361- // TODO: Write function that creates local markdown files
362- // const markdownFiles = generateMarkdown(query, analysesResults, 'local');
363- void showAndLogInformationMessage ( 'Local markdown export not yet available' ) ;
364- }
306+ // Pulled from the analysis results manager, so that we can get access to
307+ // analyses results from the "export results" command.
308+ public getAnalysesResults ( queryId : string ) : AnalysisResults [ ] {
309+ return [ ...this . analysesResultsManager . getAnalysesResults ( queryId ) ] ;
365310 }
366311}
0 commit comments