-
Notifications
You must be signed in to change notification settings - Fork 226
Monitor remote query run and render results #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
41f712e
Monitor remote query run and render results
charisk 185c440
Rename React component to make code clearer
charisk 75507fd
Address some review comments
charisk a4add55
Move file and simplify status checks
charisk cfa9bb1
Fixed bad file move
charisk fae9fb4
Apply suggestions from code review
charisk 4364f11
Address feedback and fix command run
charisk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
extensions/ql-vscode/src/remote-queries/remote-queries-manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { CancellationToken, commands, ExtensionContext, Uri, window } from 'vscode'; | ||
| import { Credentials } from '../authentication'; | ||
| import { CodeQLCliServer } from '../cli'; | ||
| import { ProgressCallback } from '../commandRunner'; | ||
| import { showAndLogErrorMessage, showInformationMessageWithAction } from '../helpers'; | ||
| import { Logger } from '../logging'; | ||
| import { getResultIndex, ResultIndexItem, runRemoteQuery } from './run-remote-query'; | ||
| import { RemoteQueriesInterfaceManager } from './remote-queries-interface'; | ||
| import { RemoteQuery } from './remote-query'; | ||
| import { RemoteQueriesMonitor } from './remote-queries-monitor'; | ||
| import { RemoteQueryResult } from './remote-query-result'; | ||
|
|
||
| export class RemoteQueriesManager { | ||
| private readonly remoteQueriesMonitor: RemoteQueriesMonitor; | ||
|
|
||
| constructor( | ||
| private readonly ctx: ExtensionContext, | ||
| private readonly logger: Logger, | ||
| private readonly cliServer: CodeQLCliServer | ||
| ) { | ||
| this.remoteQueriesMonitor = new RemoteQueriesMonitor(ctx, logger); | ||
| } | ||
|
|
||
| public async runRemoteQuery( | ||
| uri: Uri | undefined, | ||
| progress: ProgressCallback, | ||
| token: CancellationToken | ||
| ): Promise<void> { | ||
| const credentials = await Credentials.initialize(this.ctx); | ||
|
|
||
| const querySubmission = await runRemoteQuery( | ||
| this.cliServer, | ||
| credentials, uri || window.activeTextEditor?.document.uri, | ||
| false, | ||
| progress, | ||
| token); | ||
|
|
||
| if (querySubmission && querySubmission.query) { | ||
| void commands.executeCommand('codeQL.monitorRemoteQuery', querySubmission.query); | ||
| } | ||
| } | ||
|
|
||
| public async monitorRemoteQuery( | ||
|
charisk marked this conversation as resolved.
|
||
| query: RemoteQuery, | ||
| cancellationToken: CancellationToken | ||
| ): Promise<void> { | ||
| const credentials = await Credentials.initialize(this.ctx); | ||
|
|
||
| const queryResult = await this.remoteQueriesMonitor.monitorQuery(query, cancellationToken); | ||
|
|
||
| const executionEndTime = new Date(); | ||
|
|
||
| if (queryResult.status === 'CompletedSuccessfully') { | ||
| const resultIndexItems = await this.downloadResultIndex(credentials, query); | ||
|
|
||
| const totalResultCount = resultIndexItems.reduce((acc, cur) => acc + cur.results_count, 0); | ||
| const message = `Query "${query.queryName}" run on ${query.repositories.length} repositories and returned ${totalResultCount} results`; | ||
|
|
||
| const shouldOpenView = await showInformationMessageWithAction(message, 'View'); | ||
| if (shouldOpenView) { | ||
| const queryResult = this.mapQueryResult(executionEndTime, resultIndexItems); | ||
| const rqim = new RemoteQueriesInterfaceManager(this.ctx, this.logger); | ||
| await rqim.showResults(query, queryResult); | ||
| } | ||
| } else if (queryResult.status === 'CompletedUnsuccessfully') { | ||
| await showAndLogErrorMessage(`Remote query execution failed. Error: ${queryResult.error}`); | ||
| return; | ||
| } else if (queryResult.status === 'Cancelled') { | ||
| await showAndLogErrorMessage('Remote query monitoring was cancelled'); | ||
| } | ||
| } | ||
|
|
||
| private async downloadResultIndex(credentials: Credentials, query: RemoteQuery) { | ||
| return await getResultIndex( | ||
| credentials, | ||
| query.controllerRepository.owner, | ||
| query.controllerRepository.name, | ||
| query.actionsWorkflowRunId); | ||
| } | ||
|
|
||
| private mapQueryResult(executionEndTime: Date, resultindexItems: ResultIndexItem[]): RemoteQueryResult { | ||
| // Example URIs are used for now, but a solution for downloading the results will soon be implemented. | ||
| const allResultsDownloadUri = 'www.example.com'; | ||
| const analysisDownloadUri = 'www.example.com'; | ||
|
|
||
| const analysisResults = resultindexItems.map(ri => ({ | ||
| nwo: ri.nwo, | ||
| resultCount: ri.results_count, | ||
| downloadUri: analysisDownloadUri, | ||
| fileSizeInBytes: ri.sarif_file_size || ri.bqrs_file_size, | ||
| }) | ||
| ); | ||
|
|
||
| return { | ||
| executionEndTime, | ||
| analysisResults, | ||
| allResultsDownloadUri, | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.