/
task.go
154 lines (140 loc) 路 3.2 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package dvmodel
import (
"strings"
"github.com/cayleygraph/quad"
"github.com/goccy/go-graphviz/cgraph"
"go.uber.org/zap"
)
func (t *Task) AllDeps() []quad.IRI {
if len(t.IsDependingOn) < 1 && len(t.IsBlocking) < 1 {
return nil
}
allDeps := make([]quad.IRI, len(t.IsDependingOn)+len(t.IsBlocking))
copy(allDeps, t.IsDependingOn)
n := len(t.IsDependingOn)
for i, dep := range t.IsBlocking {
allDeps[n+i] = dep
}
return allDeps
}
func FilterIsolatedTasks(in []Task, logger *zap.Logger, filters Filters) []Task {
tasks := map[quad.IRI]Task{}
uniqueDeps := map[quad.IRI]*Task{}
for _, task := range in {
tasks[task.ID] = task
}
for _, task := range in {
for _, dep := range task.IsDependingOn {
if isFiltered(tasks[dep], filters) {
continue
}
uniqueDeps[task.ID] = nil
uniqueDeps[dep] = nil
}
for _, dep := range task.IsBlocking {
if isFiltered(tasks[dep], filters) {
continue
}
uniqueDeps[task.ID] = nil
uniqueDeps[dep] = nil
}
for _, dep := range task.IsRelatedWith {
if isFiltered(tasks[dep], filters) {
continue
}
uniqueDeps[task.ID] = nil
uniqueDeps[dep] = nil
}
for _, dep := range task.IsPartOf {
if isFiltered(tasks[dep], filters) {
continue
}
uniqueDeps[task.ID] = nil
uniqueDeps[dep] = nil
}
for _, dep := range task.HasPart {
if isFiltered(tasks[dep], filters) {
continue
}
uniqueDeps[task.ID] = nil
uniqueDeps[dep] = nil
}
}
for _, task := range in {
taskCopy := task
if _, found := uniqueDeps[task.ID]; found {
uniqueDeps[task.ID] = &taskCopy
}
}
out := make([]Task, len(uniqueDeps))
i := 0
for key, dep := range uniqueDeps {
if dep == nil {
logger.Warn("nil dep", zap.Any("key", key))
} else {
out[i] = *dep
i++
}
}
return out
}
func isFiltered(task Task, filters Filters) bool {
if filters.WithoutPRs && task.Kind == Task_MergeRequest {
return true
}
// TODO: catch external deps
//if filters.WithoutExternalDeps && task. {
// return true
//}
if !filters.WithClosed && task.State == Task_Closed {
return true
}
return false
}
func (t *Task) MarshalCSV() []string {
if t == nil {
return nil
}
return []string{
t.ID.String(),
t.CreatedAt.String(),
t.UpdatedAt.String(),
t.LocalID,
t.Kind.String(),
t.Title,
t.Description,
t.Driver.String(),
t.State.String(),
t.EstimatedDuration,
t.HasAuthor.String(),
t.HasOwner.String(),
// t.IsDependingOn,
// t.IsBlocking,
}
}
type fmtLabel struct {
label string
style string
color string
}
// special depviz labels, used to colorize nodes in the graphviz generation
// TODO: determine a way to create 'themes' with custom config with the following format
var depvizLabels = [...]fmtLabel{
{"focus", "filled,bold,rounded", "#ffeeee"},
{"vision", "filled,rounded", "#eeeeee"},
}
// ApplyLabel apply modifications to the Node based on the label of the task
func (t Task) ApplyLabel(node *cgraph.Node) {
if t.Driver == Driver_GitHub {
for _, label := range t.HasLabel {
s, _ := strings.CutPrefix(label.String(), t.HasOwner.String()+"/labels/")
for _, dl := range depvizLabels {
if s == dl.label {
node.SetStyle(cgraph.NodeStyle(dl.style))
node.SetColor(dl.color)
return
}
}
}
}
}