@@ -18,13 +18,14 @@ import { join, dirname, parse } from "path";
1818import { tryGetQueryMetadata } from "../codeql-cli/query-metadata" ;
1919import { window as Window } from "vscode" ;
2020import { pluralize } from "../common/word" ;
21- import { glob } from "glob" ;
2221import { readRepoTask } from "./repo-tasks-store" ;
2322import { unlink , mkdtemp , readFile , writeFile } from "fs/promises" ;
2423import { tmpdir } from "os" ;
2524import { spawn } from "child_process" ;
2625import type { execFileSync } from "child_process" ;
2726import { tryOpenExternalFile } from "../common/vscode/external-files" ;
27+ import type { VariantAnalysisManager } from "./variant-analysis-manager" ;
28+ import type { VariantAnalysisResultsManager } from "./variant-analysis-results-manager" ;
2829
2930// Limit to three repos when generating autofixes so not sending
3031// too many requests to autofix. Since we only need to validate
@@ -38,12 +39,12 @@ const MAX_NUM_FIXES: number = 3;
3839 * Generates autofixes for the results of a variant analysis.
3940 */
4041export async function viewAutofixesForVariantAnalysisResults (
42+ variantAnalysisManager : VariantAnalysisManager ,
43+ variantAnalysisResultsManager : VariantAnalysisResultsManager ,
4144 variantAnalysisId : number ,
4245 filterSort : RepositoriesFilterSortStateWithIds = defaultFilterSortState ,
43- variantAnalyses : Map < number , VariantAnalysis > ,
4446 credentials : Credentials ,
4547 logger : NotificationLogger ,
46- storagePath : string ,
4748 app : App ,
4849 cliServer : CodeQLCliServer ,
4950) : Promise < void > {
@@ -53,7 +54,8 @@ export async function viewAutofixesForVariantAnalysisResults(
5354 const localAutofixPath = await findLocalAutofix ( ) ;
5455
5556 // Get the variant analysis with the given id.
56- const variantAnalysis = variantAnalyses . get ( variantAnalysisId ) ;
57+ const variantAnalysis =
58+ variantAnalysisManager . tryGetVariantAnalysis ( variantAnalysisId ) ;
5759 if ( ! variantAnalysis ) {
5860 throw new Error ( `No variant analysis with id: ${ variantAnalysisId } ` ) ;
5961 }
@@ -72,7 +74,7 @@ export async function viewAutofixesForVariantAnalysisResults(
7274 variantAnalysisIdStoragePath,
7375 sourceRootsStoragePath,
7476 autofixOutputStoragePath,
75- } = await getStoragePaths ( variantAnalysisId , storagePath ) ;
77+ } = await getStoragePaths ( variantAnalysisManager , variantAnalysisId ) ;
7678
7779 // Process the selected repositories:
7880 // Get sarif
@@ -86,6 +88,7 @@ export async function viewAutofixesForVariantAnalysisResults(
8688 ) ,
8789 ) ;
8890 const outputTextFiles = await processSelectedRepositories (
91+ variantAnalysisResultsManager ,
8992 selectedRepoNames ,
9093 variantAnalysisIdStoragePath ,
9194 sourceRootsStoragePath ,
@@ -237,21 +240,19 @@ function getSelectedRepositoryNames(
237240 * Gets the storage paths needed for the autofix results.
238241 */
239242async function getStoragePaths (
243+ variantAnalysisManager : VariantAnalysisManager ,
240244 variantAnalysisId : number ,
241- storagePath : string ,
242245) : Promise < {
243246 variantAnalysisIdStoragePath : string ;
244247 sourceRootsStoragePath : string ;
245248 autofixOutputStoragePath : string ;
246249} > {
247250 // Confirm storage path for the variant analysis ID exists.
248- const variantAnalysisIdStoragePath = join (
249- storagePath ,
250- variantAnalysisId . toString ( ) ,
251- ) ;
251+ const variantAnalysisIdStoragePath =
252+ variantAnalysisManager . getVariantAnalysisStorageLocation ( variantAnalysisId ) ;
252253 if ( ! ( await pathExists ( variantAnalysisIdStoragePath ) ) ) {
253254 throw new Error (
254- `Variant analysis storage path does not exist: ${ variantAnalysisIdStoragePath } ` ,
255+ `Variant analysis storage location does not exist: ${ variantAnalysisIdStoragePath } ` ,
255256 ) ;
256257 }
257258
@@ -286,6 +287,7 @@ async function getStoragePaths(
286287 * Processes the selected repositories for autofix generation.
287288 */
288289async function processSelectedRepositories (
290+ variantAnalysisResultsManager : VariantAnalysisResultsManager ,
289291 selectedRepoNames : string [ ] ,
290292 variantAnalysisIdStoragePath : string ,
291293 sourceRootsStoragePath : string ,
@@ -301,13 +303,20 @@ async function processSelectedRepositories(
301303 async ( progressForRepo : ProgressCallback ) => {
302304 // Get the sarif file.
303305 progressForRepo ( progressUpdate ( 1 , 3 , `Getting sarif` ) ) ;
304- const repoStoragePath = join ( variantAnalysisIdStoragePath , nwo ) ;
305- const sarifFile = await getSarifFile ( repoStoragePath , nwo ) ;
306+ const sarifFile = await getRepoSarifFile (
307+ variantAnalysisResultsManager ,
308+ variantAnalysisIdStoragePath ,
309+ nwo ,
310+ ) ;
306311
307312 // Read the contents of the variant analysis' `repo_task.json` file,
308313 // and confirm that the `databaseCommitSha` and `resultCount` exist.
309- const repoTask : VariantAnalysisRepositoryTask =
310- await readRepoTask ( repoStoragePath ) ;
314+ const repoTask : VariantAnalysisRepositoryTask = await readRepoTask (
315+ variantAnalysisResultsManager . getRepoStorageDirectory (
316+ variantAnalysisIdStoragePath ,
317+ nwo ,
318+ ) ,
319+ ) ;
311320 if ( ! repoTask . databaseCommitSha ) {
312321 throw new Error ( `Missing database commit SHA for ${ nwo } ` ) ;
313322 }
@@ -352,22 +361,30 @@ async function processSelectedRepositories(
352361}
353362
354363/**
355- * Gets the path to a SARIF file in a given `repoStoragePath `.
364+ * Gets the path to a SARIF file for a given `nwo `.
356365 */
357- async function getSarifFile (
358- repoStoragePath : string ,
366+ async function getRepoSarifFile (
367+ variantAnalysisResultsManager : VariantAnalysisResultsManager ,
368+ variantAnalysisIdStoragePath : string ,
359369 nwo : string ,
360370) : Promise < string > {
361- // Get results directory path.
362- const repoResultsStoragePath = join ( repoStoragePath , "results" ) ;
363- // Find sarif file.
364- const sarifFiles = await glob ( `${ repoResultsStoragePath } /**/*.sarif` ) ;
365- if ( sarifFiles . length !== 1 ) {
366- throw new Error (
367- `Expected to find exactly one \`*.sarif\` file for ${ nwo } , but found ${ sarifFiles . length } .` ,
371+ if (
372+ ! ( await variantAnalysisResultsManager . isVariantAnalysisRepoDownloaded (
373+ variantAnalysisIdStoragePath ,
374+ nwo ,
375+ ) )
376+ ) {
377+ throw new Error ( `Variant analysis results not downloaded for ${ nwo } ` ) ;
378+ }
379+ const sarifFile =
380+ variantAnalysisResultsManager . getRepoResultsSarifStoragePath (
381+ variantAnalysisIdStoragePath ,
382+ nwo ,
368383 ) ;
384+ if ( ! ( await pathExists ( sarifFile ) ) ) {
385+ throw new Error ( `SARIF file not found for ${ nwo } ` ) ;
369386 }
370- return sarifFiles [ 0 ] ;
387+ return sarifFile ;
371388}
372389
373390/**
0 commit comments