diff --git a/api/buildstatus/buildstatus_controller.go b/api/buildstatus/buildstatus_controller.go index 31136fc1..9be76a7e 100644 --- a/api/buildstatus/buildstatus_controller.go +++ b/api/buildstatus/buildstatus_controller.go @@ -9,6 +9,7 @@ import ( "github.com/equinor/radix-api/models" radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1" "github.com/gorilla/mux" + "github.com/rs/zerolog/log" ) const rootPath = "/applications/{appName}/environments/{envName}" @@ -77,6 +78,7 @@ func (bsc *buildStatusController) GetBuildStatus(accounts models.Accounts, w htt buildStatus, err := buildStatusHandler.GetBuildStatusForApplication(r.Context(), appName, env, pipeline) if err != nil { + log.Error().Err(err).Msg("Error getting build status") w.WriteHeader(http.StatusInternalServerError) return } diff --git a/api/buildstatus/models/badges/build-status.svg b/api/buildstatus/models/badges/build-status.svg index f4d1d69f..f848aa43 100644 --- a/api/buildstatus/models/badges/build-status.svg +++ b/api/buildstatus/models/badges/build-status.svg @@ -1,19 +1,16 @@ - - - - - - - - - - - {{.Operation}} - - - {{.Status}} - - + + {{.Operation}} + + + + + + + + + + + @@ -29,17 +26,21 @@ - - - - - - - - - - - - + + + + + + + {{.Operation}} + + + + {{.Status}} + + + - \ No newline at end of file + diff --git a/api/buildstatus/models/buildstatus.go b/api/buildstatus/models/buildstatus.go index 36ed3a43..4d480571 100644 --- a/api/buildstatus/models/buildstatus.go +++ b/api/buildstatus/models/buildstatus.go @@ -8,7 +8,6 @@ import ( "strings" v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1" - "github.com/marstr/guid" ) // embed https://golang.org/pkg/embed/ - For embedding a single file, a variable of type []byte or string is often best @@ -17,16 +16,16 @@ import ( var defaultBadgeTemplate string const ( - buildStatusFailing = "failing" - buildStatusSuccess = "success" - buildStatusStopped = "stopped" - buildStatusPending = "pending" - buildStatusRunning = "running" - buildStatusUnknown = "unknown" + buildStatusFailing = "Failing" + buildStatusSuccess = "Succeeded" + buildStatusStopped = "Stopped" + buildStatusPending = "Pending" + buildStatusRunning = "Running" + buildStatusUnknown = "Unknown" ) const ( - pipelineStatusSuccessColor = "#4c1" + pipelineStatusSuccessColor = "#34d058" pipelineStatusFailedColor = "#e05d44" pipelineStatusStoppedColor = "#e05d44" pipelineStatusRunningColor = "#33cccc" @@ -44,17 +43,11 @@ func NewPipelineBadge() PipelineBadge { } type pipelineBadgeData struct { - Operation string - Status string - ColorLeft string - ColorRight string - ColorShadow string - ColorFont string - Width int - Height int - StatusOffset int - OperationTextId string - StatusTextId string + Operation string + OperationWidth int + Status string + StatusColor string + StatusWidth int } type pipelineBadge struct { @@ -70,23 +63,17 @@ func (rbs *pipelineBadge) getBadge(condition v1.RadixJobCondition, pipeline v1.R status := translateCondition(condition) color := getColor(condition) operationWidth := calculateWidth(10, operation) - statusWidth := calculateWidth(10, status) + 24 - + statusWidth := calculateWidth(10, status) badgeData := pipelineBadgeData{ - Operation: operation, - Status: status, - ColorRight: color, - ColorLeft: "#aaa", - ColorShadow: "#010101", - ColorFont: "#fff", - Width: statusWidth + operationWidth, - Height: 30, - StatusOffset: operationWidth, - OperationTextId: guid.NewGUID().String(), - StatusTextId: guid.NewGUID().String(), + Operation: operation, + OperationWidth: operationWidth, + Status: status, + StatusColor: color, + StatusWidth: statusWidth, } - svgTemplate := template.New("status-badge.svg") + funcMap := template.FuncMap{"sum": TemplateSum} + svgTemplate := template.New("status-badge.svg").Funcs(funcMap) _, err := svgTemplate.Parse(rbs.badgeTemplate) if err != nil { return nil, err @@ -113,6 +100,15 @@ func calculateWidth(charWidth float32, value string) int { return int(width + 5) } +func TemplateSum(arg0 int, args ...int) int { + x := arg0 + for _, arg := range args { + x += arg + } + + return x +} + func translateCondition(condition v1.RadixJobCondition) string { switch condition { case v1.JobSucceeded: diff --git a/api/buildstatus/models/buildstatus_test.go b/api/buildstatus/models/buildstatus_test.go index 1c942775..fc913d1f 100644 --- a/api/buildstatus/models/buildstatus_test.go +++ b/api/buildstatus/models/buildstatus_test.go @@ -13,42 +13,42 @@ func Test_PipelineBadgeBuilder(t *testing.T) { t.Run("failed condition", func(t *testing.T) { t.Parallel() - expected := "-failing" + expected := "-Failing" actual, err := badgeBuilder.GetBadge(v1.JobFailed, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("queued condition", func(t *testing.T) { t.Parallel() - expected := "-pending" + expected := "-Pending" actual, err := badgeBuilder.GetBadge(v1.JobQueued, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("running condition", func(t *testing.T) { t.Parallel() - expected := "-running" + expected := "-Running" actual, err := badgeBuilder.GetBadge(v1.JobRunning, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("stopped condition", func(t *testing.T) { t.Parallel() - expected := "-stopped" + expected := "-Stopped" actual, err := badgeBuilder.GetBadge(v1.JobStopped, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("succeeded condition", func(t *testing.T) { t.Parallel() - expected := "-success" + expected := "-Succeeded" actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("waiting condition", func(t *testing.T) { t.Parallel() - expected := "-pending" + expected := "-Pending" actual, err := badgeBuilder.GetBadge(v1.JobWaiting, v1.RadixPipelineType("")) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) @@ -56,28 +56,28 @@ func Test_PipelineBadgeBuilder(t *testing.T) { t.Run("build-deploy type", func(t *testing.T) { t.Parallel() - expected := "build-deploy-success" + expected := "build-deploy-Succeeded" actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.BuildDeploy) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("promote type", func(t *testing.T) { t.Parallel() - expected := "promote-success" + expected := "promote-Succeeded" actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.Promote) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("deploy type", func(t *testing.T) { t.Parallel() - expected := "deploy-success" + expected := "deploy-Succeeded" actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.Deploy) assert.Nil(t, err) assert.Equal(t, expected, string(actual)) }) t.Run("unhandled type", func(t *testing.T) { t.Parallel() - expected := "-success" + expected := "-Succeeded" actual, err := badgeBuilder.GetBadge(v1.JobSucceeded, v1.RadixPipelineType("unhandled")) assert.Nil(t, err) assert.Equal(t, expected, string(actual))