Skip to content

Commit 9ab1dd8

Browse files
authored
Use "concise" diff comment in cases "regular" diff comment is > 65536 (#20)
1 parent adbd913 commit 9ab1dd8

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

internal/pkg/githubapi/github.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"golang.org/x/exp/maps"
2929
)
3030

31+
const githubCommentMaxSize = 65536
32+
3133
type promotionInstanceMetaData struct {
3234
SourcePath string `json:"sourcePath"`
3335
TargetPaths []string `json:"targetPaths"`
@@ -186,12 +188,20 @@ func HandlePREvent(eventPayload *github.PullRequestEvent, ghPrClientDetails GhPr
186188
err, templateOutput := executeTemplate(ghPrClientDetails.PrLogger, "argoCdDiff", "argoCD-diff-pr-comment.gotmpl", diffCommentData)
187189
if err != nil {
188190
prHandleError = err
189-
log.Errorf("Failed to generate ArgoCD diff comment template: err=%s\n", err)
191+
ghPrClientDetails.PrLogger.Errorf("Failed to generate ArgoCD diff comment template: err=%s\n", err)
192+
} else if len(templateOutput) > githubCommentMaxSize {
193+
ghPrClientDetails.PrLogger.Warnf("Diff comment is too large (%d bytes), using concise template", len(templateOutput))
194+
err, templateOutput = executeTemplate(ghPrClientDetails.PrLogger, "argoCdDiffConcise", "argoCD-diff-pr-comment-concise.gotmpl", diffCommentData)
195+
if err != nil {
196+
prHandleError = err
197+
ghPrClientDetails.PrLogger.Errorf("Failed to generate ArgoCD diff comment template: err=%s\n", err)
198+
}
190199
}
200+
191201
err = commentPR(ghPrClientDetails, templateOutput)
192202
if err != nil {
193203
prHandleError = err
194-
log.Errorf("Failed to comment ArgoCD diff: err=%s\n", err)
204+
ghPrClientDetails.PrLogger.Errorf("Failed to comment ArgoCD diff: err=%s\n", err)
195205
}
196206
} else {
197207
ghPrClientDetails.PrLogger.Debugf("Diff not find affected ArogCD apps")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{define "argoCdDiffConcise"}}
2+
Diff of ArgoCD applications(⚠️ concise view, full diff didn't fit GH comment):
3+
{{ range $appDiffResult := .DiffOfChangedComponents }}
4+
5+
6+
{{if $appDiffResult.DiffError }}
7+
⚠️ ⚠️ **Error getting diff from ArgoCD** (`{{ $appDiffResult.ComponentPath }}`) ⚠️ ⚠️
8+
```
9+
{{ $appDiffResult.DiffError }}
10+
11+
```
12+
13+
{{- else }}
14+
<img src="https://argo-cd.readthedocs.io/en/stable/assets/favicon.png" width="20"/> **[{{ $appDiffResult.ArgoCdAppName }}]({{ $appDiffResult.ArgoCdAppURL }})** @ `{{ $appDiffResult.ComponentPath }}`
15+
{{if $appDiffResult.HasDiff }}
16+
17+
<details><summary>ArgoCD list of changed objects(Click to expand):</summary>
18+
19+
{{ range $objectDiff := $appDiffResult.DiffElements }}
20+
{{- if $objectDiff.Diff}}
21+
`{{ $objectDiff.ObjectNamespace }}/{{ $objectDiff.ObjectKind}}/{{ $objectDiff.ObjectName }}`
22+
{{- end}}
23+
{{- end }}
24+
25+
</details>
26+
{{- else }}
27+
No diff 🤷
28+
{{- end}}
29+
{{if $appDiffResult.AppWasTemporarilyCreated }}
30+
⚠️ ⚠️ ⚠️
31+
This PR appears to create this new application, Telefonistka has **temporarly** created an ArgoCD app object for it just to render its manifests.
32+
It will not be present in ArgoCD UI for more than a few seconds and it can not be synced from the PR branch
33+
⚠️ ⚠️ ⚠️
34+
{{- end}}
35+
36+
{{- end }}
37+
38+
{{- end }}
39+
40+
{{- if .HasSyncableComponens }}
41+
42+
- [ ] <!-- telefonistka-argocd-branch-sync --> Set ArgoCD apps Target Revision to `{{ .BranchName }}`
43+
44+
{{ end}}
45+
46+
47+
{{- end }}

0 commit comments

Comments
 (0)