Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "concise" diff comment in cases "regular" diff comment is > 65536 #20

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
hnnsgstfssn marked this conversation as resolved.
Show resolved Hide resolved
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):
hnnsgstfssn marked this conversation as resolved.
Show resolved Hide resolved
{{ 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 }}
Loading