@@ -34,6 +34,7 @@ import type {
34
34
} from './models.js' ;
35
35
import type { ProjectConfig } from './monorepo/index.js' ;
36
36
import { saveOutputFiles } from './output-files.js' ;
37
+ import { downloadReportFromPortal } from './portal/download.js' ;
37
38
38
39
export type RunEnv = {
39
40
refs : NormalizedGitRefs ;
@@ -58,6 +59,7 @@ export type CompareReportsArgs = {
58
59
59
60
export type BaseReportArgs = {
60
61
project : ProjectConfig | null ;
62
+ config : EnhancedPersistConfig ;
61
63
env : RunEnv ;
62
64
base : GitBranch ;
63
65
ctx : CommandContext ;
@@ -139,7 +141,8 @@ export async function runOnProject(
139
141
`PR/MR detected, preparing to compare base branch ${ base . ref } to head ${ head . ref } ` ,
140
142
) ;
141
143
142
- const prevReport = await collectPreviousReport ( { project, env, base, ctx } ) ;
144
+ const baseArgs : BaseReportArgs = { project, env, base, config, ctx } ;
145
+ const prevReport = await collectPreviousReport ( baseArgs ) ;
143
146
if ( ! prevReport ) {
144
147
return noDiffOutput ;
145
148
}
@@ -243,37 +246,89 @@ export async function loadCachedBaseReport(
243
246
) : Promise < ReportData < 'previous' > | null > {
244
247
const {
245
248
project,
249
+ env : { settings } ,
250
+ } = args ;
251
+
252
+ const cachedBaseReport =
253
+ ( await loadCachedBaseReportFromPortal ( args ) ) ??
254
+ ( await loadCachedBaseReportFromArtifacts ( args ) ) ;
255
+
256
+ if ( ! cachedBaseReport ) {
257
+ return null ;
258
+ }
259
+ return saveReportFiles ( {
260
+ project,
261
+ type : 'previous' ,
262
+ files : { json : cachedBaseReport } ,
263
+ settings,
264
+ } ) ;
265
+ }
266
+
267
+ async function loadCachedBaseReportFromArtifacts (
268
+ args : BaseReportArgs ,
269
+ ) : Promise < string | null > {
270
+ const {
246
271
env : { api, settings } ,
272
+ project,
247
273
} = args ;
248
274
const { logger } = settings ;
249
275
250
- const cachedBaseReport = await api
251
- . downloadReportArtifact ?.( project ?. name )
276
+ if ( api . downloadReportArtifact == null ) {
277
+ return null ;
278
+ }
279
+
280
+ const reportPath = await api
281
+ . downloadReportArtifact ( project ?. name )
252
282
. catch ( ( error : unknown ) => {
253
283
logger . warn (
254
284
`Error when downloading previous report artifact, skipping - ${ stringifyError ( error ) } ` ,
255
285
) ;
286
+ return null ;
256
287
} ) ;
257
- if ( api . downloadReportArtifact != null ) {
258
- logger . info (
259
- `Previous report artifact ${ cachedBaseReport ? 'found' : 'not found' } ` ,
260
- ) ;
261
- if ( cachedBaseReport ) {
262
- logger . debug (
263
- `Previous report artifact downloaded to ${ cachedBaseReport } ` ,
264
- ) ;
265
- }
288
+
289
+ logger . info ( `Previous report artifact ${ reportPath ? 'found' : 'not found' } ` ) ;
290
+ if ( reportPath ) {
291
+ logger . debug ( `Previous report artifact downloaded to ${ reportPath } ` ) ;
266
292
}
267
293
268
- if ( ! cachedBaseReport ) {
294
+ return reportPath ;
295
+ }
296
+
297
+ async function loadCachedBaseReportFromPortal (
298
+ args : BaseReportArgs ,
299
+ ) : Promise < string | null > {
300
+ const {
301
+ config,
302
+ env : { settings } ,
303
+ } = args ;
304
+ const { logger } = settings ;
305
+
306
+ if ( ! config . upload ) {
269
307
return null ;
270
308
}
271
- return saveReportFiles ( {
272
- project,
273
- type : 'previous' ,
274
- files : { json : cachedBaseReport } ,
275
- settings,
309
+
310
+ const reportPath = await downloadReportFromPortal ( {
311
+ server : config . upload . server ,
312
+ apiKey : config . upload . apiKey ,
313
+ parameters : {
314
+ organization : config . upload . organization ,
315
+ project : config . upload . project ,
316
+ } ,
317
+ } ) . catch ( ( error : unknown ) => {
318
+ logger . warn (
319
+ `Error when downloading previous report from portal, skipping - ${ stringifyError ( error ) } ` ,
320
+ ) ;
321
+ return null ;
276
322
} ) ;
323
+
324
+ logger . info (
325
+ `Previous report ${ reportPath ? 'found' : 'not found' } in Code PushUp portal` ,
326
+ ) ;
327
+ if ( reportPath ) {
328
+ logger . debug ( `Previous report downloaded from portal to ${ reportPath } ` ) ;
329
+ }
330
+
331
+ return reportPath ;
277
332
}
278
333
279
334
export async function runInBaseBranch < T > (
0 commit comments