diff --git a/internal/pkg/githubapi/github.go b/internal/pkg/githubapi/github.go
index c83eb96..76832c5 100644
--- a/internal/pkg/githubapi/github.go
+++ b/internal/pkg/githubapi/github.go
@@ -28,6 +28,8 @@ import (
"golang.org/x/exp/maps"
)
+const githubCommentMaxSize = 65536
+
type promotionInstanceMetaData struct {
SourcePath string `json:"sourcePath"`
TargetPaths []string `json:"targetPaths"`
@@ -186,12 +188,20 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr
err, templateOutput := executeTemplate(ghPrClientDetails.PrLogger, "argoCdDiff", "argoCD-diff-pr-comment.gotmpl", diffCommentData)
if err != nil {
prHandleError = err
- log.Errorf("Failed to generate ArgoCD diff comment template: err=%s\n", err)
+ ghPrClientDetails.PrLogger.Errorf("Failed to generate ArgoCD diff comment template: err=%s\n", err)
+ } else if len(templateOutput) > githubCommentMaxSize {
+ ghPrClientDetails.PrLogger.Warnf("Diff comment is too large (%d bytes), using concise template", len(templateOutput))
+ err, templateOutput = executeTemplate(ghPrClientDetails.PrLogger, "argoCdDiffConcise", "argoCD-diff-pr-comment-concise.gotmpl", diffCommentData)
+ if err != nil {
+ prHandleError = err
+ ghPrClientDetails.PrLogger.Errorf("Failed to generate ArgoCD diff comment template: err=%s\n", err)
+ }
}
+
err = commentPR(ghPrClientDetails, templateOutput)
if err != nil {
prHandleError = err
- log.Errorf("Failed to comment ArgoCD diff: err=%s\n", err)
+ ghPrClientDetails.PrLogger.Errorf("Failed to comment ArgoCD diff: err=%s\n", err)
}
} else {
ghPrClientDetails.PrLogger.Debugf("Diff not find affected ArogCD apps")
diff --git a/templates/argoCD-diff-pr-comment-concise.gotmpl b/templates/argoCD-diff-pr-comment-concise.gotmpl
new file mode 100644
index 0000000..4a9fc14
--- /dev/null
+++ b/templates/argoCD-diff-pr-comment-concise.gotmpl
@@ -0,0 +1,47 @@
+{{define "argoCdDiffConcise"}}
+Diff of ArgoCD applications(⚠️ concise view, full diff didn't fit GH comment):
+{{ range $appDiffResult := .DiffOfChangedComponents }}
+
+
+{{if $appDiffResult.DiffError }}
+⚠️ ⚠️ **Error getting diff from ArgoCD** (`{{ $appDiffResult.ComponentPath }}`) ⚠️ ⚠️
+```
+{{ $appDiffResult.DiffError }}
+
+```
+
+{{- else }}
+ **[{{ $appDiffResult.ArgoCdAppName }}]({{ $appDiffResult.ArgoCdAppURL }})** @ `{{ $appDiffResult.ComponentPath }}`
+{{if $appDiffResult.HasDiff }}
+
+ArgoCD list of changed objects(Click to expand):
+
+{{ range $objectDiff := $appDiffResult.DiffElements }}
+{{- if $objectDiff.Diff}}
+`{{ $objectDiff.ObjectNamespace }}/{{ $objectDiff.ObjectKind}}/{{ $objectDiff.ObjectName }}`
+{{- end}}
+{{- end }}
+
+
+{{- else }}
+No diff 🤷
+{{- end}}
+{{if $appDiffResult.AppWasTemporarilyCreated }}
+⚠️ ⚠️ ⚠️
+This PR appears to create this new application, Telefonistka has **temporarly** created an ArgoCD app object for it just to render its manifests.
+It will not be present in ArgoCD UI for more than a few seconds and it can not be synced from the PR branch
+⚠️ ⚠️ ⚠️
+{{- end}}
+
+{{- end }}
+
+{{- end }}
+
+{{- if .HasSyncableComponens }}
+
+- [ ] Set ArgoCD apps Target Revision to `{{ .BranchName }}`
+
+{{ end}}
+
+
+{{- end }}