Skip to content

Commit

Permalink
Use "concise" diff comment in cases "regular" diff comment is > 65536 (
Browse files Browse the repository at this point in the history
  • Loading branch information
Oded-B authored Aug 6, 2024
1 parent adbd913 commit 9ab1dd8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
14 changes: 12 additions & 2 deletions internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"golang.org/x/exp/maps"
)

const githubCommentMaxSize = 65536

type promotionInstanceMetaData struct {
SourcePath string `json:"sourcePath"`
TargetPaths []string `json:"targetPaths"`
Expand Down Expand Up @@ -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")
Expand Down
47 changes: 47 additions & 0 deletions templates/argoCD-diff-pr-comment-concise.gotmpl
Original file line number Diff line number Diff line change
@@ -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 }}
<img src="https://argo-cd.readthedocs.io/en/stable/assets/favicon.png" width="20"/> **[{{ $appDiffResult.ArgoCdAppName }}]({{ $appDiffResult.ArgoCdAppURL }})** @ `{{ $appDiffResult.ComponentPath }}`
{{if $appDiffResult.HasDiff }}

<details><summary>ArgoCD list of changed objects(Click to expand):</summary>

{{ range $objectDiff := $appDiffResult.DiffElements }}
{{- if $objectDiff.Diff}}
`{{ $objectDiff.ObjectNamespace }}/{{ $objectDiff.ObjectKind}}/{{ $objectDiff.ObjectName }}`
{{- end}}
{{- end }}

</details>
{{- 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 }}

- [ ] <!-- telefonistka-argocd-branch-sync --> Set ArgoCD apps Target Revision to `{{ .BranchName }}`

{{ end}}


{{- end }}

0 comments on commit 9ab1dd8

Please sign in to comment.