-
Notifications
You must be signed in to change notification settings - Fork 226
Download variant analysis results #1559
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
elenatanasoiu
merged 11 commits into
main
from
elenatanasoiu/download-variant-analysis-results
Oct 5, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3bf27b3
Set up factories for VSCode VariantAnalysis
elenatanasoiu a47031b
Call monitor from new VariantAnalysisManager class
elenatanasoiu deac8c8
Add API method for download scanned repo result
elenatanasoiu 765c956
Introduce download method on VariantAnalysisManager
elenatanasoiu 5e76c08
Only import what we need from vscode in VariantAnalysisMonitor
elenatanasoiu 4f84376
Make monitor trigger autodownload of result when a new repo is scanned
elenatanasoiu 644a83d
Only use safe navigator for optional fields
elenatanasoiu 7dc5eeb
Generate a real NotFoundRepoGroup
elenatanasoiu f56f017
Generate ids using faker for test factories
elenatanasoiu b82cd8b
Use real cancellation token match VSCode behaviour
elenatanasoiu bb7246b
Pass in variant analysis summary to autodownload command
elenatanasoiu 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
81 changes: 81 additions & 0 deletions
81
extensions/ql-vscode/src/remote-queries/variant-analysis-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,81 @@ | ||
| import * as ghApiClient from './gh-api/gh-api-client'; | ||
| import * as path from 'path'; | ||
| import * as fs from 'fs-extra'; | ||
| import { CancellationToken, ExtensionContext } from 'vscode'; | ||
| import { DisposableObject } from '../pure/disposable-object'; | ||
| import { Logger } from '../logging'; | ||
| import { Credentials } from '../authentication'; | ||
| import { VariantAnalysisMonitor } from './variant-analysis-monitor'; | ||
| import { | ||
| VariantAnalysis as VariantAnalysisApiResponse, | ||
| VariantAnalysisRepoTask, | ||
| VariantAnalysisScannedRepository as ApiVariantAnalysisScannedRepository | ||
| } from './gh-api/variant-analysis'; | ||
| import { VariantAnalysis } from './shared/variant-analysis'; | ||
| import { getErrorMessage } from '../pure/helpers-pure'; | ||
|
|
||
| export class VariantAnalysisManager extends DisposableObject { | ||
| private readonly variantAnalysisMonitor: VariantAnalysisMonitor; | ||
|
|
||
| constructor( | ||
| private readonly ctx: ExtensionContext, | ||
| logger: Logger, | ||
| ) { | ||
| super(); | ||
| this.variantAnalysisMonitor = new VariantAnalysisMonitor(ctx, logger); | ||
| } | ||
|
|
||
| public async monitorVariantAnalysis( | ||
| variantAnalysis: VariantAnalysis, | ||
| cancellationToken: CancellationToken | ||
| ): Promise<void> { | ||
| await this.variantAnalysisMonitor.monitorVariantAnalysis(variantAnalysis, cancellationToken); | ||
| } | ||
|
|
||
| public async autoDownloadVariantAnalysisResult( | ||
| scannedRepo: ApiVariantAnalysisScannedRepository, | ||
| variantAnalysisSummary: VariantAnalysisApiResponse, | ||
| cancellationToken: CancellationToken | ||
| ): Promise<void> { | ||
|
|
||
| const credentials = await Credentials.initialize(this.ctx); | ||
| if (!credentials) { throw Error('Error authenticating with GitHub'); } | ||
|
|
||
| if (cancellationToken && cancellationToken.isCancellationRequested) { | ||
| return; | ||
| } | ||
|
|
||
| let repoTask: VariantAnalysisRepoTask; | ||
| try { | ||
| repoTask = await ghApiClient.getVariantAnalysisRepo( | ||
| credentials, | ||
| variantAnalysisSummary.controller_repo.id, | ||
| variantAnalysisSummary.id, | ||
| scannedRepo.repository.id | ||
| ); | ||
| } | ||
| catch (e) { throw new Error(`Could not download the results for variant analysis with id: ${variantAnalysisSummary.id}. Error: ${getErrorMessage(e)}`); } | ||
|
|
||
| if (repoTask.artifact_url) { | ||
| const resultDirectory = path.join( | ||
| this.ctx.globalStorageUri.fsPath, | ||
| 'variant-analyses', | ||
| `${variantAnalysisSummary.id}`, | ||
| scannedRepo.repository.full_name | ||
| ); | ||
|
|
||
| const storagePath = path.join( | ||
| resultDirectory, | ||
| scannedRepo.repository.full_name | ||
| ); | ||
|
|
||
| const result = await ghApiClient.getVariantAnalysisRepoResult( | ||
| credentials, | ||
| repoTask.artifact_url | ||
| ); | ||
|
|
||
| fs.mkdirSync(resultDirectory, { recursive: true }); | ||
| await fs.writeFile(storagePath, JSON.stringify(result, null, 2), 'utf8'); | ||
| } | ||
| } | ||
| } | ||
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
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.