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

chore: various fixes/tweaks #50

Merged
merged 3 commits into from
Jan 26, 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
12 changes: 11 additions & 1 deletion internal/argocd/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ func GetApplicationChanges(ctx context.Context, repoOwner, repoName, repoDefault
if err != nil {
return appResList, err
}
log.Debug().Msgf("Matching apps: %v", apps)
log.Debug().Msgf("Matching apps: %s", func() (s string) {
for _, app := range apps {
if s != "" {
s += ", " + app.ObjectMeta.Name
} else {
s += app.ObjectMeta.Name
}
}
return
}())

for _, app := range apps {
log.Info().Msgf("Generating application diff for ArgoCD App '%s' w/ revision %s", app.ObjectMeta.Name, revision)
applicationResourceChanges, _ := GetApplicationDiff(ctx, app.ObjectMeta.Name, app.ObjectMeta.Namespace, revision)
appResList = append(appResList, applicationResourceChanges)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/github/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var (
statusContextStr = "argo-diff"
)

const statusDescriptionMaxLen = 140

const StatusPending = "pending"
const StatusSuccess = "success"
const StatusFailure = "failure"
Expand Down Expand Up @@ -42,6 +44,9 @@ func Status(ctx context.Context, isPr bool, status, description, repoOwner, repo
if isPr {
contextStr = statusContextStr + " (pull_request)"
}
if len(description) > statusDescriptionMaxLen {
description = description[:137] + "..."
}
// TODO add support for AvatarURL ?
// TODO add support for TargetURL ?
repoStatus := &github.RepoStatus{
Expand Down
8 changes: 5 additions & 3 deletions internal/process_event/code_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func ProcessCodeChange(eventInfo webhook.EventInfo, devMode bool, wg *sync.WaitG
github.Status(ctx, isPr, github.StatusError, err.Error(), eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.Sha, devMode)
log.Error().Err(err).Msg("argocd.GetApplicationChanges() failed")
return // we're done due to a processing error

}
log.Trace().Msgf("argocd.GetApplicationChanges() returned %d results", len(appResList))

errorCount := 0 // keep track of the number of errors
changeCount := 0 // how many apps have changes
Expand All @@ -60,6 +60,7 @@ func ProcessCodeChange(eventInfo webhook.EventInfo, devMode bool, wg *sync.WaitG
appHealthMsg := a.ArgoApp.Status.Health.Message
// appNs := a.ArgoApp.ObjectMeta.Namespance
if a.WarnStr != "" {
log.Trace().Msgf("%s has WarnStr %s", appName, a.WarnStr)
errorCount++
markdown += github.AppMarkdownStart(appName, "Error: "+a.WarnStr, appSyncStatus, appHealthStatus, appHealthMsg)
markdown += github.AppMarkdownEnd()
Expand All @@ -68,6 +69,7 @@ func ProcessCodeChange(eventInfo webhook.EventInfo, devMode bool, wg *sync.WaitG
firstError = a.WarnStr
}
} else {
log.Trace().Msgf("%s has %d Changed Resources", appName, len(a.ChangedResources))
if len(a.ChangedResources) > 0 {
changeCount++
markdown += github.AppMarkdownStart(appName, "", appSyncStatus, appHealthStatus, appHealthMsg)
Expand Down Expand Up @@ -113,8 +115,8 @@ func ProcessCodeChange(eventInfo webhook.EventInfo, devMode bool, wg *sync.WaitG
markdownStart += " compared to live state\n"
markdownStart += "\n" + tStr + "\n"
cMarkdown.Preamble = markdownStart
if changeCount == 0 {
// if there are no change, don't comment (but clear out any existing comments)
if changeCount == 0 && firstError == "" {
// if there are no changes or warnings, don't comment (but clear out any existing comments)
_, _ = github.Comment(ctx, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.PrNum, eventInfo.Sha, []string{})
} else {
_, _ = github.Comment(ctx, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.PrNum, eventInfo.Sha, cMarkdown.String())
Expand Down
Loading