forked from umweltdk/teamcity
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvcs_root.go
64 lines (54 loc) · 1.23 KB
/
vcs_root.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 types
import (
"encoding/json"
)
type VcsRoot struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
VcsName string `json:"vcsName,omitempty"`
Href string `json:"href,omitempty"`
ProjectID ProjectId `json:"project,omitempty"`
Properties Properties `json:"properties,omitempty"`
}
type VcsRootShort struct {
ID string `json:"id"`
Name string `json:"name"`
Href string `json:"href"`
}
type VcsRootId string
func (v VcsRootId) MarshalJSON() ([]byte, error) {
vrs := &VcsRootShort{
ID: string(v),
}
return json.Marshal(vrs)
}
func (v *VcsRootId) UnmarshalJSON(b []byte) error {
var vrs VcsRootShort
if err := json.Unmarshal(b, &vrs); err != nil {
return err
}
*v = VcsRootId(vrs.ID)
return nil
}
type VcsRoots []VcsRootShort
type vcsRootsInput struct {
VcsRoot []VcsRootShort `json:"vcs-root"`
}
func (vc VcsRoots) MarshalJSON() ([]byte, error) {
vci := &vcsRootsInput{
VcsRoot: vc,
}
return json.Marshal(vci)
}
func (vc *VcsRoots) UnmarshalJSON(b []byte) error {
var vci vcsRootsInput
if err := json.Unmarshal(b, &vci); err != nil {
return err
}
if vci.VcsRoot != nil {
*vc = vci.VcsRoot
} else {
*vc = make(VcsRoots, 0)
}
return nil
}