diff --git a/core/service/box/box.go b/core/service/box/box.go index 2735bd0..155b58c 100644 --- a/core/service/box/box.go +++ b/core/service/box/box.go @@ -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 { diff --git a/pkg/api/core/v1/box.go b/pkg/api/core/v1/box.go index 6fa4c2f..cebdca0 100644 --- a/pkg/api/core/v1/box.go +++ b/pkg/api/core/v1/box.go @@ -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) {