Skip to content

Commit 69b2db3

Browse files
committed
improve summary error reporting
1 parent af9d4eb commit 69b2db3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

backend/controllers/projects.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

libs/digger_config/digger_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func ReadDiggerYmlFileContents(dir string) (string, error) {
3636
if err != nil {
3737
// if file doesn't exist look for digger.yaml instead
3838
diggerYmlBytes, err = os.ReadFile(path.Join(dir, "digger.yaml"))
39+
if err != nil {
40+
return "", fmt.Errorf("could not read the file both digger.yml and digger.yaml are missing: %v", err)
41+
}
3942
}
4043
diggerYmlStr := string(diggerYmlBytes)
4144
return diggerYmlStr, nil

0 commit comments

Comments
 (0)