Skip to content

Commit

Permalink
feat: 'the world' target
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Nov 26, 2019
1 parent 76204aa commit 7f7e1b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
2 changes: 2 additions & 0 deletions internal/dvcore/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func Run(h *cayley.Handle, args []string, opts RunOpts) error {
}
opts.Logger.Debug("Run called", zap.Strings("args", args), zap.Any("opts", opts))

// FIXME: support the world

targets, err := dvparser.ParseTargets(args)
if err != nil {
return fmt.Errorf("parse targets: %w", err)
Expand Down
14 changes: 9 additions & 5 deletions internal/dvserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ func (s *service) Graph(ctx context.Context, in *Graph_Input) (*Graph_Output, er
return nil, fmt.Errorf("targets is required")
}

targets, err := dvparser.ParseTargets(in.Targets)
if err != nil {
return nil, fmt.Errorf("parse targets: %w", err)
}
filters := dvstore.LoadTasksFilters{
WithClosed: in.WithClosed,
WithoutIsolated: in.WithoutIsolated,
WithoutPRs: in.WithoutPRs,
WithoutExternalDeps: in.WithoutExternalDeps,
Targets: targets,
}
if len(in.Targets) == 1 && in.Targets[0] == "world" {
filters.TheWorld = true
} else {
targets, err := dvparser.ParseTargets(in.Targets)
if err != nil {
return nil, fmt.Errorf("parse targets: %w", err)
}
filters.Targets = targets
}

// load tasks
Expand Down
55 changes: 30 additions & 25 deletions internal/dvstore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,56 @@ func LastUpdatedIssueInRepo(ctx context.Context, h *cayley.Handle, entity multip

type LoadTasksFilters struct {
Targets []multipmuri.Entity
TheWorld bool
WithClosed bool
WithoutIsolated bool
WithoutPRs bool
WithoutExternalDeps bool
}

func LoadTasks(h *cayley.Handle, schema *schema.Config, filters LoadTasksFilters, logger *zap.Logger) (dvmodel.Tasks, error) {
if filters.Targets == nil || len(filters.Targets) == 0 {
if (filters.Targets == nil || len(filters.Targets) == 0) && !filters.TheWorld {
return nil, fmt.Errorf("missing filter.targets")
}

ctx := context.TODO()

// fetch and filter
// fetch targets
paths := []*path.Path{}
for _, target := range filters.Targets {
// FIXME: handle different target types (for now only repo)
p := path.StartPath(h, quad.IRI(target.String())).
In().
Has(quad.IRI("rdf:type"), quad.IRI("dv:Task"))
kinds := []quad.Value{
quad.Int(dvmodel.Task_Issue),
quad.Int(dvmodel.Task_Milestone),
quad.Int(dvmodel.Task_Epic),
quad.Int(dvmodel.Task_Story),
quad.Int(dvmodel.Task_Card),
if filters.TheWorld {
paths = append(paths, path.StartPath(h))
} else {
for _, target := range filters.Targets {
// FIXME: handle different target types (for now only repo)
p := path.StartPath(h, quad.IRI(target.String())).
Both().
Has(quad.IRI("rdf:type"), quad.IRI("dv:Task"))

// FIXME: reverse depends/blocks
paths = append(paths, p)
}
// FIXME: one option per type
if !filters.WithoutPRs {
kinds = append(kinds, quad.Int(dvmodel.Task_MergeRequest))
}
p = p.Has(quad.IRI("schema:kind"), kinds...)
if !filters.WithClosed {
p = p.Has(quad.IRI("schema:state"), quad.Int(dvmodel.Task_Open))
}
// FIXME: reverse depends/blocks

paths = append(paths, p)
}

p := paths[0]
for _, path := range paths[1:] {
p = p.Or(path)
}

// filters
kinds := []quad.Value{
quad.Int(dvmodel.Task_Issue),
quad.Int(dvmodel.Task_Milestone),
quad.Int(dvmodel.Task_Epic),
quad.Int(dvmodel.Task_Story),
quad.Int(dvmodel.Task_Card),
}
if !filters.WithoutPRs {
kinds = append(kinds, quad.Int(dvmodel.Task_MergeRequest))
}
p = p.Has(quad.IRI("schema:kind"), kinds...)
if !filters.WithClosed {
p = p.Has(quad.IRI("schema:state"), quad.Int(dvmodel.Task_Open))
}

if !filters.WithoutExternalDeps {
p = p.Or(p.Both(
quad.IRI("isDependingOn"),
Expand Down

0 comments on commit 7f7e1b8

Please sign in to comment.