Skip to content

Commit

Permalink
add build count to box info
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Mar 20, 2024
1 parent 9da572d commit 5136709
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/service/box/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ func (s *srv) Info(ctx context.Context, namespace, name string) (*v1.Box, error)
if err := db.Where(info).First(info).Error; err != nil {
return nil, err
}
return info.ToAPI()
out, err := info.ToAPI()
if err != nil {
return nil, err
}

if err := db.Model(&storageV1.Build{}).Where(&storageV1.Build{BoxID: info.ID}).Count(&out.Status.Builds).Error; err != nil {
return nil, err
}
return out, nil
}

func (s *srv) Create(ctx context.Context, data *v1.Box) error {
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/core/v1/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ import (
"github.com/zc2638/ink/pkg/selector"
)

type BoxStatus struct {
Builds int64 `json:"builds"`
}

// Box defines a collection of stage executions.
type Box struct {
Metadata `yaml:",inline"`

Resources []BoxResource `json:"resources" yaml:"resources"`
Settings map[string]string `json:"settings,omitempty" yaml:"settings,omitempty"`
Status BoxStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

func (b *Box) GetSelectors(kind string, settings map[string]string) (names []string, selectors []*selector.Selector) {
Expand Down

0 comments on commit 5136709

Please sign in to comment.