@@ -218,22 +218,10 @@ func createReport(ctx context.Context, cfg *createCfg, iss *issues.Issue) (r *re
218
218
return nil , err
219
219
}
220
220
221
- aliases := allAliases (ctx , parsed .aliases , cfg .ghsaClient )
222
- if alias , ok := pickBestAlias (aliases , * preferCVE ); ok {
223
- log .Infof ("creating report %s based on %s (picked from [%s])" , parsed .id , alias , strings .Join (aliases , ", " ))
224
- r , err = reportFromAlias (ctx , parsed .id , parsed .modulePath , alias , cfg )
225
- if err != nil {
226
- return nil , err
227
- }
228
- } else {
229
- log .Infof ("no alias found, creating basic report for %s" , parsed .id )
230
- r = & report.Report {
231
- ID : parsed .id ,
232
- Modules : []* report.Module {
233
- {
234
- Module : parsed .modulePath ,
235
- },
236
- }}
221
+ r , err = reportFromAliases (ctx , parsed .id , parsed .modulePath , parsed .aliases ,
222
+ cfg .proxyClient , cfg .ghsaClient , cfg .aiClient )
223
+ if err != nil {
224
+ return nil , err
237
225
}
238
226
239
227
if parsed .excluded != "" {
@@ -250,14 +238,38 @@ func createReport(ctx context.Context, cfg *createCfg, iss *issues.Issue) (r *re
250
238
}
251
239
}
252
240
241
+ addTODOs (r )
242
+ return r , nil
243
+ }
244
+
245
+ func reportFromAliases (ctx context.Context , id , modulePath string , aliases []string ,
246
+ pc * proxy.Client , gc * ghsa.Client , ac * genai.GeminiClient ) (r * report.Report , err error ) {
247
+ aliases = allAliases (ctx , aliases , gc )
248
+ if alias , ok := pickBestAlias (aliases , * preferCVE ); ok {
249
+ log .Infof ("creating report %s based on %s (picked from [%s])" , id , alias , strings .Join (aliases , ", " ))
250
+ r , err = reportFromAlias (ctx , id , modulePath , alias , pc , gc )
251
+ if err != nil {
252
+ return nil , err
253
+ }
254
+ } else {
255
+ log .Infof ("no alias found, creating basic report for %s" , id )
256
+ r = & report.Report {
257
+ ID : id ,
258
+ Modules : []* report.Module {
259
+ {
260
+ Module : modulePath ,
261
+ },
262
+ }}
263
+ }
264
+
253
265
// Ensure all source aliases are added to the report.
254
266
r .AddAliases (aliases )
255
267
256
268
// Find any additional aliases referenced by the source aliases.
257
- addMissingAliases (ctx , r , cfg . ghsaClient )
269
+ addMissingAliases (ctx , r , gc )
258
270
259
- if cfg . aiClient != nil {
260
- suggestions , err := suggest (ctx , cfg . aiClient , r , 1 )
271
+ if ac != nil {
272
+ suggestions , err := suggest (ctx , ac , r , 1 )
261
273
if err != nil {
262
274
log .Warnf ("failed to get AI-generated suggestions for %s: %v\n " , r .ID , err )
263
275
} else if len (suggestions ) == 0 {
@@ -268,7 +280,6 @@ func createReport(ctx context.Context, cfg *createCfg, iss *issues.Issue) (r *re
268
280
}
269
281
}
270
282
271
- addTODOs (r )
272
283
return r , nil
273
284
}
274
285
@@ -353,22 +364,22 @@ Adds excluded reports:
353
364
// reportFromBestAlias returns a new report created from the "best" alias in the list.
354
365
// For now, it prefers the first GHSA in the list, followed by the first CVE in the list
355
366
// (if no GHSA is present). If no GHSAs or CVEs are present, it returns a new empty Report.
356
- func reportFromAlias (ctx context.Context , id , modulePath , alias string , cfg * createCfg ) (* report.Report , error ) {
367
+ func reportFromAlias (ctx context.Context , id , modulePath , alias string , pc * proxy. Client , gc * ghsa. Client ) (* report.Report , error ) {
357
368
switch {
358
369
case ghsa .IsGHSA (alias ) && * graphQL :
359
- ghsa , err := cfg . ghsaClient .FetchGHSA (ctx , alias )
370
+ ghsa , err := gc .FetchGHSA (ctx , alias )
360
371
if err != nil {
361
372
return nil , err
362
373
}
363
- r := report .GHSAToReport (ghsa , modulePath , cfg . proxyClient )
374
+ r := report .GHSAToReport (ghsa , modulePath , pc )
364
375
r .ID = id
365
376
return r , nil
366
377
case ghsa .IsGHSA (alias ):
367
378
ghsa , err := genericosv .Fetch (alias )
368
379
if err != nil {
369
380
return nil , err
370
381
}
371
- return ghsa .ToReport (id , cfg . proxyClient ), nil
382
+ return ghsa .ToReport (id , pc ), nil
372
383
case cveschema5 .IsCVE (alias ):
373
384
cve , err := cveclient .Fetch (alias )
374
385
if err != nil {
@@ -377,7 +388,7 @@ func reportFromAlias(ctx context.Context, id, modulePath, alias string, cfg *cre
377
388
log .Infof ("no published record found for %s, creating basic report" , alias )
378
389
return basicReport (id , modulePath ), nil
379
390
}
380
- return report .CVE5ToReport (cve , id , modulePath , cfg . proxyClient ), nil
391
+ return report .CVE5ToReport (cve , id , modulePath , pc ), nil
381
392
}
382
393
383
394
log .Infof ("alias %s is not a CVE or GHSA, creating basic report" , alias )
0 commit comments