Skip to content

Commit e19c7be

Browse files
authored
feat: scoped issue (#666)
* feat: scoped issue Signed-off-by: ismael FALL <ismael.fall@epitech.eu> * feat: unit-tests scpoed issue Signed-off-by: ismael FALL <ismael.fall@epitech.eu> * test(scope-issue): verify every output of scope issue are related to the target one --------- Signed-off-by: ismael FALL <ismael.fall@epitech.eu>
1 parent 7cb533d commit e19c7be

File tree

9 files changed

+282
-109
lines changed

9 files changed

+282
-109
lines changed

cmd/depviz/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ var (
7070
genHideExternalDeps = genFlags.Bool("hide-external-deps", false, "hide dependencies outside of the specified targets")
7171
genHideIsolated = genFlags.Bool("hide-isolated", false, "hide isolated tasks")
7272
genShowClosed = genFlags.Bool("show-closed", false, "show closed tasks")
73+
genScope = genFlags.String("scope", "", "target scope")
74+
genScopeSize = genFlags.Int("scope-size", 1, "scope size")
7375

7476
fetchFlags = flag.NewFlagSet("fetch", flag.ExitOnError)
7577
fetchGitHubToken = fetchFlags.String("github-token", "", "GitHub token")
@@ -371,6 +373,8 @@ func execGenGraphviz(ctx context.Context, args []string) error {
371373
HideIsolated: *genHideIsolated,
372374
HidePRs: *genHidePRs,
373375
HideExternalDeps: *genHideExternalDeps,
376+
Scope: *genScope,
377+
ScopeSize: *genScopeSize,
374378
}
375379

376380
opts := dvcore.GraphvizOpts{
@@ -403,6 +407,8 @@ func execGenJSON(ctx context.Context, args []string) error {
403407
HideIsolated: *genHideIsolated,
404408
HidePRs: *genHidePRs,
405409
HideExternalDeps: *genHideExternalDeps,
410+
Scope: *genScope,
411+
ScopeSize: *genScopeSize,
406412
Format: "json",
407413
}
408414

@@ -429,6 +435,8 @@ func execGenCSV(ctx context.Context, args []string) error {
429435
HideIsolated: *genHideIsolated,
430436
HidePRs: *genHidePRs,
431437
HideExternalDeps: *genHideExternalDeps,
438+
Scope: *genScope,
439+
ScopeSize: *genScopeSize,
432440
Format: "csv",
433441
}
434442

go.mod

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/dvcore/gen.go

Lines changed: 87 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ type GenOpts struct {
3535
HideIsolated bool
3636
HidePRs bool
3737
HideExternalDeps bool
38+
Scope string
39+
ScopeSize int
3840
}
3941

4042
func Gen(h *cayley.Handle, args []string, opts GenOpts) error {
@@ -50,87 +52,97 @@ func Gen(h *cayley.Handle, args []string, opts GenOpts) error {
5052
return fmt.Errorf("parse targets: %w", err)
5153
}
5254

53-
if !opts.NoGraph { // nolint:nestif
54-
// load tasks
55-
filters := dvmodel.Filters{
56-
Targets: targets,
57-
WithClosed: opts.ShowClosed,
58-
WithoutIsolated: opts.HideIsolated,
59-
WithoutPRs: opts.HidePRs,
60-
WithoutExternalDeps: opts.HideExternalDeps,
61-
}
62-
tasks, err := dvstore.LoadTasks(h, opts.Schema, filters, opts.Logger)
55+
var scope multipmuri.Entity
56+
if opts.Scope != "" {
57+
scope, err = dvparser.ParseTarget(opts.Scope)
6358
if err != nil {
6459
return fmt.Errorf("load tasks: %w", err)
6560
}
61+
}
6662

67-
// graph
68-
pertConfig := graphmanPertConfig(tasks, opts)
69-
70-
switch opts.Format {
71-
case "json":
72-
return genJSON(tasks)
73-
case "csv":
74-
return genCSV(tasks)
75-
case "graphman-pert":
76-
out, err := yaml.Marshal(pertConfig)
77-
if err != nil {
78-
return err
79-
}
80-
fmt.Println(string(out))
81-
return nil
82-
// TODO: fix many issues with generated dependencies
83-
//case "dot":
84-
// // graph from PERT config
85-
// graph := graphman.FromPertConfig(*pertConfig)
86-
//
87-
// // initialize graph from config
88-
// if !opts.NoPert {
89-
// result := graphman.ComputePert(graph)
90-
// shortestPath, distance := graph.FindShortestPath("Start", "Finish")
91-
// opts.Logger.Debug("pert result", zap.Any("result", result), zap.Int64("distance", distance))
92-
//
93-
// for _, edge := range shortestPath {
94-
// edge.Dst().SetColor("red")
95-
// edge.SetColor("red")
96-
// }
97-
// }
98-
//
99-
// // graph fine tuning
100-
// graph.GetVertex("Start").SetColor("blue")
101-
// graph.GetVertex("Finish").SetColor("blue")
102-
// if opts.Vertical {
103-
// graph.Attrs["rankdir"] = "TB"
104-
// }
105-
// graph.Attrs["overlap"] = "false"
106-
// graph.Attrs["pack"] = "true"
107-
// graph.Attrs["splines"] = "true"
108-
// graph.Attrs["sep"] = "0.1"
109-
// // graph.Attrs["layout"] = "neato"
110-
// // graph.Attrs["size"] = "\"11,11\""
111-
// // graph.Attrs["start"] = "random"
112-
// // FIXME: hightlight critical paths
113-
// // FIXME: highlight other infos
114-
// // FIXME: highlight target
115-
//
116-
// // graphviz
117-
// s, err := viz.ToGraphviz(graph, &viz.Opts{
118-
// CommentsInLabel: true,
119-
// })
120-
// if err != nil {
121-
// return fmt.Errorf("graphviz: %w", err)
122-
// }
123-
//
124-
// fmt.Println(s)
125-
// return nil
126-
case "quads":
127-
return fmt.Errorf("not implemented")
128-
default:
129-
return fmt.Errorf("unsupported graph format: %q", opts.Format)
130-
}
63+
if opts.NoGraph { // nolint:nestif
64+
return nil
13165
}
13266

133-
return nil
67+
// load tasks
68+
filters := dvmodel.Filters{
69+
Targets: targets,
70+
WithClosed: opts.ShowClosed,
71+
WithoutIsolated: opts.HideIsolated,
72+
WithoutPRs: opts.HidePRs,
73+
WithoutExternalDeps: opts.HideExternalDeps,
74+
Scope: scope,
75+
ScopeSize: opts.ScopeSize,
76+
}
77+
tasks, err := dvstore.LoadTasks(h, opts.Schema, filters, opts.Logger)
78+
if err != nil {
79+
return fmt.Errorf("load tasks: %w", err)
80+
}
81+
82+
// graph
83+
pertConfig := graphmanPertConfig(tasks, opts)
84+
85+
switch opts.Format {
86+
case "json":
87+
return genJSON(tasks)
88+
case "csv":
89+
return genCSV(tasks)
90+
case "graphman-pert":
91+
out, err := yaml.Marshal(pertConfig)
92+
if err != nil {
93+
return err
94+
}
95+
fmt.Println(string(out))
96+
return nil
97+
// TODO: fix many issues with generated dependencies
98+
//case "dot":
99+
// // graph from PERT config
100+
// graph := graphman.FromPertConfig(*pertConfig)
101+
//
102+
// // initialize graph from config
103+
// if !opts.NoPert {
104+
// result := graphman.ComputePert(graph)
105+
// shortestPath, distance := graph.FindShortestPath("Start", "Finish")
106+
// opts.Logger.Debug("pert result", zap.Any("result", result), zap.Int64("distance", distance))
107+
//
108+
// for _, edge := range shortestPath {
109+
// edge.Dst().SetColor("red")
110+
// edge.SetColor("red")
111+
// }
112+
// }
113+
//
114+
// // graph fine tuning
115+
// graph.GetVertex("Start").SetColor("blue")
116+
// graph.GetVertex("Finish").SetColor("blue")
117+
// if opts.Vertical {
118+
// graph.Attrs["rankdir"] = "TB"
119+
// }
120+
// graph.Attrs["overlap"] = "false"
121+
// graph.Attrs["pack"] = "true"
122+
// graph.Attrs["splines"] = "true"
123+
// graph.Attrs["sep"] = "0.1"
124+
// // graph.Attrs["layout"] = "neato"
125+
// // graph.Attrs["size"] = "\"11,11\""
126+
// // graph.Attrs["start"] = "random"
127+
// // FIXME: hightlight critical paths
128+
// // FIXME: highlight other infos
129+
// // FIXME: highlight target
130+
//
131+
// // graphviz
132+
// s, err := viz.ToGraphviz(graph, &viz.Opts{
133+
// CommentsInLabel: true,
134+
// })
135+
// if err != nil {
136+
// return fmt.Errorf("graphviz: %w", err)
137+
// }
138+
//
139+
// fmt.Println(s)
140+
// return nil
141+
case "quads":
142+
return fmt.Errorf("not implemented")
143+
default:
144+
return fmt.Errorf("unsupported graph format: %q", opts.Format)
145+
}
134146
}
135147

136148
func pullBatches(targets []multipmuri.Entity, h *cayley.Handle, githubToken string, resync bool, logger *zap.Logger) []dvmodel.Batch {

pkg/dvmodel/filters.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ type Filters struct {
1212
WithoutPRs bool
1313
WithoutExternalDeps bool
1414
WithFetch bool
15+
Scope multipmuri.Entity
16+
ScopeSize int
1517
}

pkg/dvstore/query.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,35 @@ func LoadTasks(h *cayley.Handle, schema *schema.Config, filters dvmodel.Filters,
6060
ctx := context.TODO()
6161

6262
// fetch targets
63-
paths := []*path.Path{}
64-
if filters.TheWorld {
65-
paths = append(paths, path.StartPath(h))
66-
} else {
67-
for _, target := range filters.Targets {
68-
// FIXME: handle different target types (for now only repo)
69-
p := path.StartPath(h, quad.IRI(target.String())).
70-
Both().
71-
Has(quad.IRI("rdf:type"), quad.IRI("dv:Task"))
72-
73-
// FIXME: reverse depends/blocks
74-
paths = append(paths, p)
63+
var p *path.Path
64+
if filters.Scope == nil {
65+
paths := []*path.Path{}
66+
if filters.TheWorld {
67+
paths = append(paths, path.StartPath(h))
68+
} else {
69+
for _, target := range filters.Targets {
70+
// FIXME: handle different target types (for now only repo)
71+
p := path.StartPath(h, quad.IRI(target.String())).
72+
Both().
73+
Has(quad.IRI("rdf:type"), quad.IRI("dv:Task"))
74+
75+
// FIXME: reverse depends/blocks
76+
paths = append(paths, p)
77+
}
7578
}
76-
}
77-
p := paths[0]
78-
for _, path := range paths[1:] {
79-
p = p.Or(path)
79+
p = paths[0]
80+
for _, path := range paths[1:] {
81+
p = p.Or(path)
82+
}
83+
} else {
84+
p = path.StartPath(h, quad.IRI(filters.Scope.String())).Is(quad.IRI(filters.Scope.String()))
85+
p = scopeIssue(p, filters.ScopeSize, []quad.IRI{
86+
"isDependingOn",
87+
"isBlocking",
88+
//"IsRelatedWith",
89+
//"IsPartOf",
90+
//"HasPart",
91+
})
8092
}
8193

8294
// filters

pkg/dvstore/query_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
_ "github.com/cayleygraph/quad/json"
1010
"github.com/stretchr/testify/assert"
11+
"moul.io/depviz/v3/pkg/dvmodel"
1112
"moul.io/depviz/v3/pkg/dvparser"
1213
"moul.io/depviz/v3/pkg/multipmuri"
1314
"moul.io/depviz/v3/pkg/testutil"
@@ -18,19 +19,19 @@ func TestLoadTasks(t *testing.T) {
1819
tests := []struct {
1920
golden string
2021
name string
21-
filters LoadTasksFilters
22+
filters dvmodel.Filters
2223
expectedErr error
2324
}{
24-
{"all-depviz-test", "theworld", LoadTasksFilters{TheWorld: true}, nil},
25-
{"all-depviz-test", "theworld-light", LoadTasksFilters{TheWorld: true, WithoutPRs: true, WithClosed: false, WithoutExternalDeps: true}, nil},
26-
{"all-depviz-test", "theworld-with-closed", LoadTasksFilters{TheWorld: true, WithClosed: true}, nil},
27-
{"all-depviz-test", "theworld-without-prs", LoadTasksFilters{TheWorld: true, WithoutPRs: true}, nil},
28-
{"all-depviz-test", "theworld-without-isolated", LoadTasksFilters{TheWorld: true, WithoutIsolated: true}, nil},
29-
{"all-depviz-test", "theworld-without-external-deps", LoadTasksFilters{TheWorld: true, WithoutExternalDeps: true}, nil},
30-
{"all-depviz-test", "theworld-all-flags", LoadTasksFilters{TheWorld: true, WithClosed: true, WithoutPRs: true, WithoutIsolated: true, WithoutExternalDeps: true}, nil},
31-
{"all-depviz-test", "moul-depviz-test", LoadTasksFilters{Targets: parseTargets(t, "moul/depviz-test")}, nil},
32-
{"all-depviz-test", "moulbot-depviz-test", LoadTasksFilters{Targets: parseTargets(t, "moul-bot/depviz-test")}, nil},
33-
{"all-depviz-test", "moul-and-moulbot-depviz-test", LoadTasksFilters{Targets: parseTargets(t, "moul/depviz-test, moul-bot/depviz-test")}, nil},
25+
{"all-depviz-test", "theworld", dvmodel.Filters{TheWorld: true}, nil},
26+
{"all-depviz-test", "theworld-light", dvmodel.Filters{TheWorld: true, WithoutPRs: true, WithClosed: false, WithoutExternalDeps: true}, nil},
27+
{"all-depviz-test", "theworld-with-closed", dvmodel.Filters{TheWorld: true, WithClosed: true}, nil},
28+
{"all-depviz-test", "theworld-without-prs", dvmodel.Filters{TheWorld: true, WithoutPRs: true}, nil},
29+
{"all-depviz-test", "theworld-without-isolated", dvmodel.Filters{TheWorld: true, WithoutIsolated: true}, nil},
30+
{"all-depviz-test", "theworld-without-external-deps", dvmodel.Filters{TheWorld: true, WithoutExternalDeps: true}, nil},
31+
{"all-depviz-test", "theworld-all-flags", dvmodel.Filters{TheWorld: true, WithClosed: true, WithoutPRs: true, WithoutIsolated: true, WithoutExternalDeps: true}, nil},
32+
{"all-depviz-test", "moul-depviz-test", dvmodel.Filters{Targets: parseTargets(t, "moul/depviz-test")}, nil},
33+
{"all-depviz-test", "moulbot-depviz-test", dvmodel.Filters{Targets: parseTargets(t, "moul-bot/depviz-test")}, nil},
34+
{"all-depviz-test", "moul-and-moulbot-depviz-test", dvmodel.Filters{Targets: parseTargets(t, "moul/depviz-test, moul-bot/depviz-test")}, nil},
3435
}
3536
alreadySeen := map[string]bool{}
3637
for _, testptr := range tests {

0 commit comments

Comments
 (0)