From 4628239ec1868a41c609c5e910f1ad667d23c66a Mon Sep 17 00:00:00 2001 From: Vincent Rivellino Date: Fri, 26 Jan 2024 15:10:08 -0500 Subject: [PATCH 1/3] chore: logging improvements --- internal/argocd/helper.go | 12 +++++++++++- internal/process_event/code_change.go | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/argocd/helper.go b/internal/argocd/helper.go index 7f4f658..784a9c7 100644 --- a/internal/argocd/helper.go +++ b/internal/argocd/helper.go @@ -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) } diff --git a/internal/process_event/code_change.go b/internal/process_event/code_change.go index 3282b43..3615e6a 100644 --- a/internal/process_event/code_change.go +++ b/internal/process_event/code_change.go @@ -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 @@ -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() @@ -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) From d4466258cc1ced93f806c837162231b0b367d015 Mon Sep 17 00:00:00 2001 From: Vincent Rivellino Date: Fri, 26 Jan 2024 15:14:17 -0500 Subject: [PATCH 2/3] fix: truncate github status description to 140 chars Fixes #49 --- internal/github/status.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/github/status.go b/internal/github/status.go index fdf725e..b070b97 100644 --- a/internal/github/status.go +++ b/internal/github/status.go @@ -14,6 +14,8 @@ var ( statusContextStr = "argo-diff" ) +const statusDescriptionMaxLen = 140 + const StatusPending = "pending" const StatusSuccess = "success" const StatusFailure = "failure" @@ -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{ From ba94f5f76c3a7aa4220c48291e5fdd3d1aba398b Mon Sep 17 00:00:00 2001 From: Vincent Rivellino Date: Fri, 26 Jan 2024 15:15:06 -0500 Subject: [PATCH 3/3] chore: comment when there's an error --- internal/process_event/code_change.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/process_event/code_change.go b/internal/process_event/code_change.go index 3615e6a..a8e96f6 100644 --- a/internal/process_event/code_change.go +++ b/internal/process_event/code_change.go @@ -115,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())