Skip to content

Commit 253ad21

Browse files
Doozersmoul
andauthored
feat: add tree command (build, artifacts) (#449)
Co-authored-by: Manfred Touron <[email protected]>
1 parent dd833d1 commit 253ad21

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

go/cmd/yolo/main.go

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import (
1515
"berty.tech/yolo/v2/go/pkg/bintray"
1616
"berty.tech/yolo/v2/go/pkg/yolopb"
1717
"berty.tech/yolo/v2/go/pkg/yolosvc"
18+
"go.uber.org/zap"
19+
"golang.org/x/oauth2"
20+
"moul.io/godev"
21+
"moul.io/hcfilters"
22+
"moul.io/zapconfig"
23+
1824
"github.com/buildkite/go-buildkite/buildkite"
1925
"github.com/google/go-github/v32/github"
2026
"github.com/gregjones/httpcache"
@@ -28,11 +34,6 @@ import (
2834
ff "github.com/peterbourgon/ff/v2"
2935
"github.com/peterbourgon/ff/v2/ffcli"
3036
"github.com/tevino/abool"
31-
"go.uber.org/zap"
32-
"golang.org/x/oauth2"
33-
"moul.io/godev"
34-
"moul.io/hcfilters"
35-
"moul.io/zapconfig"
3637
)
3738

3839
func main() {
@@ -264,7 +265,7 @@ func yolo(args []string) error {
264265

265266
ctx := context.Background()
266267
input := &yolopb.DevDumpObjects_Request{
267-
WithPreloading: withPreloading,
268+
WithPreloading: true,
268269
}
269270
ret, err := svc.DevDumpObjects(ctx, input)
270271
if err != nil {
@@ -276,6 +277,42 @@ func yolo(args []string) error {
276277
},
277278
}
278279

280+
tree := &ffcli.Command{
281+
Name: `tree`,
282+
FlagSet: storeFlagSet,
283+
Options: []ff.Option{ff.WithEnvVarNoPrefix()},
284+
Exec: func(ctx context.Context, _ []string) error {
285+
logger, err := loggerFromArgs(verbose, logFormat)
286+
if err != nil {
287+
return err
288+
}
289+
db, err := dbFromArgs(dbStorePath, logger)
290+
if err != nil {
291+
return err
292+
}
293+
defer db.Close()
294+
295+
svc, err := yolosvc.NewService(db, yolosvc.ServiceOpts{
296+
Logger: logger,
297+
DevMode: true,
298+
})
299+
if err != nil {
300+
return err
301+
}
302+
303+
input := &yolopb.DevDumpObjects_Request{
304+
WithPreloading: true,
305+
}
306+
ret, err := svc.DevDumpObjects(ctx, input)
307+
if err != nil {
308+
return err
309+
}
310+
fmt.Println(ret.Batch.DisplayTreeFormat())
311+
312+
return nil
313+
},
314+
}
315+
279316
info := &ffcli.Command{
280317
Name: `info`,
281318
FlagSet: storeFlagSet,
@@ -313,7 +350,7 @@ func yolo(args []string) error {
313350
root := &ffcli.Command{
314351
ShortUsage: `server [flags] <subcommand>`,
315352
FlagSet: rootFlagSet,
316-
Subcommands: []*ffcli.Command{server, dumpObjects, info},
353+
Subcommands: []*ffcli.Command{server, dumpObjects, info, tree},
317354
Options: []ff.Option{ff.WithEnvVarNoPrefix()},
318355
Exec: func(_ context.Context, _ []string) error {
319356
return flag.ErrHelp

go/pkg/yolopb/batch.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package yolopb
22

3+
import (
4+
"fmt"
5+
"sort"
6+
)
7+
38
func NewBatch() *Batch {
49
return &Batch{
510
Builds: []*Build{},
@@ -136,3 +141,19 @@ func (b *Batch) AllObjects() []interface{} {
136141
}
137142
return all
138143
}
144+
145+
func (b *Batch) DisplayTreeFormat() (res string) {
146+
sort.Slice(b.Builds, func(i, j int) bool {
147+
return b.Builds[i].FinishedAt.Before(*b.Builds[j].FinishedAt)
148+
})
149+
for _, build := range b.Builds {
150+
res += fmt.Sprintf(" - builds: %s from %s\n", build.ShortID, build.GetHasProjectID())
151+
for _, a := range b.Artifacts {
152+
if a.HasBuildID == build.ID {
153+
res += fmt.Sprintf(" - > artifacts: %s\n", a.LocalPath)
154+
}
155+
}
156+
res += "\n"
157+
}
158+
return
159+
}

0 commit comments

Comments
 (0)