forked from yext/teamcity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trigger.go
48 lines (42 loc) · 1.14 KB
/
trigger.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
package teamcity
import (
"encoding/json"
"strconv"
)
// Trigger represents something that kicks off a build type.
type Trigger struct {
Id string
DependsOn string
AfterSuccessfulBuildOnly bool
}
type jsonTrigger struct {
Id string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
PropertyList *PropertyList `json:"properties,omitempty"`
}
type Triggers struct {
Triggers []jsonTrigger `json:"trigger,omitempty"`
}
func (t *Trigger) UnmarshalJSON(data []byte) error {
var jt jsonTrigger
e := json.Unmarshal(data, &jt)
if e != nil {
return e
}
*t = Trigger{
Id: jt.Id,
DependsOn: jt.PropertyList.Value("dependsOn"),
AfterSuccessfulBuildOnly: jt.PropertyList.Bool("afterSuccessfulBuildOnly"),
}
return nil
}
func (t Trigger) MarshalJSON() ([]byte, error) {
return json.Marshal(jsonTrigger{
Id: t.Id,
Type: "buildDependencyTrigger",
PropertyList: NewPropertyList(map[string]string{
"dependsOn": t.DependsOn,
"afterSuccessfulBuildOnly": strconv.FormatBool(t.AfterSuccessfulBuildOnly),
}),
})
}