@@ -376,6 +376,15 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
376
376
}
377
377
}
378
378
379
+ commentReporterManager := utils .InitCommentReporterManager (ghService , prNumber )
380
+ if _ , exists := os .LookupEnv ("DIGGER_REPORT_BEFORE_LOADING_CONFIG" ); exists {
381
+ _ , err := commentReporterManager .UpdateComment (":construction_worker: Digger starting...." )
382
+ if err != nil {
383
+ log .Printf ("Error initializing comment reporter: %v" , err )
384
+ return fmt .Errorf ("error initializing comment reporter" )
385
+ }
386
+ }
387
+
379
388
diggerYmlStr , ghService , config , projectsGraph , _ , _ , err := getDiggerConfigForPR (gh , installationId , repoFullName , repoOwner , repoName , cloneURL , prNumber )
380
389
if err != nil {
381
390
log .Printf ("getDiggerConfigForPR error: %v" , err )
@@ -385,14 +394,14 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
385
394
impactedProjects , impactedProjectsSourceMapping , _ , err := dg_github .ProcessGitHubPullRequestEvent (payload , config , projectsGraph , ghService )
386
395
if err != nil {
387
396
log .Printf ("Error processing event: %v" , err )
388
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: Error processing event: %v" , err ))
397
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Error processing event: %v" , err ))
389
398
return fmt .Errorf ("error processing event" )
390
399
}
391
400
392
401
jobsForImpactedProjects , _ , err := dg_github .ConvertGithubPullRequestEventToJobs (payload , impactedProjects , nil , * config , false )
393
402
if err != nil {
394
403
log .Printf ("Error converting event to jobsForImpactedProjects: %v" , err )
395
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: Error converting event to jobsForImpactedProjects: %v" , err ))
404
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Error converting event to jobsForImpactedProjects: %v" , err ))
396
405
return fmt .Errorf ("error converting event to jobsForImpactedProjects" )
397
406
}
398
407
@@ -408,7 +417,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
408
417
diggerCommand , err := orchestrator_scheduler .GetCommandFromJob (jobsForImpactedProjects [0 ])
409
418
if err != nil {
410
419
log .Printf ("could not determine digger command from job: %v" , jobsForImpactedProjects [0 ].Commands )
411
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: could not determine digger command from job: %v" , err ))
420
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: could not determine digger command from job: %v" , err ))
412
421
return fmt .Errorf ("unknown digger command in comment %v" , err )
413
422
}
414
423
@@ -432,7 +441,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
432
441
}
433
442
err = dg_locking .PerformLockingActionFromCommand (prLock , * diggerCommand )
434
443
if err != nil {
435
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: Failed perform lock action on project: %v %v" , project .Name , err ))
444
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Failed perform lock action on project: %v %v" , project .Name , err ))
436
445
return fmt .Errorf ("failed to perform lock action on project: %v, %v" , project .Name , err )
437
446
}
438
447
}
@@ -441,7 +450,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
441
450
// if commands are locking or unlocking we don't need to trigger any jobs
442
451
if * diggerCommand == orchestrator_scheduler .DiggerCommandUnlock ||
443
452
* diggerCommand == orchestrator_scheduler .DiggerCommandLock {
444
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":white_check_mark: Command %v completed successfully" , * diggerCommand ))
453
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":white_check_mark: Command %v completed successfully" , * diggerCommand ))
445
454
return nil
446
455
}
447
456
@@ -450,7 +459,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
450
459
return nil
451
460
}
452
461
453
- commentReporter , err := utils . InitCommentReporter ( ghService , prNumber , ":construction_worker: Digger starting..." )
462
+ commentReporter , err := commentReporterManager . UpdateComment ( ":construction_worker: Digger starting... Config loaded successfully " )
454
463
if err != nil {
455
464
log .Printf ("Error initializing comment reporter: %v" , err )
456
465
return fmt .Errorf ("error initializing comment reporter" )
@@ -459,14 +468,14 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
459
468
err = utils .ReportInitialJobsStatus (commentReporter , jobsForImpactedProjects )
460
469
if err != nil {
461
470
log .Printf ("Failed to comment initial status for jobs: %v" , err )
462
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: Failed to comment initial status for jobs: %v" , err ))
471
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Failed to comment initial status for jobs: %v" , err ))
463
472
return fmt .Errorf ("failed to comment initial status for jobs" )
464
473
}
465
474
466
475
err = utils .SetPRStatusForJobs (ghService , prNumber , jobsForImpactedProjects )
467
476
if err != nil {
468
477
log .Printf ("error setting status for PR: %v" , err )
469
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: error setting status for PR: %v" , err ))
478
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: error setting status for PR: %v" , err ))
470
479
fmt .Errorf ("error setting status for PR: %v" , err )
471
480
}
472
481
@@ -483,38 +492,38 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
483
492
commentId , err := strconv .ParseInt (commentReporter .CommentId , 10 , 64 )
484
493
if err != nil {
485
494
log .Printf ("strconv.ParseInt error: %v" , err )
486
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: could not handle commentId: %v" , err ))
495
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: could not handle commentId: %v" , err ))
487
496
}
488
497
batchId , _ , err := utils .ConvertJobsToDiggerJobs (* diggerCommand , models .DiggerVCSGithub , organisationId , impactedJobsMap , impactedProjectsMap , projectsGraph , installationId , branch , prNumber , repoOwner , repoName , repoFullName , commitSha , commentId , diggerYmlStr , 0 )
489
498
if err != nil {
490
499
log .Printf ("ConvertJobsToDiggerJobs error: %v" , err )
491
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: ConvertJobsToDiggerJobs error: %v" , err ))
500
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: ConvertJobsToDiggerJobs error: %v" , err ))
492
501
return fmt .Errorf ("error converting jobs" )
493
502
}
494
503
495
504
if config .CommentRenderMode == dg_configuration .CommentRenderModeGroupByModule {
496
505
sourceDetails , err := comment_updater .PostInitialSourceComments (ghService , prNumber , impactedProjectsSourceMapping )
497
506
if err != nil {
498
507
log .Printf ("PostInitialSourceComments error: %v" , err )
499
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
508
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
500
509
return fmt .Errorf ("error posting initial comments" )
501
510
}
502
511
batch , err := models .DB .GetDiggerBatch (batchId )
503
512
if err != nil {
504
513
log .Printf ("GetDiggerBatch error: %v" , err )
505
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
514
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
506
515
return fmt .Errorf ("error getting digger batch" )
507
516
}
508
517
batch .SourceDetails , err = json .Marshal (sourceDetails )
509
518
if err != nil {
510
519
log .Printf ("sourceDetails, json Marshal error: %v" , err )
511
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: json Marshal error: %v" , err ))
520
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: json Marshal error: %v" , err ))
512
521
return fmt .Errorf ("error marshalling sourceDetails" )
513
522
}
514
523
err = models .DB .UpdateDiggerBatch (batch )
515
524
if err != nil {
516
525
log .Printf ("UpdateDiggerBatch error: %v" , err )
517
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: UpdateDiggerBatch error: %v" , err ))
526
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: UpdateDiggerBatch error: %v" , err ))
518
527
return fmt .Errorf ("error updating digger batch" )
519
528
}
520
529
}
@@ -533,14 +542,14 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
533
542
)
534
543
if err != nil {
535
544
log .Printf ("GetCiBackend error: %v" , err )
536
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: GetCiBackend error: %v" , err ))
545
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: GetCiBackend error: %v" , err ))
537
546
return fmt .Errorf ("error fetching ci backed %v" , err )
538
547
}
539
548
540
549
err = TriggerDiggerJobs (ciBackend , repoFullName , repoOwner , repoName , batchId , prNumber , ghService , gh )
541
550
if err != nil {
542
551
log .Printf ("TriggerDiggerJobs error: %v" , err )
543
- utils . InitCommentReporter ( ghService , prNumber , fmt .Sprintf (":x: TriggerDiggerJobs error: %v" , err ))
552
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: TriggerDiggerJobs error: %v" , err ))
544
553
return fmt .Errorf ("error triggering Digger Jobs" )
545
554
}
546
555
@@ -678,14 +687,23 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
678
687
return nil
679
688
}
680
689
690
+ ghService , _ , ghServiceErr := utils .GetGithubService (gh , installationId , repoFullName , repoOwner , repoName )
691
+ if ghServiceErr != nil {
692
+ log .Printf ("GetGithubService error: %v" , err )
693
+ return fmt .Errorf ("error getting ghService to post error comment" )
694
+ }
695
+ commentReporterManager := utils .InitCommentReporterManager (ghService , issueNumber )
696
+ if _ , exists := os .LookupEnv ("DIGGER_REPORT_BEFORE_LOADING_CONFIG" ); exists {
697
+ _ , err := commentReporterManager .UpdateComment (":construction_worker: Digger starting...." )
698
+ if err != nil {
699
+ log .Printf ("Error initializing comment reporter: %v" , err )
700
+ return fmt .Errorf ("error initializing comment reporter" )
701
+ }
702
+ }
703
+
681
704
diggerYmlStr , ghService , config , projectsGraph , branch , commitSha , err := getDiggerConfigForPR (gh , installationId , repoFullName , repoOwner , repoName , cloneURL , issueNumber )
682
705
if err != nil {
683
- ghService , _ , gherr := utils .GetGithubService (gh , installationId , repoFullName , repoOwner , repoName )
684
- if gherr != nil {
685
- log .Printf ("GetGithubService error: %v" , gherr )
686
- return fmt .Errorf ("error getting ghService to post error comment" )
687
- }
688
- utils .InitCommentReporter (ghService , issueNumber , fmt .Sprintf (":x: Could not load digger config, error: %v" , err ))
706
+ commentReporterManager .UpdateComment (fmt .Sprintf (":x: Could not load digger config, error: %v" , err ))
689
707
log .Printf ("getDiggerConfigForPR error: %v" , err )
690
708
return fmt .Errorf ("error getting digger config" )
691
709
}
@@ -701,7 +719,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
701
719
return nil
702
720
}
703
721
704
- commentReporter , err := utils . InitCommentReporter ( ghService , issueNumber , ":construction_worker: Digger starting...." )
722
+ commentReporter , err := commentReporterManager . UpdateComment ( ":construction_worker: Digger starting.... config loaded successfully " )
705
723
if err != nil {
706
724
log .Printf ("Error initializing comment reporter: %v" , err )
707
725
return fmt .Errorf ("error initializing comment reporter" )
@@ -710,21 +728,21 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
710
728
diggerCommand , err := orchestrator_scheduler .GetCommandFromComment (* payload .Comment .Body )
711
729
if err != nil {
712
730
log .Printf ("unknown digger command in comment: %v" , * payload .Comment .Body )
713
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: Could not recognise comment, error: %v" , err ))
731
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Could not recognise comment, error: %v" , err ))
714
732
return fmt .Errorf ("unknown digger command in comment %v" , err )
715
733
}
716
734
717
735
prBranchName , _ , err := ghService .GetBranchName (issueNumber )
718
736
if err != nil {
719
737
log .Printf ("GetBranchName error: %v" , err )
720
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: GetBranchName error: %v" , err ))
738
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: GetBranchName error: %v" , err ))
721
739
return fmt .Errorf ("error while fetching branch name" )
722
740
}
723
741
724
742
impactedProjects , impactedProjectsSourceMapping , requestedProject , _ , err := generic .ProcessIssueCommentEvent (issueNumber , * payload .Comment .Body , config , projectsGraph , ghService )
725
743
if err != nil {
726
744
log .Printf ("Error processing event: %v" , err )
727
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: Error processing event: %v" , err ))
745
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Error processing event: %v" , err ))
728
746
return fmt .Errorf ("error processing event" )
729
747
}
730
748
log .Printf ("GitHub IssueComment event processed successfully\n " )
@@ -744,7 +762,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
744
762
}
745
763
err = dg_locking .PerformLockingActionFromCommand (prLock , * diggerCommand )
746
764
if err != nil {
747
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: Failed perform lock action on project: %v %v" , project .Name , err ))
765
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Failed perform lock action on project: %v %v" , project .Name , err ))
748
766
return fmt .Errorf ("failed perform lock action on project: %v %v" , project .Name , err )
749
767
}
750
768
}
@@ -753,22 +771,22 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
753
771
// if commands are locking or unlocking we don't need to trigger any jobs
754
772
if * diggerCommand == orchestrator_scheduler .DiggerCommandUnlock ||
755
773
* diggerCommand == orchestrator_scheduler .DiggerCommandLock {
756
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":white_check_mark: Command %v completed successfully" , * diggerCommand ))
774
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":white_check_mark: Command %v completed successfully" , * diggerCommand ))
757
775
return nil
758
776
}
759
777
760
778
jobs , _ , err := generic .ConvertIssueCommentEventToJobs (repoFullName , actor , issueNumber , commentBody , impactedProjects , requestedProject , config .Workflows , prBranchName , defaultBranch )
761
779
if err != nil {
762
780
log .Printf ("Error converting event to jobs: %v" , err )
763
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: Error converting event to jobs: %v" , err ))
781
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Error converting event to jobs: %v" , err ))
764
782
return fmt .Errorf ("error converting event to jobs" )
765
783
}
766
784
log .Printf ("GitHub IssueComment event converted to Jobs successfully\n " )
767
785
768
786
err = utils .ReportInitialJobsStatus (commentReporter , jobs )
769
787
if err != nil {
770
788
log .Printf ("Failed to comment initial status for jobs: %v" , err )
771
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: Failed to comment initial status for jobs: %v" , err ))
789
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: Failed to comment initial status for jobs: %v" , err ))
772
790
return fmt .Errorf ("failed to comment initial status for jobs" )
773
791
}
774
792
@@ -782,7 +800,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
782
800
err = utils .SetPRStatusForJobs (ghService , issueNumber , jobs )
783
801
if err != nil {
784
802
log .Printf ("error setting status for PR: %v" , err )
785
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: error setting status for PR: %v" , err ))
803
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: error setting status for PR: %v" , err ))
786
804
fmt .Errorf ("error setting status for PR: %v" , err )
787
805
}
788
806
@@ -799,13 +817,14 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
799
817
reporterCommentId , err := strconv .ParseInt (commentReporter .CommentId , 10 , 64 )
800
818
if err != nil {
801
819
log .Printf ("strconv.ParseInt error: %v" , err )
802
- utils .InitCommentReporter (ghService , issueNumber , fmt .Sprintf (":x: could not handle commentId: %v" , err ))
820
+ commentReporterManager .UpdateComment (fmt .Sprintf (":x: could not handle commentId: %v" , err ))
821
+ return fmt .Errorf ("comment reporter error: %v" , err )
803
822
}
804
823
805
824
batchId , _ , err := utils .ConvertJobsToDiggerJobs (* diggerCommand , "github" , orgId , impactedProjectsJobMap , impactedProjectsMap , projectsGraph , installationId , * branch , issueNumber , repoOwner , repoName , repoFullName , * commitSha , reporterCommentId , diggerYmlStr , 0 )
806
825
if err != nil {
807
826
log .Printf ("ConvertJobsToDiggerJobs error: %v" , err )
808
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: ConvertJobsToDiggerJobs error: %v" , err ))
827
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: ConvertJobsToDiggerJobs error: %v" , err ))
809
828
return fmt .Errorf ("error convertingjobs" )
810
829
}
811
830
@@ -815,26 +834,26 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
815
834
sourceDetails , err := comment_updater .PostInitialSourceComments (ghService , issueNumber , impactedProjectsSourceMapping )
816
835
if err != nil {
817
836
log .Printf ("PostInitialSourceComments error: %v" , err )
818
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
837
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
819
838
return fmt .Errorf ("error posting initial comments" )
820
839
}
821
840
batch , err := models .DB .GetDiggerBatch (batchId )
822
841
if err != nil {
823
842
log .Printf ("GetDiggerBatch error: %v" , err )
824
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
843
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: PostInitialSourceComments error: %v" , err ))
825
844
return fmt .Errorf ("error getting digger batch" )
826
845
}
827
846
828
847
batch .SourceDetails , err = json .Marshal (sourceDetails )
829
848
if err != nil {
830
849
log .Printf ("sourceDetails, json Marshal error: %v" , err )
831
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: json Marshal error: %v" , err ))
850
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: json Marshal error: %v" , err ))
832
851
return fmt .Errorf ("error marshalling sourceDetails" )
833
852
}
834
853
err = models .DB .UpdateDiggerBatch (batch )
835
854
if err != nil {
836
855
log .Printf ("UpdateDiggerBatch error: %v" , err )
837
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: UpdateDiggerBatch error: %v" , err ))
856
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: UpdateDiggerBatch error: %v" , err ))
838
857
return fmt .Errorf ("error updating digger batch" )
839
858
}
840
859
}
@@ -853,13 +872,13 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
853
872
)
854
873
if err != nil {
855
874
log .Printf ("GetCiBackend error: %v" , err )
856
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: GetCiBackend error: %v" , err ))
875
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: GetCiBackend error: %v" , err ))
857
876
return fmt .Errorf ("error fetching ci backed %v" , err )
858
877
}
859
878
err = TriggerDiggerJobs (ciBackend , repoFullName , repoOwner , repoName , batchId , issueNumber , ghService , gh )
860
879
if err != nil {
861
880
log .Printf ("TriggerDiggerJobs error: %v" , err )
862
- utils . InitCommentReporter ( ghService , issueNumber , fmt .Sprintf (":x: TriggerDiggerJobs error: %v" , err ))
881
+ commentReporterManager . UpdateComment ( fmt .Sprintf (":x: TriggerDiggerJobs error: %v" , err ))
863
882
return fmt .Errorf ("error triggering Digger Jobs" )
864
883
}
865
884
return nil
0 commit comments