@@ -9,7 +9,11 @@ import {
99 window ,
1010 workspace ,
1111} from "vscode" ;
12- import { ProgressCallback , UserCancellationException } from "../commandRunner" ;
12+ import {
13+ ProgressCallback ,
14+ UserCancellationException ,
15+ withProgress ,
16+ } from "../commandRunner" ;
1317import { showInformationMessageWithAction } from "../helpers" ;
1418import { extLogger } from "../common" ;
1519import { QueryHistoryManager } from "../query-history/query-history-manager" ;
@@ -37,6 +41,7 @@ import { Credentials } from "../common/authentication";
3741 * Exports the results of the currently-selected variant analysis.
3842 */
3943export async function exportSelectedVariantAnalysisResults (
44+ variantAnalysisManager : VariantAnalysisManager ,
4045 queryHistoryManager : QueryHistoryManager ,
4146) : Promise < void > {
4247 const queryHistoryItem = queryHistoryManager . getCurrentQueryHistoryItem ( ) ;
@@ -46,8 +51,7 @@ export async function exportSelectedVariantAnalysisResults(
4651 ) ;
4752 }
4853
49- return commands . executeCommand (
50- "codeQL.exportVariantAnalysisResults" ,
54+ await variantAnalysisManager . exportResults (
5155 queryHistoryItem . variantAnalysis . id ,
5256 ) ;
5357}
@@ -63,108 +67,117 @@ export async function exportVariantAnalysisResults(
6367 variantAnalysisId : number ,
6468 filterSort : RepositoriesFilterSortStateWithIds | undefined ,
6569 credentials : Credentials ,
66- progress : ProgressCallback ,
67- token : CancellationToken ,
6870) : Promise < void > {
69- const variantAnalysis = await variantAnalysisManager . getVariantAnalysis (
70- variantAnalysisId ,
71- ) ;
72- if ( ! variantAnalysis ) {
73- void extLogger . log (
74- `Could not find variant analysis with id ${ variantAnalysisId } ` ,
75- ) ;
76- throw new Error (
77- "There was an error when trying to retrieve variant analysis information" ,
78- ) ;
79- }
80-
81- if ( token . isCancellationRequested ) {
82- throw new UserCancellationException ( "Cancelled" ) ;
83- }
84-
85- const repoStates = await variantAnalysisManager . getRepoStates (
86- variantAnalysisId ,
87- ) ;
88-
89- void extLogger . log (
90- `Exporting variant analysis results for variant analysis with id ${ variantAnalysis . id } ` ,
91- ) ;
71+ await withProgress (
72+ async ( progress : ProgressCallback , token : CancellationToken ) => {
73+ const variantAnalysis = await variantAnalysisManager . getVariantAnalysis (
74+ variantAnalysisId ,
75+ ) ;
76+ if ( ! variantAnalysis ) {
77+ void extLogger . log (
78+ `Could not find variant analysis with id ${ variantAnalysisId } ` ,
79+ ) ;
80+ throw new Error (
81+ "There was an error when trying to retrieve variant analysis information" ,
82+ ) ;
83+ }
9284
93- progress ( {
94- maxStep : MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS ,
95- step : 0 ,
96- message : "Determining export format" ,
97- } ) ;
85+ if ( token . isCancellationRequested ) {
86+ throw new UserCancellationException ( "Cancelled" ) ;
87+ }
9888
99- const exportFormat = await determineExportFormat ( ) ;
100- if ( ! exportFormat ) {
101- return ;
102- }
89+ const repoStates = await variantAnalysisManager . getRepoStates (
90+ variantAnalysisId ,
91+ ) ;
10392
104- if ( token . isCancellationRequested ) {
105- throw new UserCancellationException ( "Cancelled" ) ;
106- }
93+ void extLogger . log (
94+ `Exporting variant analysis results for variant analysis with id ${ variantAnalysis . id } ` ,
95+ ) ;
10796
108- const repositories = filterAndSortRepositoriesWithResults (
109- variantAnalysis . scannedRepos ,
110- filterSort ,
111- ) ?. filter (
112- ( repo ) =>
113- repo . resultCount &&
114- repoStates . find ( ( r ) => r . repositoryId === repo . repository . id )
115- ?. downloadStatus ===
116- VariantAnalysisScannedRepositoryDownloadStatus . Succeeded ,
117- ) ;
97+ progress ( {
98+ maxStep : MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS ,
99+ step : 0 ,
100+ message : "Determining export format" ,
101+ } ) ;
118102
119- async function * getAnalysesResults ( ) : AsyncGenerator <
120- [ VariantAnalysisScannedRepository , VariantAnalysisScannedRepositoryResult ]
121- > {
122- if ( ! variantAnalysis ) {
123- return ;
124- }
103+ const exportFormat = await determineExportFormat ( ) ;
104+ if ( ! exportFormat ) {
105+ return ;
106+ }
125107
126- if ( ! repositories ) {
127- return ;
128- }
108+ if ( token . isCancellationRequested ) {
109+ throw new UserCancellationException ( "Cancelled" ) ;
110+ }
129111
130- for ( const repo of repositories ) {
131- const result = await variantAnalysisManager . loadResults (
132- variantAnalysis . id ,
133- repo . repository . fullName ,
134- {
135- skipCacheStore : true ,
136- } ,
112+ const repositories = filterAndSortRepositoriesWithResults (
113+ variantAnalysis . scannedRepos ,
114+ filterSort ,
115+ ) ?. filter (
116+ ( repo ) =>
117+ repo . resultCount &&
118+ repoStates . find ( ( r ) => r . repositoryId === repo . repository . id )
119+ ?. downloadStatus ===
120+ VariantAnalysisScannedRepositoryDownloadStatus . Succeeded ,
137121 ) ;
138122
139- yield [ repo , result ] ;
140- }
141- }
142-
143- const exportDirectory =
144- variantAnalysisManager . getVariantAnalysisStorageLocation (
145- variantAnalysis . id ,
146- ) ;
123+ async function * getAnalysesResults ( ) : AsyncGenerator <
124+ [
125+ VariantAnalysisScannedRepository ,
126+ VariantAnalysisScannedRepositoryResult ,
127+ ]
128+ > {
129+ if ( ! variantAnalysis ) {
130+ return ;
131+ }
132+
133+ if ( ! repositories ) {
134+ return ;
135+ }
136+
137+ for ( const repo of repositories ) {
138+ const result = await variantAnalysisManager . loadResults (
139+ variantAnalysis . id ,
140+ repo . repository . fullName ,
141+ {
142+ skipCacheStore : true ,
143+ } ,
144+ ) ;
145+
146+ yield [ repo , result ] ;
147+ }
148+ }
147149
148- // The date will be formatted like the following: 20221115T123456Z. The time is in UTC.
149- const formattedDate = new Date ( )
150- . toISOString ( )
151- . replace ( / [ - : ] / g, "" )
152- . replace ( / \. \d + Z $ / , "Z" ) ;
153- const exportedResultsDirectory = join (
154- exportDirectory ,
155- "exported-results" ,
156- `results_${ formattedDate } ` ,
157- ) ;
150+ const exportDirectory =
151+ variantAnalysisManager . getVariantAnalysisStorageLocation (
152+ variantAnalysis . id ,
153+ ) ;
154+
155+ // The date will be formatted like the following: 20221115T123456Z. The time is in UTC.
156+ const formattedDate = new Date ( )
157+ . toISOString ( )
158+ . replace ( / [ - : ] / g, "" )
159+ . replace ( / \. \d + Z $ / , "Z" ) ;
160+ const exportedResultsDirectory = join (
161+ exportDirectory ,
162+ "exported-results" ,
163+ `results_${ formattedDate } ` ,
164+ ) ;
158165
159- await exportVariantAnalysisAnalysisResults (
160- exportedResultsDirectory ,
161- variantAnalysis ,
162- getAnalysesResults ( ) ,
163- repositories ?. length ?? 0 ,
164- exportFormat ,
165- credentials ,
166- progress ,
167- token ,
166+ await exportVariantAnalysisAnalysisResults (
167+ exportedResultsDirectory ,
168+ variantAnalysis ,
169+ getAnalysesResults ( ) ,
170+ repositories ?. length ?? 0 ,
171+ exportFormat ,
172+ credentials ,
173+ progress ,
174+ token ,
175+ ) ;
176+ } ,
177+ {
178+ title : "Exporting variant analysis results" ,
179+ cancellable : true ,
180+ } ,
168181 ) ;
169182}
170183
0 commit comments