1- import {
2- pathExists ,
3- mkdir ,
4- outputJson ,
5- writeFileSync ,
6- readJson ,
7- } from "fs-extra" ;
1+ import { appendFile , pathExists , mkdir , outputJson , readJson } from "fs-extra" ;
2+ import fetch from "node-fetch" ;
83import { EOL } from "os" ;
94import { join } from "path" ;
105
11- import { Credentials } from "../common/authentication" ;
126import { Logger } from "../common" ;
137import { AnalysisAlert , AnalysisRawResults } from "./shared/analysis-result" ;
148import { sarifParser } from "../sarif-parser" ;
@@ -21,7 +15,6 @@ import {
2115 VariantAnalysisScannedRepositoryResult ,
2216} from "./shared/variant-analysis" ;
2317import { DisposableObject , DisposeHandler } from "../pure/disposable-object" ;
24- import { getVariantAnalysisRepoResult } from "./gh-api/gh-api-client" ;
2518import { EventEmitter } from "vscode" ;
2619import { unzipFile } from "../pure/zip" ;
2720
@@ -63,7 +56,6 @@ export class VariantAnalysisResultsManager extends DisposableObject {
6356 readonly onResultLoaded = this . _onResultLoaded . event ;
6457
6558 constructor (
66- private readonly credentials : Credentials ,
6759 private readonly cliServer : CodeQLCliServer ,
6860 private readonly logger : Logger ,
6961 ) {
@@ -75,6 +67,7 @@ export class VariantAnalysisResultsManager extends DisposableObject {
7567 variantAnalysisId : number ,
7668 repoTask : VariantAnalysisRepositoryTask ,
7769 variantAnalysisStoragePath : string ,
70+ onDownloadPercentageChanged : ( downloadPercentage : number ) => Promise < void > ,
7871 ) : Promise < void > {
7972 if ( ! repoTask . artifactUrl ) {
8073 throw new Error ( "Missing artifact URL" ) ;
@@ -85,11 +78,6 @@ export class VariantAnalysisResultsManager extends DisposableObject {
8578 repoTask . repository . fullName ,
8679 ) ;
8780
88- const result = await getVariantAnalysisRepoResult (
89- this . credentials ,
90- repoTask . artifactUrl ,
91- ) ;
92-
9381 if ( ! ( await pathExists ( resultDirectory ) ) ) {
9482 await mkdir ( resultDirectory , { recursive : true } ) ;
9583 }
@@ -100,12 +88,22 @@ export class VariantAnalysisResultsManager extends DisposableObject {
10088 ) ;
10189
10290 const zipFilePath = join ( resultDirectory , "results.zip" ) ;
91+
92+ const response = await fetch ( repoTask . artifactUrl ) ;
93+ let amountDownloaded = 0 ;
94+ for await ( const chunk of response . body ) {
95+ await appendFile ( zipFilePath , Buffer . from ( chunk ) ) ;
96+ amountDownloaded += chunk . length ;
97+ await onDownloadPercentageChanged (
98+ Math . floor ( ( amountDownloaded / response . size ) * 100 ) ,
99+ ) ;
100+ }
101+
103102 const unzippedFilesDirectory = join (
104103 resultDirectory ,
105104 VariantAnalysisResultsManager . RESULTS_DIRECTORY ,
106105 ) ;
107106
108- writeFileSync ( zipFilePath , Buffer . from ( result ) ) ;
109107 await unzipFile ( zipFilePath , unzippedFilesDirectory ) ;
110108
111109 this . _onResultDownloaded . fire ( {
0 commit comments