Skip to content

Commit

Permalink
Improve comment and deployment status description (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Feb 4, 2024
1 parent ee3f08b commit 2681c64
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
6 changes: 2 additions & 4 deletions internal/notification/healthcomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ func generateCommentBodyOnHealthChanged(app argocdv1alpha1.Application, argocdUR
argocdApplicationURL := fmt.Sprintf("%s/applications/%s", argocdURL, app.Name)
switch app.Status.Health.Status {
case health.HealthStatusHealthy:
return fmt.Sprintf("## %s %s: [%s](%s)\nDeployed %s",
":white_check_mark:",
return fmt.Sprintf(":white_check_mark: %s [%s](%s) at %s",
app.Status.Health.Status,
app.Name,
argocdApplicationURL,
sourceRevision.Revision,
)
case health.HealthStatusDegraded:
return fmt.Sprintf("## %s %s: [%s](%s)\nError while deploying %s:\n%s",
":x:",
return fmt.Sprintf("## :x: %s [%s](%s) at %s:\n%s",
app.Status.Health.Status,
app.Name,
argocdApplicationURL,
Expand Down
8 changes: 4 additions & 4 deletions internal/notification/healthdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ func generateDeploymentStatusOnHealthChanged(app argocdv1alpha1.Application, arg

func generateDeploymentStatusDescriptionOnHealthChanged(app argocdv1alpha1.Application) string {
var b strings.Builder
b.WriteString(fmt.Sprintf("%s:\n%s\n",
app.Status.Health.Status,
app.Status.Health.Message,
))
b.WriteString(fmt.Sprintf("%s:\n", app.Status.Health.Status))
if app.Status.Health.Message != "" {
b.WriteString(fmt.Sprintf("%s\n", app.Status.Health.Message))
}
for _, r := range app.Status.Resources {
if r.Health == nil {
continue
Expand Down
12 changes: 9 additions & 3 deletions internal/notification/phasecomment.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ func generateCommentBodyOnPhaseChanged(app argocdv1alpha1.Application, argocdURL
return fmt.Sprintf(":warning: Syncing [%s](%s) to %s", app.Name, argocdApplicationURL, sourceRevision.Revision)
case synccommon.OperationSucceeded:
return fmt.Sprintf(":white_check_mark: Synced [%s](%s) to %s", app.Name, argocdApplicationURL, sourceRevision.Revision)
case synccommon.OperationFailed, synccommon.OperationError:
return fmt.Sprintf("## :x: Sync %s: [%s](%s)\nError while syncing to %s:\n%s",
phase,
case synccommon.OperationFailed:
return fmt.Sprintf("## :x: Failed to sync [%s](%s) to %s\n%s",
app.Name,
argocdApplicationURL,
sourceRevision.Revision,
generateCommentResourcesOnPhaseChanged(app.Status.OperationState.SyncResult),
)
case synccommon.OperationError:
return fmt.Sprintf("## :x: Sync error [%s](%s) at %s\n%s",
app.Name,
argocdApplicationURL,
sourceRevision.Revision,
Expand Down
25 changes: 24 additions & 1 deletion internal/notification/phasedeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package notification
import (
"context"
"fmt"
"strings"

argocdv1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
Expand Down Expand Up @@ -44,7 +45,7 @@ func generateDeploymentStatusOnPhaseChanged(app argocdv1alpha1.Application, argo
GitHubDeployment: *deployment,
GitHubDeploymentStatus: github.DeploymentStatus{
LogURL: fmt.Sprintf("%s/applications/%s", argocdURL, app.Name),
Description: trimDescription(fmt.Sprintf("%s:\n%s", phase, app.Status.OperationState.Message)),
Description: trimDescription(generateDeploymentStatusDescriptionOnPhaseChanged(app)),
},
}
if len(app.Status.Summary.ExternalURLs) > 0 {
Expand All @@ -66,3 +67,25 @@ func generateDeploymentStatusOnPhaseChanged(app argocdv1alpha1.Application, argo
}
return nil
}

func generateDeploymentStatusDescriptionOnPhaseChanged(app argocdv1alpha1.Application) string {
phase := argocd.GetSyncOperationPhase(app)
if phase == "" {
return ""
}
syncResult := app.Status.OperationState.SyncResult
if syncResult == nil {
return ""
}

var b strings.Builder
b.WriteString(fmt.Sprintf("%s:\n", phase))
for _, r := range syncResult.Resources {
namespacedName := r.Namespace + "/" + r.Name
switch r.Status {
case synccommon.ResultCodeSyncFailed:
b.WriteString(fmt.Sprintf("%s: %s\n", namespacedName, r.Message))
}
}
return b.String()
}

0 comments on commit 2681c64

Please sign in to comment.