@@ -145,12 +145,14 @@ func (a *Analyzer) AnalyzeOrg(ctx context.Context, org string, numberOfGoroutine
145145 }
146146 }()
147147
148+ discoveryCompleted := false
148149 for repoBatch := range orgReposBatches {
149150 if repoBatch .Err != nil {
150151 log .Error ().Err (repoBatch .Err ).Msg ("failed to fetch batch of repos, skipping batch" )
151152 continue
152153 }
153- if repoBatch .TotalCount != 0 {
154+ if ! discoveryCompleted && repoBatch .TotalCount != 0 {
155+ discoveryCompleted = true
154156 obs .OnDiscoveryCompleted (org , repoBatch .TotalCount )
155157 }
156158
@@ -242,7 +244,6 @@ func (a *Analyzer) AnalyzeOrg(ctx context.Context, org string, numberOfGoroutine
242244 obs .OnFinalizeStarted (len (scannedPackages ))
243245 err = a .finalizeAnalysis (ctx , scannedPackages )
244246 if err != nil {
245- obs .OnFinalizeCompleted ()
246247 return scannedPackages , err
247248 }
248249 obs .OnFinalizeCompleted ()
@@ -281,6 +282,7 @@ func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string,
281282 repoUrl := repo .BuildGitURL (a .ScmClient .GetProviderBaseURL ())
282283 repoKey , err := a .fetchCone (ctx , repoUrl , a .ScmClient .GetToken (), "refs/heads/*:refs/remotes/origin/*" , ".github/workflows" )
283284 if err != nil {
285+ obs .OnRepoError (repoString , err )
284286 return nil , fmt .Errorf ("failed to fetch cone: %w" , err )
285287 }
286288 defer a .GitClient .Cleanup (repoKey )
@@ -290,6 +292,7 @@ func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string,
290292
291293 workflows , err := a .GitClient .GetUniqWorkflowsBranches (ctx , repoKey )
292294 if err != nil {
295+ obs .OnRepoError (repoString , err )
293296 return nil , fmt .Errorf ("failed to get unique workflow: %w" , err )
294297 }
295298
@@ -355,13 +358,15 @@ func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string,
355358 close (filesChan )
356359 wgConsumer .Wait ()
357360 for err := range errChan {
361+ obs .OnRepoError (repoString , err )
358362 return nil , err
359363 }
360364
361365 bar .Describe ("Scanning package" )
362366 _ = bar .Add (1 )
363367 pkg , err := a .GeneratePackageInsights (ctx , repoKey , repo , "HEAD" )
364368 if err != nil {
369+ obs .OnRepoError (repoString , err )
365370 return nil , fmt .Errorf ("failed to generate package insight: %w" , err )
366371 }
367372
@@ -374,6 +379,7 @@ func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string,
374379
375380 scannedPackage , err := inventory .ScanPackageScanner (ctx , * pkg , & inventoryScanner )
376381 if err != nil {
382+ obs .OnRepoError (repoString , err )
377383 return nil , fmt .Errorf ("failed to scan package: %w" , err )
378384 }
379385
@@ -403,7 +409,6 @@ func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string,
403409 scannedPackage .FindingsResults .Findings = expanded
404410
405411 if err := a .Formatter .Format (ctx , []* models.PackageInsights {scannedPackage }); err != nil {
406- obs .OnFinalizeCompleted ()
407412 return nil , fmt .Errorf ("failed to finalize analysis of package: %w" , err )
408413 }
409414 } else {
@@ -417,7 +422,6 @@ func (a *Analyzer) AnalyzeStaleBranches(ctx context.Context, repoString string,
417422 }
418423
419424 if err := a .Formatter .FormatWithPath (ctx , []* models.PackageInsights {scannedPackage }, results ); err != nil {
420- obs .OnFinalizeCompleted ()
421425 return nil , fmt .Errorf ("failed to finalize analysis of package: %w" , err )
422426 }
423427 }
@@ -455,6 +459,7 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
455459 obs .OnRepoStarted (repoString )
456460 repoKey , err := a .cloneRepo (ctx , repo .BuildGitURL (a .ScmClient .GetProviderBaseURL ()), a .ScmClient .GetToken (), ref )
457461 if err != nil {
462+ obs .OnRepoError (repoString , err )
458463 return nil , err
459464 }
460465 defer a .GitClient .Cleanup (repoKey )
@@ -464,11 +469,13 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
464469
465470 pkg , err := a .GeneratePackageInsights (ctx , repoKey , repo , ref )
466471 if err != nil {
472+ obs .OnRepoError (repoString , err )
467473 return nil , err
468474 }
469475
470476 files , err := a .GitClient .ListFiles (repoKey , []string {".yml" , ".yaml" })
471477 if err != nil {
478+ obs .OnRepoError (repoString , err )
472479 return nil , fmt .Errorf ("failed to list files: %w" , err )
473480 }
474481
@@ -485,6 +492,7 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
485492
486493 scannedPackage , err := inventory .ScanPackageScanner (ctx , * pkg , memScanner )
487494 if err != nil {
495+ obs .OnRepoError (repoString , err )
488496 return nil , err
489497 }
490498 _ = bar .Finish ()
@@ -493,7 +501,6 @@ func (a *Analyzer) AnalyzeRepo(ctx context.Context, repoString string, ref strin
493501 obs .OnFinalizeStarted (1 )
494502 err = a .finalizeAnalysis (ctx , []* models.PackageInsights {scannedPackage })
495503 if err != nil {
496- obs .OnFinalizeCompleted ()
497504 return nil , err
498505 }
499506 obs .OnFinalizeCompleted ()
0 commit comments