Skip to content

Commit

Permalink
feat: add tree command (build, artifacts) (#449)
Browse files Browse the repository at this point in the history
Co-authored-by: Manfred Touron <[email protected]>
  • Loading branch information
Doozers and moul authored Sep 8, 2022
1 parent dd833d1 commit 253ad21
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
51 changes: 44 additions & 7 deletions go/cmd/yolo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
"berty.tech/yolo/v2/go/pkg/bintray"
"berty.tech/yolo/v2/go/pkg/yolopb"
"berty.tech/yolo/v2/go/pkg/yolosvc"
"go.uber.org/zap"
"golang.org/x/oauth2"
"moul.io/godev"
"moul.io/hcfilters"
"moul.io/zapconfig"

"github.com/buildkite/go-buildkite/buildkite"
"github.com/google/go-github/v32/github"
"github.com/gregjones/httpcache"
Expand All @@ -28,11 +34,6 @@ import (
ff "github.com/peterbourgon/ff/v2"
"github.com/peterbourgon/ff/v2/ffcli"
"github.com/tevino/abool"
"go.uber.org/zap"
"golang.org/x/oauth2"
"moul.io/godev"
"moul.io/hcfilters"
"moul.io/zapconfig"
)

func main() {
Expand Down Expand Up @@ -264,7 +265,7 @@ func yolo(args []string) error {

ctx := context.Background()
input := &yolopb.DevDumpObjects_Request{
WithPreloading: withPreloading,
WithPreloading: true,
}
ret, err := svc.DevDumpObjects(ctx, input)
if err != nil {
Expand All @@ -276,6 +277,42 @@ func yolo(args []string) error {
},
}

tree := &ffcli.Command{
Name: `tree`,
FlagSet: storeFlagSet,
Options: []ff.Option{ff.WithEnvVarNoPrefix()},
Exec: func(ctx context.Context, _ []string) error {
logger, err := loggerFromArgs(verbose, logFormat)
if err != nil {
return err
}
db, err := dbFromArgs(dbStorePath, logger)
if err != nil {
return err
}
defer db.Close()

svc, err := yolosvc.NewService(db, yolosvc.ServiceOpts{
Logger: logger,
DevMode: true,
})
if err != nil {
return err
}

input := &yolopb.DevDumpObjects_Request{
WithPreloading: true,
}
ret, err := svc.DevDumpObjects(ctx, input)
if err != nil {
return err
}
fmt.Println(ret.Batch.DisplayTreeFormat())

return nil
},
}

info := &ffcli.Command{
Name: `info`,
FlagSet: storeFlagSet,
Expand Down Expand Up @@ -313,7 +350,7 @@ func yolo(args []string) error {
root := &ffcli.Command{
ShortUsage: `server [flags] <subcommand>`,
FlagSet: rootFlagSet,
Subcommands: []*ffcli.Command{server, dumpObjects, info},
Subcommands: []*ffcli.Command{server, dumpObjects, info, tree},
Options: []ff.Option{ff.WithEnvVarNoPrefix()},
Exec: func(_ context.Context, _ []string) error {
return flag.ErrHelp
Expand Down
21 changes: 21 additions & 0 deletions go/pkg/yolopb/batch.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package yolopb

import (
"fmt"
"sort"
)

func NewBatch() *Batch {
return &Batch{
Builds: []*Build{},
Expand Down Expand Up @@ -136,3 +141,19 @@ func (b *Batch) AllObjects() []interface{} {
}
return all
}

func (b *Batch) DisplayTreeFormat() (res string) {
sort.Slice(b.Builds, func(i, j int) bool {
return b.Builds[i].FinishedAt.Before(*b.Builds[j].FinishedAt)
})
for _, build := range b.Builds {
res += fmt.Sprintf(" - builds: %s from %s\n", build.ShortID, build.GetHasProjectID())
for _, a := range b.Artifacts {
if a.HasBuildID == build.ID {
res += fmt.Sprintf(" - > artifacts: %s\n", a.LocalPath)
}
}
res += "\n"
}
return
}

0 comments on commit 253ad21

Please sign in to comment.