@@ -666,19 +666,28 @@ func CreateTerraformOutputsSummary(gh utils.GithubClientProvider, batch *models.
666666 prService , err := GetPrServiceFromBatch (batch , gh )
667667 if err != nil {
668668 log .Printf ("Error getting github service: %v" , err )
669+ prService .EditComment (batch .PrNumber , batch .AiSummaryCommentId , ":x: could not generate AI summary \n \n could not communicate with github" )
669670 return fmt .Errorf ("error getting github service: %v" , err )
670671 }
671672
673+ if batch .AiSummaryCommentId == "" {
674+ log .Printf ("could not post summary comment, initial comment not found" )
675+ prService .PublishComment (batch .PrNumber , ":x: could not generate AI summary \n \n could not communicate with github" )
676+ return fmt .Errorf ("could not post summary comment, initial comment not found" )
677+ }
678+
672679 summaryEndpoint := os .Getenv ("DIGGER_AI_SUMMARY_ENDPOINT" )
673680 if summaryEndpoint == "" {
674681 log .Printf ("could not generate AI summary, ai summary endpoint missing" )
682+ prService .EditComment (batch .PrNumber , batch .AiSummaryCommentId , ":x: could not generate AI summary \n \n comment ID is missing " )
675683 return fmt .Errorf ("could not generate AI summary, ai summary endpoint missing" )
676684 }
677685 apiToken := os .Getenv ("DIGGER_AI_SUMMARY_API_TOKEN" )
678686
679687 jobs , err := models .DB .GetDiggerJobsForBatch (batch .ID )
680688 if err != nil {
681689 log .Printf ("could not get jobs for batch: %v" , err )
690+ prService .EditComment (batch .PrNumber , batch .AiSummaryCommentId , ":x: could not generate AI summary \n \n error fetching jobs " )
682691 return fmt .Errorf ("could not get jobs for batch: %v" , err )
683692 }
684693
@@ -688,6 +697,7 @@ func CreateTerraformOutputsSummary(gh utils.GithubClientProvider, batch *models.
688697 err := json .Unmarshal (job .SerializedJobSpec , & jobSpec )
689698 if err != nil {
690699 log .Printf ("could not summarise plans due to unmarshalling error: %v" , err )
700+ prService .EditComment (batch .PrNumber , batch .AiSummaryCommentId , ":x: could not generate AI summary \n \n error fetching job spec" )
691701 return fmt .Errorf ("could not summarise plans due to unmarshalling error: %v" , err )
692702 }
693703 projectName := jobSpec .ProjectName
@@ -696,14 +706,10 @@ func CreateTerraformOutputsSummary(gh utils.GithubClientProvider, batch *models.
696706 summary , err := utils .GetAiSummaryFromTerraformPlans (terraformOutputs , summaryEndpoint , apiToken )
697707 if err != nil {
698708 log .Printf ("could not summarise terraform outputs: %v" , err )
709+ prService .EditComment (batch .PrNumber , batch .AiSummaryCommentId , ":x: could not generate AI summary \n \n error generating summary from plans" )
699710 return fmt .Errorf ("could not summarise terraform outputs: %v" , err )
700711 }
701712
702- if batch .AiSummaryCommentId == "" {
703- log .Printf ("could not post summary comment, initial comment not found" )
704- return fmt .Errorf ("could not post summary comment, initial comment not found" )
705- }
706-
707713 prService .EditComment (batch .PrNumber , batch .AiSummaryCommentId , summary )
708714 }
709715 return nil
0 commit comments