-
Notifications
You must be signed in to change notification settings - Fork 0
/
branch.go
64 lines (53 loc) · 1.23 KB
/
branch.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
package main
import (
"encoding/json"
"time"
)
type BranchType string
const (
BranchTypeMain BranchType = "main"
BranchTypeFeature = "feature"
BranchTypeRelease = "release"
BranchTypeReleaseLive = "live"
)
type Branch struct {
Order int `json:"-"`
Name string `json:"name"`
ParentName string `json:"parent"`
Parent *Branch `json:"-"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
BranchType BranchType `json:"type"`
}
type Branches map[string]*Branch
func (bt *BranchType) ToColour() string {
switch *bt {
case BranchTypeFeature:
return "red"
case BranchTypeRelease:
return "green"
case BranchTypeReleaseLive:
return "purple"
case BranchTypeMain:
return "#000"
default:
return "#000"
}
}
func (this *Branches) UnmarshalJSON(b []byte) error {
var branches []*Branch
err := json.Unmarshal(b, &branches)
if err != nil {
return err
}
// Create a name -> *Branch map to save repeated looping
*this = make(map[string]*Branch)
for i, b := range branches {
(*this)[b.Name] = branches[i]
}
for i, b := range branches {
branches[i].Order = i
branches[i].Parent = (*this)[b.ParentName]
}
return nil
}