forked from abourget/teamcity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.go
118 lines (102 loc) · 2.1 KB
/
build.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
package teamcity
import "fmt"
// Build represents a TeamCity build, along with its metadata.
type Build struct {
ID int64
BuildTypeID string
BuildType struct {
ID string
Name string
Description string
ProjectName string
ProjectID string
HREF string
WebURL string
}
Triggered struct {
Type string
Date JSONTime
User struct {
Username string
}
}
Changes struct {
Change []Change
}
QueuedDate JSONTime
StartDate JSONTime
FinishDate JSONTime
Number string
Status string
StatusText string
State string
BranchName string
Personal bool
Running bool
Pinned bool
DefaultBranch bool
HREF string
WebURL string
Agent struct {
ID int64
Name string
TypeID int64
HREF string
}
ProblemOccurrences struct {
ProblemOccurrence []ProblemOccurrence
}
TestOccurrences struct {
TestOccurrence []TestOccurrence
}
// As received from the API
TagsInput struct {
Tag []struct {
Name string
}
} `json:"tags"`
// Useable, filled before sending to `IncomingBuilds`
Tags []string `json:"-"`
// As received from the API
PropertiesInput struct {
Property []oneProperty `json:"property"`
} `json:"properties"`
// Useable, filled before sending to `IncomingBuilds`
Properties map[string]string `json:"-"`
}
type oneProperty struct {
Name string `json:"name"`
Value string `json:"value"`
}
func (b *Build) convertInputs() {
b.Tags = make([]string, 0)
for _, tag := range b.TagsInput.Tag {
b.Tags = append(b.Tags, tag.Name)
}
b.Properties = make(map[string]string)
for _, prop := range b.PropertiesInput.Property {
b.Properties[prop.Name] = prop.Value
}
}
func (b *Build) String() string {
return fmt.Sprintf("Build %d, %#v state=%s", b.ID, b.ComputedState(), b.State)
}
type State int
const (
Unknown = State(iota)
Queued
Started
Finished
)
func (b *Build) ComputedState() State {
if b.QueuedDate == "" {
return Unknown
}
if b.StartDate == "" {
return Queued
}
if b.FinishDate == "" {
return Started
}
return Finished
}