forked from umweltdk/teamcity
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild_configuration.go
86 lines (76 loc) · 2.53 KB
/
build_configuration.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
package types
import (
"encoding/json"
)
type BuildConfiguration struct {
ID string `json:"id,omitempty"`
ProjectID string `json:"projectId"`
TemplateFlag bool `json:"templateFlag"`
TemplateID TemplateId `json:"template,omitempty"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
VcsRootEntries VcsRootEntries `json:"vcs-root-entries,omitempty"`
Settings BuildSettings `json:"settings,omitempty"`
Parameters Parameters `json:"parameters,omitempty"`
Steps BuildSteps `json:"steps,omitempty"`
Features BuildFeatures `json:"features,omitempty"`
Triggers BuildTriggers `json:"triggers,omitempty"`
SnapshotDependencies BuildSnapshotDependencies `json:"snapshot-dependencies,omitempty"`
ArtifactDependencies BuildArtifactDependencies `json:"artifact-dependencies,omitempty"`
AgentRequirements BuildAgentRequirements `json:"agent-requirements,omitempty"`
}
type TemplateId string
type BuildConfigurationShort struct {
ID string `json:"id"`
ProjectID string `json:"projectId,omitempty"`
TemplateFlag bool `json:"templateFlag,omitempty"`
Name string `json:"name,omitempty"`
Href string `json:"href,omitempty"`
}
func (p TemplateId) MarshalJSON() ([]byte, error) {
if p != "" {
pi := &BuildConfigurationShort{
ID: string(p),
}
return json.Marshal(pi)
} else {
return json.Marshal(nil)
}
}
func (p *TemplateId) UnmarshalJSON(b []byte) error {
var pi *BuildConfigurationShort
if err := json.Unmarshal(b, &pi); err != nil {
return err
}
if pi == nil {
*p = ""
} else {
*p = TemplateId(pi.ID)
}
return nil
}
type BuildConfigurations map[string]BuildConfiguration
type buildConfigurationsInput struct {
BuildType []BuildConfiguration
}
func (bc BuildConfigurations) MarshalJSON() ([]byte, error) {
bci := &buildConfigurationsInput{
BuildType: make([]BuildConfiguration, 0),
}
for _, value := range bc {
bci.BuildType = append(bci.BuildType, value)
}
return json.Marshal(bci)
}
func (bc *BuildConfigurations) UnmarshalJSON(b []byte) error {
var bci buildConfigurationsInput
if err := json.Unmarshal(b, &bci); err != nil {
return err
}
m := make(BuildConfigurations)
for _, bt := range bci.BuildType {
m[bt.ID] = bt
}
*bc = m
return nil
}