@@ -131,40 +131,21 @@ export class RemoteQueriesManager extends DisposableObject {
131131 const executionEndTime = Date . now ( ) ;
132132
133133 if ( queryWorkflowResult . status === 'CompletedSuccessfully' ) {
134- const resultIndex = await getRemoteQueryIndex ( credentials , queryItem . remoteQuery ) ;
135- queryItem . completed = true ;
136- if ( resultIndex ) {
137- queryItem . status = QueryStatus . Completed ;
138- const queryResult = this . mapQueryResult ( executionEndTime , resultIndex , queryItem . queryId ) ;
139-
140- await this . storeJsonFile ( queryItem , 'query-result.json' , queryResult ) ;
141-
142- // Kick off auto-download of results in the background.
143- void commands . executeCommand ( 'codeQL.autoDownloadRemoteQueryResults' , queryResult ) ;
144-
145- // Ask if the user wants to open the results in the background.
146- void this . askToOpenResults ( queryItem . remoteQuery , queryResult ) . then (
147- noop ,
148- err => {
149- void showAndLogErrorMessage ( err ) ;
150- }
151- ) ;
152- } else {
153- void showAndLogErrorMessage ( `There was an issue retrieving the result for the query ${ queryItem . remoteQuery . queryName } ` ) ;
154- queryItem . status = QueryStatus . Failed ;
155- }
134+ await this . downloadAvailableResults ( queryItem , credentials , executionEndTime ) ;
156135 } else if ( queryWorkflowResult . status === 'CompletedUnsuccessfully' ) {
157136 if ( queryWorkflowResult . error ?. includes ( 'cancelled' ) ) {
158137 // workflow was cancelled on the server
159138 queryItem . failureReason = 'Cancelled' ;
160139 queryItem . status = QueryStatus . Failed ;
140+ await this . downloadAvailableResults ( queryItem , credentials , executionEndTime ) ;
161141 void showAndLogInformationMessage ( 'Variant analysis was cancelled' ) ;
162142 } else {
163143 queryItem . failureReason = queryWorkflowResult . error ;
164144 queryItem . status = QueryStatus . Failed ;
165145 void showAndLogErrorMessage ( `Variant analysis execution failed. Error: ${ queryWorkflowResult . error } ` ) ;
166146 }
167147 } else if ( queryWorkflowResult . status === 'Cancelled' ) {
148+ // workflow was cancelled from within VS Code
168149 queryItem . failureReason = 'Cancelled' ;
169150 queryItem . status = QueryStatus . Failed ;
170151 void showAndLogErrorMessage ( 'Variant analysis was cancelled' ) ;
@@ -282,4 +263,34 @@ export class RemoteQueriesManager extends DisposableObject {
282263 const filePath = path . join ( this . storagePath , queryItem . queryId ) ;
283264 return await fs . pathExists ( filePath ) ;
284265 }
266+
267+ /**
268+ * Checks whether there's a result index artifact available for the given query.
269+ * If so, set the query status to `Completed` and auto-download the results.
270+ */
271+ private async downloadAvailableResults ( queryItem : RemoteQueryHistoryItem , credentials : Credentials , executionEndTime : number ) : Promise < void > {
272+ const resultIndex = await getRemoteQueryIndex ( credentials , queryItem . remoteQuery ) ;
273+ if ( resultIndex ) {
274+ queryItem . completed = true ;
275+ queryItem . status = QueryStatus . Completed ;
276+ queryItem . failureReason = undefined ;
277+ const queryResult = this . mapQueryResult ( executionEndTime , resultIndex , queryItem . queryId ) ;
278+
279+ await this . storeJsonFile ( queryItem , 'query-result.json' , queryResult ) ;
280+
281+ // Kick off auto-download of results in the background.
282+ void commands . executeCommand ( 'codeQL.autoDownloadRemoteQueryResults' , queryResult ) ;
283+
284+ // Ask if the user wants to open the results in the background.
285+ void this . askToOpenResults ( queryItem . remoteQuery , queryResult ) . then (
286+ noop ,
287+ err => {
288+ void showAndLogErrorMessage ( err ) ;
289+ }
290+ ) ;
291+ } else {
292+ void showAndLogErrorMessage ( `There was an issue retrieving the result for the query ${ queryItem . remoteQuery . queryName } ` ) ;
293+ queryItem . status = QueryStatus . Failed ;
294+ }
295+ }
285296}
0 commit comments