forked from umweltdk/teamcity
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild.go
127 lines (111 loc) · 2.09 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
119
120
121
122
123
124
125
126
127
package types
import (
"encoding/json"
"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
}
Tags []string `json:"tags,omitempty"`
Properties Properties `json:"properties"`
}
type Tags []string
type tagInput struct {
Name string `json:"name"`
}
type tagsInput struct {
Tag []tagInput `json:"tag"`
}
func (tags Tags) MarshalJSON() ([]byte, error) {
tagInputs := make([]tagInput, len(tags))
for idx, tag := range tags {
tagInputs[idx] = tagInput{tag}
}
ti := &tagsInput{
Tag: tagInputs,
}
return json.Marshal(ti)
}
func (tags *Tags) UnmarshalJSON(b []byte) error {
var ti tagsInput
if err := json.Unmarshal(b, &ti); err != nil {
return err
}
if ti.Tag != nil {
*tags = make(Tags, len(ti.Tag))
for idx, tag := range ti.Tag {
(*tags)[idx] = tag.Name
}
} else {
*tags = make(Tags, 0)
}
return nil
}
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
}