/
minionator.go
88 lines (82 loc) · 2.41 KB
/
minionator.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
package main
import (
"github.com/fatih/color"
"gopkg.in/gcfg.v1"
"fmt"
"log"
"strconv"
)
func main() {
var cfg Config
err := gcfg.ReadFileInto(&cfg, ".config")
if err != nil {
log.Fatal(err)
}
if ContainsString("OpenChildren", cfg.Minionator.Task) {
OpenChildren(cfg)
}
if ContainsString("CloseChildren", cfg.Minionator.Task) {
CloseChildren(cfg)
}
}
func OpenChildren(cfg Config) {
parent := GetBug(strconv.Itoa(cfg.Bugzilla.Parent), cfg)
if parent.Id == cfg.Bugzilla.Parent {
for _, alias := range cfg.Bugzilla.Child {
child := GetBug(alias, cfg)
if child.Alias == alias {
fmt.Printf("bug %v found for %v\n", child.Id, child.Alias)
if ContainsInt(cfg.Bugzilla.Parent, child.DependsOn) {
color.Blue(" - is linked to parent %v", cfg.Bugzilla.Parent)
} else {
color.Yellow(" - not linked to parent %v", cfg.Bugzilla.Parent)
}
if !child.IsOpen {
if SetDepends(parent.Id, child.Id, fmt.Sprint("allocated to bug ", parent.Id), cfg) {
color.Green(" - reopened %v (%v) and linked to parent %v", child.Id, child.Alias, parent.Id)
}
}
} else {
color.Yellow("no bug found for %v", alias)
//todo: create the bug
}
}
}
}
func CloseChildren(cfg Config) {
parent := GetBug(strconv.Itoa(cfg.Bugzilla.Parent), cfg)
if parent.Id == cfg.Bugzilla.Parent {
for _, alias := range cfg.Bugzilla.Child {
child := GetBug(alias, cfg)
if child.Alias == alias {
fmt.Printf("bug %v found for %v\n", child.Id, child.Alias)
if ContainsInt(cfg.Bugzilla.Parent, child.DependsOn) {
color.Blue(" - is linked to parent %v", cfg.Bugzilla.Parent)
if child.IsOpen {
if Resolve(parent.Id, child.Id, fmt.Sprint("deallocated from bug ", parent.Id), cfg) {
color.Green(" - resolved %v (%v) and deallocated from parent %v", child.Id, child.Alias, parent.Id)
}
}
} else {
color.Yellow(" - not linked to parent %v", cfg.Bugzilla.Parent)
}
}
}
}
}
func ContainsInt(needle int, haystack []int) bool {
for _, straw := range haystack {
if straw == needle {
return true
}
}
return false
}
func ContainsString(needle string, haystack []string) bool {
for _, straw := range haystack {
if straw == needle {
return true
}
}
return false
}