diff --git a/backend/controllers/projects_helpers.go b/backend/controllers/projects_helpers.go index 3870d3190..b743c69e7 100644 --- a/backend/controllers/projects_helpers.go +++ b/backend/controllers/projects_helpers.go @@ -52,7 +52,7 @@ func GenerateChecksSummaryForBatch( batch *models.DiggerBatch) (string, error) { "outputLength", len(job.TerraformOutput), ) - terraformOutputs += fmt.Sprintf("terraform output for %v: %v \n\n", projectName, job.TerraformOutput) + terraformOutputs += "terraform output for " + projectName + ": " + job.TerraformOutput + " \n\n" } aiSummary, err := utils.GetAiSummaryFromTerraformPlans(terraformOutputs, summaryEndpoint, apiToken) @@ -86,7 +86,7 @@ func GenerateChecksSummaryForJob( job *models.DiggerJob) (string, error) { slog.Warn("Terraform output not set yet, ignoring this call") return "", nil } - terraformOutput := fmt.Sprintf("Terraform output for: %v\n\n", job.TerraformOutput) + terraformOutput := "Terraform output for: " + job.TerraformOutput + "\n\n" aiSummary, err := utils.GetAiSummaryFromTerraformPlans(terraformOutput, summaryEndpoint, apiToken) if err != nil { slog.Error("Could not generate AI summary from Terraform outputs", diff --git a/backend/utils/comment_utils.go b/backend/utils/comment_utils.go index 8a793b52d..c0db1978f 100644 --- a/backend/utils/comment_utils.go +++ b/backend/utils/comment_utils.go @@ -6,6 +6,7 @@ import ( "log/slog" "runtime/debug" "strconv" + "strings" "github.com/diggerhq/digger/backend/models" "github.com/diggerhq/digger/libs/ci" @@ -183,11 +184,11 @@ func GenerateRealtimeCommentMessage(jobs []models.DiggerJob, batchType orchestra // Match exact CLI format: |emoji **project** |status | jobType | + | ~ | - | message += fmt.Sprintf("|%s **%s** |%s | %s | %d | %d | %d|\n", job.Status.ToEmoji(), - projectDisplayName, - workflowRunUrl, - job.Status.ToString(), - checkRunUrl, - jobTypeTitle, + strings.ReplaceAll(projectDisplayName, "%", "%%"), + strings.ReplaceAll(workflowRunUrl, "%", "%%"), + strings.ReplaceAll(job.Status.ToString(), "%", "%%"), + strings.ReplaceAll(checkRunUrl, "%", "%%"), + strings.ReplaceAll(jobTypeTitle, "%", "%%"), resourcesCreated, resourcesUpdated, resourcesDeleted) diff --git a/cli/pkg/drift/github_issue.go b/cli/pkg/drift/github_issue.go index d96b27201..72e213027 100644 --- a/cli/pkg/drift/github_issue.go +++ b/cli/pkg/drift/github_issue.go @@ -5,6 +5,7 @@ import ( orchestrator "github.com/diggerhq/digger/libs/ci" "github.com/samber/lo" "log" + "strings" ) type GithubIssueNotification struct { @@ -14,8 +15,8 @@ type GithubIssueNotification struct { func (ghi *GithubIssueNotification) SendNotificationForProject(projectName string, repoFullName string, plan string) error { log.Printf("Info: Sending drift notification regarding project: %v", projectName) - title := fmt.Sprintf("Drift detected in project: %v", projectName) - message := fmt.Sprintf(":bangbang: Drift detected in digger project %v details below: \n\n```\n%v\n```", projectName, plan) + title := fmt.Sprintf("Drift detected in project: %s", strings.ReplaceAll(projectName, "%", "%%")) + message := ":bangbang: Drift detected in digger project " + projectName + " details below: \n\n```\n" + plan + "\n```" existingIssues, err := (*ghi.GithubService).ListIssues() if err != nil { log.Printf("failed to retrieve issues: %v", err) diff --git a/ee/cli/pkg/comment_updater/updater.go b/ee/cli/pkg/comment_updater/updater.go index 98d955863..197edb3ae 100644 --- a/ee/cli/pkg/comment_updater/updater.go +++ b/ee/cli/pkg/comment_updater/updater.go @@ -44,9 +44,15 @@ func (a AdvancedCommentUpdater) UpdateComment(jobs []scheduler.SerializedJob, pr workflowUrl = *job.WorkflowRunUrl } - message = message + fmt.Sprintf("\n", job.ProjectName) - message = message + fmt.Sprintf("%v **%v** %v%v %v\n", job.Status.ToEmoji(), jobSpec.ProjectName, workflowUrl, job.Status.ToString(), job.ResourcesSummaryString(isPlan), DriftSummaryString(job.ProjectName, issuesMap)) - message = message + fmt.Sprintf("\n", job.ProjectName) + message = message + fmt.Sprintf("\n", strings.ReplaceAll(job.ProjectName, "%", "%%")) + message = message + fmt.Sprintf("%s **%s** %s%s %s\n", + job.Status.ToEmoji(), + strings.ReplaceAll(jobSpec.ProjectName, "%", "%%"), + strings.ReplaceAll(workflowUrl, "%", "%%"), + strings.ReplaceAll(job.Status.ToString(), "%", "%%"), + strings.ReplaceAll(job.ResourcesSummaryString(isPlan), "%", "%%"), + strings.ReplaceAll(DriftSummaryString(job.ProjectName, issuesMap), "%", "%%")) + message = message + fmt.Sprintf("\n", strings.ReplaceAll(job.ProjectName, "%", "%%")) } prService.EditComment(prNumber, prCommentId, message) diff --git a/libs/comment_utils/reporting/source_grouping.go b/libs/comment_utils/reporting/source_grouping.go index d161413d0..a812e9750 100644 --- a/libs/comment_utils/reporting/source_grouping.go +++ b/libs/comment_utils/reporting/source_grouping.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log/slog" + "strings" "github.com/diggerhq/digger/libs/ci" "github.com/diggerhq/digger/libs/digger_config" @@ -77,7 +78,7 @@ func (r SourceGroupingReporter) UpdateComment(sourceDetails []SourceDetails, loc } message := "" - message = message + fmt.Sprintf("# Group: %v (similar: %v)\n", location, allSimilarInGroup) + message = message + fmt.Sprintf("# Group: %s (similar: %v)\n", strings.ReplaceAll(location, "%", "%%"), allSimilarInGroup) slog.Info("generating comment for source location", "location", location, @@ -95,7 +96,7 @@ func (r SourceGroupingReporter) UpdateComment(sourceDetails []SourceDetails, loc expanded := i == 0 || !allSimilarInGroup // Use alias for display with fallback to project name displayName := scheduler.GetProjectAlias(job) - commenter := GetTerraformOutputAsCollapsibleComment(fmt.Sprintf("Plan for %v", displayName), expanded) + commenter := GetTerraformOutputAsCollapsibleComment("Plan for "+displayName, expanded) message = message + commenter(terraformOutputs[project]) + "\n" } diff --git a/libs/comment_utils/summary/updater.go b/libs/comment_utils/summary/updater.go index f5fa8913d..bcd4b0c77 100644 --- a/libs/comment_utils/summary/updater.go +++ b/libs/comment_utils/summary/updater.go @@ -3,6 +3,7 @@ package comment_updater import ( "fmt" "log/slog" + "strings" "github.com/diggerhq/digger/libs/ci" "github.com/diggerhq/digger/libs/scheduler" @@ -52,13 +53,13 @@ func (b BasicCommentUpdater) UpdateComment(jobs []scheduler.SerializedJob, prNum workflowUrl = *job.WorkflowRunUrl } - message = message + fmt.Sprintf("|%v **%v** |%v | %v | %v | %v | %v|\n", + message = message + fmt.Sprintf("|%s **%s** |%s | %s | %d | %d | %d|\n", job.Status.ToEmoji(), - scheduler.GetProjectAlias(job), - workflowUrl, - job.Status.ToString(), - prCommentUrl, - jobTypeTitle, + strings.ReplaceAll(scheduler.GetProjectAlias(job), "%", "%%"), + strings.ReplaceAll(workflowUrl, "%", "%%"), + strings.ReplaceAll(job.Status.ToString(), "%", "%%"), + strings.ReplaceAll(prCommentUrl, "%", "%%"), + strings.ReplaceAll(jobTypeTitle, "%", "%%"), job.ResourcesCreated, job.ResourcesUpdated, job.ResourcesDeleted)