Skip to content

Commit

Permalink
feat: update style to match github
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Oct 29, 2024
1 parent 287bdab commit cdee2d4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 54 deletions.
10 changes: 5 additions & 5 deletions api/buildstatus/build_status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestGetBuildStatus(t *testing.T) {
expected := []byte("badge")

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
Return(expected, nil).
Times(1)

Expand All @@ -129,7 +129,7 @@ func TestGetBuildStatus(t *testing.T) {
var actualPipeline v1.RadixPipelineType

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) {
actualCondition = c
actualPipeline = p
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestGetBuildStatus(t *testing.T) {
var actualPipeline v1.RadixPipelineType

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) {
actualCondition = c
actualPipeline = p
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestGetBuildStatus(t *testing.T) {
var actualPipeline v1.RadixPipelineType

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(func(c v1.RadixJobCondition, p v1.RadixPipelineType) ([]byte, error) {
actualCondition = c
actualPipeline = p
Expand All @@ -216,7 +216,7 @@ func TestGetBuildStatus(t *testing.T) {
fakeBuildStatus := mock.NewMockPipelineBadge(ctrl)

fakeBuildStatus.EXPECT().
GetBadge(gomock.Any(), gomock.Any()).
GetBadge(gomock.Any(), gomock.Any(), gomock.Any()).
Return(nil, errors.New("error")).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion api/buildstatus/buildstatus_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (handler BuildStatusHandler) GetBuildStatusForApplication(ctx context.Conte
buildCondition = latestPipelineJob.Status.Condition
}

output, err = handler.pipelineBadge.GetBadge(buildCondition, v1.RadixPipelineType(pipeline))
output, err = handler.pipelineBadge.GetBadge(ctx, buildCondition, v1.RadixPipelineType(pipeline))
if err != nil {
return nil, err
}
Expand Down
86 changes: 48 additions & 38 deletions api/buildstatus/models/badges/build-status.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions api/buildstatus/models/buildstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package models

import (
"bytes"
"context"
_ "embed"
"errors"
"html/template"
"strings"

v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/rs/zerolog/log"
)

// embed https://golang.org/pkg/embed/ - For embedding a single file, a variable of type []byte or string is often best
Expand All @@ -33,7 +35,7 @@ const (
)

type PipelineBadge interface {
GetBadge(condition v1.RadixJobCondition, pipeline v1.RadixPipelineType) ([]byte, error)
GetBadge(ctx context.Context, condition v1.RadixJobCondition, pipeline v1.RadixPipelineType) ([]byte, error)
}

func NewPipelineBadge() PipelineBadge {
Expand All @@ -54,16 +56,16 @@ type pipelineBadge struct {
badgeTemplate string
}

func (rbs *pipelineBadge) GetBadge(condition v1.RadixJobCondition, pipeline v1.RadixPipelineType) ([]byte, error) {
return rbs.getBadge(condition, pipeline)
func (rbs *pipelineBadge) GetBadge(ctx context.Context, condition v1.RadixJobCondition, pipeline v1.RadixPipelineType) ([]byte, error) {
return rbs.getBadge(ctx, condition, pipeline)
}

func (rbs *pipelineBadge) getBadge(condition v1.RadixJobCondition, pipeline v1.RadixPipelineType) ([]byte, error) {
func (rbs *pipelineBadge) getBadge(ctx context.Context, condition v1.RadixJobCondition, pipeline v1.RadixPipelineType) ([]byte, error) {
operation := translatePipeline(pipeline)
status := translateCondition(condition)
color := getColor(condition)
operationWidth := calculateWidth(10, operation)
statusWidth := calculateWidth(10, status)
operationWidth := calculateWidth(6, operation)
statusWidth := calculateWidth(6, status)
badgeData := pipelineBadgeData{
Operation: operation,
OperationWidth: operationWidth,
Expand All @@ -72,6 +74,8 @@ func (rbs *pipelineBadge) getBadge(condition v1.RadixJobCondition, pipeline v1.R
StatusWidth: statusWidth,
}

log.Ctx(ctx).Trace().Interface("badge", badgeData).Msg("Rendering badge")

funcMap := template.FuncMap{"sum": TemplateSum}
svgTemplate := template.New("status-badge.svg").Funcs(funcMap)
_, err := svgTemplate.Parse(rbs.badgeTemplate)
Expand Down
9 changes: 5 additions & 4 deletions api/test/mock/buildstatus_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdee2d4

Please sign in to comment.