Skip to content

Commit

Permalink
Merge pull request #158 from berty/dev/moul/fix-cli-dump-objects
Browse files Browse the repository at this point in the history
feat: 'yolo dump-objects' cli
  • Loading branch information
moul authored Apr 30, 2020
2 parents a0e7e12 + 45c5871 commit ce2c3bc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 30 deletions.
12 changes: 9 additions & 3 deletions go/cmd/yolo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"berty.tech/yolo/v2/go/pkg/bintray"
"berty.tech/yolo/v2/go/pkg/yolopb"
"berty.tech/yolo/v2/go/pkg/yolosvc"
bearer "github.com/Bearer/bearer-go"
"github.com/buildkite/go-buildkite/buildkite"
Expand Down Expand Up @@ -52,6 +53,7 @@ func yolo(args []string) error {
bintrayToken string
circleciToken string
dbStorePath string
withPreloading bool
grpcBind string
httpBind string
corsAllowedOrigins string
Expand All @@ -77,8 +79,9 @@ func yolo(args []string) error {
serverFlagSet.StringVar(&bintrayToken, "bintray-token", "", "Bintray API Token")
serverFlagSet.StringVar(&circleciToken, "circleci-token", "", "CircleCI API Token")
serverFlagSet.StringVar(&githubToken, "github-token", "", "GitHub API Token")
serverFlagSet.StringVar(&dbStorePath, "db-path", ":temp:", "DB Store path")
storeFlagSet.StringVar(&dbStorePath, "db-path", ":temp:", "DB Store path")
serverFlagSet.StringVar(&dbStorePath, "db-path", ":memory:", "DB Store path")
storeFlagSet.StringVar(&dbStorePath, "db-path", ":memory:", "DB Store path")
storeFlagSet.BoolVar(&withPreloading, "with-preloading", false, "with auto DB preloading")
serverFlagSet.IntVar(&maxBuilds, "max-builds", 100, "maximum builds to fetch from external services (pagination)")
serverFlagSet.StringVar(&httpBind, "http-bind", ":8000", "HTTP bind address")
serverFlagSet.StringVar(&grpcBind, "grpc-bind", ":9000", "gRPC bind address")
Expand Down Expand Up @@ -227,7 +230,10 @@ func yolo(args []string) error {
}

ctx := context.Background()
ret, err := svc.DevDumpObjects(ctx, nil)
input := &yolopb.DevDumpObjects_Request{
WithPreloading: withPreloading,
}
ret, err := svc.DevDumpObjects(ctx, input)
if err != nil {
return err
}
Expand Down
100 changes: 73 additions & 27 deletions go/pkg/yolosvc/api_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,94 @@ package yolosvc

import (
"context"
"fmt"

"berty.tech/yolo/v2/go/pkg/yolopb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (svc service) DevDumpObjects(ctx context.Context, req *yolopb.DevDumpObjects_Request) (*yolopb.DevDumpObjects_Response, error) {
if req == nil {
req = &yolopb.DevDumpObjects_Request{}
}
if !svc.devMode {
return nil, status.Error(codes.PermissionDenied, "Permission Denied")
}

batch := yolopb.NewBatch()

db := svc.db
if req.WithPreloading {
fmt.Println("####################", true)
db = db.Set("gorm:auto_preload", true)
if err := svc.db.
Preload("HasOwner").
Find(&batch.Projects).Error; err != nil {
return nil, err
}
if err := svc.db.
// FIXME: TODO
Find(&batch.Entities).Error; err != nil {
return nil, err
}
if err := svc.db.
Preload("HasCommit").
Preload("HasProject").
Preload("HasMergerequest").
Preload("HasMergerequest.HasProject").
Preload("HasMergerequest.HasProject.HasOwner").
Preload("HasMergerequest.HasAuthor").
Preload("HasMergerequest.HasCommit").
Find(&batch.Builds).Error; err != nil {
return nil, err
}
if err := svc.db.
Preload("HasBuild").
Preload("HasBuild.HasProject").
Preload("HasBuild.HasMergerequest").
Preload("HasBuild.HasMergerequest.HasProject").
Preload("HasBuild.HasMergerequest.HasAuthor").
Preload("HasBuild.HasMergerequest.HasCommit").
Preload("HasBuild.HasCommit").
Find(&batch.Artifacts).Error; err != nil {
return nil, err
}
if err := svc.db.
Preload("HasCommit").
Preload("HasProject").
Preload("HasAuthor").
Find(&batch.MergeRequests).Error; err != nil {
return nil, err
}
if err := svc.db.
// FIXME: TODO
Find(&batch.Releases).Error; err != nil {
return nil, err
}
if err := svc.db.
// FIXME: TODO
Find(&batch.Commits).Error; err != nil {
return nil, err
}
} else {
fmt.Println("####################", false)
}

if err := db.Find(&batch.Projects).Error; err != nil {
return nil, err
}
if err := db.Find(&batch.Entities).Error; err != nil {
return nil, err
}
if err := db.Find(&batch.Builds).Error; err != nil {
return nil, err
}
if err := db.Find(&batch.Artifacts).Error; err != nil {
return nil, err
}
if err := db.Find(&batch.MergeRequests).Error; err != nil {
return nil, err
}
if err := db.Find(&batch.Releases).Error; err != nil {
return nil, err
}
if err := db.Find(&batch.Commits).Error; err != nil {
return nil, err
if err := svc.db.Find(&batch.Projects).Error; err != nil {
return nil, err
}
if err := svc.db.Find(&batch.Entities).Error; err != nil {
return nil, err
}
if err := svc.db.Find(&batch.Builds).Error; err != nil {
return nil, err
}
if err := svc.db.Find(&batch.Artifacts).Error; err != nil {
return nil, err
}
if err := svc.db.Find(&batch.MergeRequests).Error; err != nil {
return nil, err
}
if err := svc.db.Find(&batch.Releases).Error; err != nil {
return nil, err
}
if err := svc.db.Find(&batch.Commits).Error; err != nil {
return nil, err
}
}

resp := yolopb.DevDumpObjects_Response{
Expand Down

0 comments on commit ce2c3bc

Please sign in to comment.