From 7f7e1b8eded869b6e0f2b01e3ca88ac82310fb10 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Tue, 26 Nov 2019 18:21:24 +0100 Subject: [PATCH] feat: 'the world' target --- internal/dvcore/run.go | 2 ++ internal/dvserver/api.go | 14 ++++++---- internal/dvstore/query.go | 55 +++++++++++++++++++++------------------ 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/internal/dvcore/run.go b/internal/dvcore/run.go index 3580eeb04..77aaa014c 100644 --- a/internal/dvcore/run.go +++ b/internal/dvcore/run.go @@ -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) diff --git a/internal/dvserver/api.go b/internal/dvserver/api.go index 17354636c..0617a633b 100644 --- a/internal/dvserver/api.go +++ b/internal/dvserver/api.go @@ -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 diff --git a/internal/dvstore/query.go b/internal/dvstore/query.go index 3aaa49eee..8331ecb8d 100644 --- a/internal/dvstore/query.go +++ b/internal/dvstore/query.go @@ -50,6 +50,7 @@ func LastUpdatedIssueInRepo(ctx context.Context, h *cayley.Handle, entity multip type LoadTasksFilters struct { Targets []multipmuri.Entity + TheWorld bool WithClosed bool WithoutIsolated bool WithoutPRs bool @@ -57,44 +58,48 @@ type LoadTasksFilters struct { } 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"),