@@ -376,6 +376,15 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
376376 }
377377 }
378378
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+
379388 diggerYmlStr , ghService , config , projectsGraph , _ , _ , err := getDiggerConfigForPR (gh , installationId , repoFullName , repoOwner , repoName , cloneURL , prNumber )
380389 if err != nil {
381390 log .Printf ("getDiggerConfigForPR error: %v" , err )
@@ -385,14 +394,14 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
385394 impactedProjects , impactedProjectsSourceMapping , _ , err := dg_github .ProcessGitHubPullRequestEvent (payload , config , projectsGraph , ghService )
386395 if err != nil {
387396 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 ))
389398 return fmt .Errorf ("error processing event" )
390399 }
391400
392401 jobsForImpactedProjects , _ , err := dg_github .ConvertGithubPullRequestEventToJobs (payload , impactedProjects , nil , * config , false )
393402 if err != nil {
394403 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 ))
396405 return fmt .Errorf ("error converting event to jobsForImpactedProjects" )
397406 }
398407
@@ -408,7 +417,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
408417 diggerCommand , err := orchestrator_scheduler .GetCommandFromJob (jobsForImpactedProjects [0 ])
409418 if err != nil {
410419 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 ))
412421 return fmt .Errorf ("unknown digger command in comment %v" , err )
413422 }
414423
@@ -432,7 +441,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
432441 }
433442 err = dg_locking .PerformLockingActionFromCommand (prLock , * diggerCommand )
434443 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 ))
436445 return fmt .Errorf ("failed to perform lock action on project: %v, %v" , project .Name , err )
437446 }
438447 }
@@ -441,7 +450,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
441450 // if commands are locking or unlocking we don't need to trigger any jobs
442451 if * diggerCommand == orchestrator_scheduler .DiggerCommandUnlock ||
443452 * 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 ))
445454 return nil
446455 }
447456
@@ -450,7 +459,7 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
450459 return nil
451460 }
452461
453- commentReporter , err := utils . InitCommentReporter ( ghService , prNumber , ":construction_worker: Digger starting..." )
462+ commentReporter , err := commentReporterManager . UpdateComment ( ":construction_worker: Digger starting... Config loaded successfully " )
454463 if err != nil {
455464 log .Printf ("Error initializing comment reporter: %v" , err )
456465 return fmt .Errorf ("error initializing comment reporter" )
@@ -459,14 +468,14 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
459468 err = utils .ReportInitialJobsStatus (commentReporter , jobsForImpactedProjects )
460469 if err != nil {
461470 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 ))
463472 return fmt .Errorf ("failed to comment initial status for jobs" )
464473 }
465474
466475 err = utils .SetPRStatusForJobs (ghService , prNumber , jobsForImpactedProjects )
467476 if err != nil {
468477 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 ))
470479 fmt .Errorf ("error setting status for PR: %v" , err )
471480 }
472481
@@ -483,38 +492,38 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
483492 commentId , err := strconv .ParseInt (commentReporter .CommentId , 10 , 64 )
484493 if err != nil {
485494 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 ))
487496 }
488497 batchId , _ , err := utils .ConvertJobsToDiggerJobs (* diggerCommand , models .DiggerVCSGithub , organisationId , impactedJobsMap , impactedProjectsMap , projectsGraph , installationId , branch , prNumber , repoOwner , repoName , repoFullName , commitSha , commentId , diggerYmlStr , 0 )
489498 if err != nil {
490499 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 ))
492501 return fmt .Errorf ("error converting jobs" )
493502 }
494503
495504 if config .CommentRenderMode == dg_configuration .CommentRenderModeGroupByModule {
496505 sourceDetails , err := comment_updater .PostInitialSourceComments (ghService , prNumber , impactedProjectsSourceMapping )
497506 if err != nil {
498507 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 ))
500509 return fmt .Errorf ("error posting initial comments" )
501510 }
502511 batch , err := models .DB .GetDiggerBatch (batchId )
503512 if err != nil {
504513 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 ))
506515 return fmt .Errorf ("error getting digger batch" )
507516 }
508517 batch .SourceDetails , err = json .Marshal (sourceDetails )
509518 if err != nil {
510519 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 ))
512521 return fmt .Errorf ("error marshalling sourceDetails" )
513522 }
514523 err = models .DB .UpdateDiggerBatch (batch )
515524 if err != nil {
516525 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 ))
518527 return fmt .Errorf ("error updating digger batch" )
519528 }
520529 }
@@ -533,14 +542,14 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
533542 )
534543 if err != nil {
535544 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 ))
537546 return fmt .Errorf ("error fetching ci backed %v" , err )
538547 }
539548
540549 err = TriggerDiggerJobs (ciBackend , repoFullName , repoOwner , repoName , batchId , prNumber , ghService , gh )
541550 if err != nil {
542551 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 ))
544553 return fmt .Errorf ("error triggering Digger Jobs" )
545554 }
546555
@@ -678,14 +687,23 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
678687 return nil
679688 }
680689
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+
681704 diggerYmlStr , ghService , config , projectsGraph , branch , commitSha , err := getDiggerConfigForPR (gh , installationId , repoFullName , repoOwner , repoName , cloneURL , issueNumber )
682705 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 ))
689707 log .Printf ("getDiggerConfigForPR error: %v" , err )
690708 return fmt .Errorf ("error getting digger config" )
691709 }
@@ -701,7 +719,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
701719 return nil
702720 }
703721
704- commentReporter , err := utils . InitCommentReporter ( ghService , issueNumber , ":construction_worker: Digger starting...." )
722+ commentReporter , err := commentReporterManager . UpdateComment ( ":construction_worker: Digger starting.... config loaded successfully " )
705723 if err != nil {
706724 log .Printf ("Error initializing comment reporter: %v" , err )
707725 return fmt .Errorf ("error initializing comment reporter" )
@@ -710,21 +728,21 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
710728 diggerCommand , err := orchestrator_scheduler .GetCommandFromComment (* payload .Comment .Body )
711729 if err != nil {
712730 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 ))
714732 return fmt .Errorf ("unknown digger command in comment %v" , err )
715733 }
716734
717735 prBranchName , _ , err := ghService .GetBranchName (issueNumber )
718736 if err != nil {
719737 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 ))
721739 return fmt .Errorf ("error while fetching branch name" )
722740 }
723741
724742 impactedProjects , impactedProjectsSourceMapping , requestedProject , _ , err := generic .ProcessIssueCommentEvent (issueNumber , * payload .Comment .Body , config , projectsGraph , ghService )
725743 if err != nil {
726744 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 ))
728746 return fmt .Errorf ("error processing event" )
729747 }
730748 log .Printf ("GitHub IssueComment event processed successfully\n " )
@@ -744,7 +762,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
744762 }
745763 err = dg_locking .PerformLockingActionFromCommand (prLock , * diggerCommand )
746764 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 ))
748766 return fmt .Errorf ("failed perform lock action on project: %v %v" , project .Name , err )
749767 }
750768 }
@@ -753,22 +771,22 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
753771 // if commands are locking or unlocking we don't need to trigger any jobs
754772 if * diggerCommand == orchestrator_scheduler .DiggerCommandUnlock ||
755773 * 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 ))
757775 return nil
758776 }
759777
760778 jobs , _ , err := generic .ConvertIssueCommentEventToJobs (repoFullName , actor , issueNumber , commentBody , impactedProjects , requestedProject , config .Workflows , prBranchName , defaultBranch )
761779 if err != nil {
762780 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 ))
764782 return fmt .Errorf ("error converting event to jobs" )
765783 }
766784 log .Printf ("GitHub IssueComment event converted to Jobs successfully\n " )
767785
768786 err = utils .ReportInitialJobsStatus (commentReporter , jobs )
769787 if err != nil {
770788 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 ))
772790 return fmt .Errorf ("failed to comment initial status for jobs" )
773791 }
774792
@@ -782,7 +800,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
782800 err = utils .SetPRStatusForJobs (ghService , issueNumber , jobs )
783801 if err != nil {
784802 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 ))
786804 fmt .Errorf ("error setting status for PR: %v" , err )
787805 }
788806
@@ -799,13 +817,14 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
799817 reporterCommentId , err := strconv .ParseInt (commentReporter .CommentId , 10 , 64 )
800818 if err != nil {
801819 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 )
803822 }
804823
805824 batchId , _ , err := utils .ConvertJobsToDiggerJobs (* diggerCommand , "github" , orgId , impactedProjectsJobMap , impactedProjectsMap , projectsGraph , installationId , * branch , issueNumber , repoOwner , repoName , repoFullName , * commitSha , reporterCommentId , diggerYmlStr , 0 )
806825 if err != nil {
807826 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 ))
809828 return fmt .Errorf ("error convertingjobs" )
810829 }
811830
@@ -815,26 +834,26 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
815834 sourceDetails , err := comment_updater .PostInitialSourceComments (ghService , issueNumber , impactedProjectsSourceMapping )
816835 if err != nil {
817836 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 ))
819838 return fmt .Errorf ("error posting initial comments" )
820839 }
821840 batch , err := models .DB .GetDiggerBatch (batchId )
822841 if err != nil {
823842 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 ))
825844 return fmt .Errorf ("error getting digger batch" )
826845 }
827846
828847 batch .SourceDetails , err = json .Marshal (sourceDetails )
829848 if err != nil {
830849 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 ))
832851 return fmt .Errorf ("error marshalling sourceDetails" )
833852 }
834853 err = models .DB .UpdateDiggerBatch (batch )
835854 if err != nil {
836855 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 ))
838857 return fmt .Errorf ("error updating digger batch" )
839858 }
840859 }
@@ -853,13 +872,13 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
853872 )
854873 if err != nil {
855874 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 ))
857876 return fmt .Errorf ("error fetching ci backed %v" , err )
858877 }
859878 err = TriggerDiggerJobs (ciBackend , repoFullName , repoOwner , repoName , batchId , issueNumber , ghService , gh )
860879 if err != nil {
861880 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 ))
863882 return fmt .Errorf ("error triggering Digger Jobs" )
864883 }
865884 return nil
0 commit comments