forked from harness/gitness
/
types.go
212 lines (187 loc) · 4.41 KB
/
types.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package internal
import (
"net/url"
"strconv"
"time"
)
type Account struct {
Login string `json:"username"`
Name string `json:"display_name"`
Type string `json:"type"`
Links Links `json:"links"`
}
type AccountResp struct {
Page int `json:"page"`
Pages int `json:"pagelen"`
Size int `json:"size"`
Next string `json:"next"`
Values []*Account `json:"values"`
}
type BuildStatus struct {
State string `json:"state"`
Key string `json:"key"`
Name string `json:"name,omitempty"`
Url string `json:"url"`
Desc string `json:"description,omitempty"`
}
type Email struct {
Email string `json:"email"`
IsConfirmed bool `json:"is_confirmed"`
IsPrimary bool `json:"is_primary"`
}
type EmailResp struct {
Page int `json:"page"`
Pages int `json:"pagelen"`
Size int `json:"size"`
Next string `json:"next"`
Values []*Email `json:"values"`
}
type Hook struct {
Uuid string `json:"uuid,omitempty"`
Desc string `json:"description"`
Url string `json:"url"`
Events []string `json:"events"`
Active bool `json:"active"`
}
type HookResp struct {
Page int `json:"page"`
Pages int `json:"pagelen"`
Size int `json:"size"`
Next string `json:"next"`
Values []*Hook `json:"values"`
}
type Links struct {
Avatar Link `json:"avatar"`
Html Link `json:"html"`
Clone []Link `json:"clone"`
}
type Link struct {
Href string `json:"href"`
Name string `json:"name"`
}
type LinkClone struct {
Link
}
type Repo struct {
Owner Account `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Language string `json:"language"`
IsPrivate bool `json:"is_private"`
Scm string `json:"scm"`
Desc string `json:"desc"`
Links Links `json:"links"`
}
type RepoResp struct {
Page int `json:"page"`
Pages int `json:"pagelen"`
Size int `json:"size"`
Next string `json:"next"`
Values []*Repo `json:"values"`
}
type Source struct {
Node string `json:"node"`
Path string `json:"path"`
Data string `json:"data"`
Size int64 `json:"size"`
}
type Change struct {
New struct {
Type string `json:"type"`
Name string `json:"name"`
Target struct {
Type string `json:"type"`
Hash string `json:"hash"`
Message string `json:"message"`
Date time.Time `json:"date"`
Links Links `json:"links"`
Author struct {
Raw string `json:"raw"`
User Account `json:"user"`
} `json:"author"`
} `json:"target"`
} `json:"new"`
}
type PushHook struct {
Actor Account `json:"actor"`
Repo Repo `json:"repository"`
Push struct {
Changes []Change `json:"changes"`
} `json:"push"`
}
type PullRequestHook struct {
Actor Account `json:"actor"`
Repo Repo `json:"repository"`
PullRequest struct {
ID int `json:"id"`
Type string `json:"type"`
Reason string `json:"reason"`
Desc string `json:"description"`
Title string `json:"title"`
State string `json:"state"`
Links Links `json:"links"`
Created time.Time `json:"created_on"`
Updated time.Time `json:"updated_on"`
Source struct {
Repo Repo `json:"repsoitory"`
Commit struct {
Hash string `json:"hash"`
Links Links `json:"links"`
} `json:"commit"`
Branch struct {
Name string `json:"name"`
} `json:"branch"`
} `json:"source"`
Dest struct {
Repo Repo `json:"repsoitory"`
Commit struct {
Hash string `json:"hash"`
Links Links `json:"links"`
} `json:"commit"`
Branch struct {
Name string `json:"name"`
} `json:"branch"`
} `json:"destination"`
} `json:"pullrequest"`
}
type ListOpts struct {
Page int
PageLen int
}
func (o *ListOpts) Encode() string {
params := url.Values{}
if o.Page != 0 {
params.Set("page", strconv.Itoa(o.Page))
}
if o.PageLen != 0 {
params.Set("pagelen", strconv.Itoa(o.PageLen))
}
return params.Encode()
}
type ListTeamOpts struct {
Page int
PageLen int
Role string
}
func (o *ListTeamOpts) Encode() string {
params := url.Values{}
if o.Page != 0 {
params.Set("page", strconv.Itoa(o.Page))
}
if o.PageLen != 0 {
params.Set("pagelen", strconv.Itoa(o.PageLen))
}
if len(o.Role) != 0 {
params.Set("role", o.Role)
}
return params.Encode()
}
type Error struct {
Status int
Body struct {
Message string `json:"message"`
} `json:"error"`
}
func (e Error) Error() string {
return e.Body.Message
}