Skip to content

Commit

Permalink
feat: add tree command (build, artifacts)
Browse files Browse the repository at this point in the history
Signed-off-by: ismael FALL <[email protected]>
  • Loading branch information
Doozers committed Sep 5, 2022
1 parent a0d21a1 commit 4f7cc55
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 19 deletions.
40 changes: 39 additions & 1 deletion go/cmd/yolo/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"berty.tech/yolo/v2/go/pkg/yolotree"
"context"
"flag"
"fmt"
Expand Down Expand Up @@ -276,6 +277,43 @@ func yolo(args []string) error {
},
}

tree := &ffcli.Command{
Name: `tree`,
FlagSet: storeFlagSet,
Options: []ff.Option{ff.WithEnvVarNoPrefix()},
Exec: func(_ 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
}

ctx := context.Background()
input := &yolopb.DevDumpObjects_Request{
WithPreloading: withPreloading,
}
ret, err := svc.DevDumpObjects(ctx, input)
if err != nil {
return err
}
yolotree.DisplayTreeFormat(ret.Batch)

return nil
},
}

info := &ffcli.Command{
Name: `info`,
FlagSet: storeFlagSet,
Expand Down Expand Up @@ -313,7 +351,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
18 changes: 0 additions & 18 deletions go/pkg/yolosvc/driver_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,6 @@ func (worker *githubWorker) fetchBaseObjects(ctx context.Context) (*yolopb.Batch
// FIXME: list last branches, commits etc for each repo
}

// configure repo configs
{
// FIXME: automatically configure repo configs based on .github/yolo.yml
/*
// fetch workflows
{
opts := &github.ListOptions{}
before := time.Now()
workflows, _, err := svc.ghc.Actions.ListWorkflows(ctx, repo.owner, repo.repo, opts)
if err != nil {
return nil, err
}
logger.Debug("github.Actions.ListWorkflows", zap.Int("total", len(workflows.Workflows)), zap.Duration("duration", time.Since(before)))
fmt.Println(u.PrettyJSON(workflows))
}
*/
}

return batch, nil
}

Expand Down
49 changes: 49 additions & 0 deletions go/pkg/yolotree/yolotree.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package yolotree

import (
"berty.tech/yolo/v2/go/pkg/yolopb"
"fmt"
"sort"
)

type artifact struct {
ID string
file string
entity string
project string
build string
date string
}

func DisplayTreeFormat(d *yolopb.Batch) {
/* for _, e := range d.Entities {
fmt.Printf(" - entities: %s\n", e.Name)
for _, p := range d.Projects {
if p.GetHasOwnerID() == e.ID {
fmt.Printf(" - > - projects: %s\n", p.Name)
for _, b := range d.Builds {
if b.GetHasProjectID() == p.ID {
fmt.Printf(" - > > - builds: %s\n", b.ShortID)
for _, a := range d.Artifacts {
if a.HasBuildID == b.ID {
fmt.Printf(" - > > > - artifacts: %s\n", a.LocalPath)
}
}
}
}
}
}
}*/
sort.Slice(d.Builds, func(i, j int) bool {
return d.Builds[i].FinishedAt.Before(*d.Builds[j].FinishedAt)
})
for _, b := range d.Builds {
fmt.Printf(" - builds: %s from %s\n", b.ShortID, b.GetHasProjectID())
for _, a := range d.Artifacts {
if a.HasBuildID == b.ID {
fmt.Printf(" - > artifacts: %s\n", a.LocalPath)
}
}
fmt.Println()
}
}

0 comments on commit 4f7cc55

Please sign in to comment.