Skip to content

Commit

Permalink
Merge pull request #50 from vince-riv/fix/various
Browse files Browse the repository at this point in the history
chore: various fixes/tweaks
  • Loading branch information
vrivellino authored Jan 26, 2024
2 parents 6f49e41 + ba94f5f commit fe73988
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit fe73988

Please sign in to comment.