-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployment_pipeline.go
366 lines (311 loc) · 12.3 KB
/
deployment_pipeline.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package ilert
import (
"encoding/json"
"errors"
"fmt"
"net/url"
"strconv"
)
// DeploymentPipeline definition https://api.ilert.com/api-docs/#tag/deployment-pipelines
type DeploymentPipeline struct {
ID int64 `json:"id"`
Name string `json:"name"`
IntegrationType string `json:"integrationType"`
IntegrationKey string `json:"integrationKey,omitempty"`
Teams []TeamShort `json:"teams,omitempty"`
CreatedAt string `json:"createdAt,omitempty"` // date time string in ISO 8601
UpdatedAt string `json:"updatedAt,omitempty"` // date time string in ISO 8601
IntegrationUrl string `json:"integrationUrl,omitempty"`
Params interface{} `json:"params"`
}
// DeploymentPipelineOutput definition https://api.ilert.com/api-docs/#tag/deployment-pipelines
type DeploymentPipelineOutput struct {
ID int64 `json:"id"`
Name string `json:"name"`
IntegrationType string `json:"integrationType"`
IntegrationKey string `json:"integrationKey,omitempty"`
Teams []TeamShort `json:"teams,omitempty"`
CreatedAt string `json:"createdAt,omitempty"` // date time string in ISO 8601
UpdatedAt string `json:"updatedAt,omitempty"` // date time string in ISO 8601
IntegrationUrl string `json:"integrationUrl,omitempty"`
Params *DeploymentPipelineOutputParams `json:"params"`
}
// DeploymentPipelineParams defines settings for a deployment pipeline
type DeploymentPipelineOutputParams struct {
BranchFilters []string `json:"branchFilters,omitempty"` // used for GitHub and GitLab
EventFilters []string `json:"eventFilters,omitempty"` // used for GitHub and GitLab
}
// DeploymentPipelineGitHubParams definition
type DeploymentPipelineGitHubParams struct {
BranchFilters []string `json:"branchFilters,omitempty"`
EventFilters []string `json:"eventFilters,omitempty"`
}
// DeploymentPipelineGitLabParams definition
type DeploymentPipelineGitLabParams struct {
BranchFilters []string `json:"branchFilters,omitempty"`
EventFilters []string `json:"eventFilters,omitempty"`
}
// IntegrationType defines integration type
var DeploymentPipelineIntegrationType = struct {
Api string
GitHub string
GitLab string
}{
Api: "API",
GitHub: "GITHUB",
GitLab: "GITLAB",
}
// IntegrationTypeAll defines integration type list
var DeploymentPipelineIntegrationTypeAll = []string{
DeploymentPipelineIntegrationType.Api,
DeploymentPipelineIntegrationType.GitHub,
DeploymentPipelineIntegrationType.GitLab,
}
// GitHubEventFilterType defines github event filter type
var GitHubEventFilterType = struct {
PullRequest string
Push string
Release string
}{
PullRequest: "pull_request",
Push: "push",
Release: "release",
}
// GitHubEventFilterTypeAll defines github event filter type list
var GitHubEventFilterTypeAll = []string{
GitHubEventFilterType.PullRequest,
GitHubEventFilterType.Push,
GitHubEventFilterType.Release,
}
// GitLabEventFilterType defines gitlab event filter type
var GitLabEventFilterType = struct {
PushHook string
MergeRequestHook string
ReleaseHook string
}{
PushHook: "Push Hook",
MergeRequestHook: "Merge Request Hook",
ReleaseHook: "Release Hook",
}
// GitLabEventFilterTypeAll defines gitlab event filter type list
var GitLabEventFilterTypeAll = []string{
GitLabEventFilterType.PushHook,
GitLabEventFilterType.MergeRequestHook,
GitLabEventFilterType.ReleaseHook,
}
// CreateDeploymentPipelineInput represents the input of a CreateDeploymentPipeline operation.
type CreateDeploymentPipelineInput struct {
_ struct{}
DeploymentPipeline *DeploymentPipeline
// describes optional properties that should be included in the response
// possible values: "integrationUrl"
Include []*string
}
// CreateDeploymentPipelineOutput represents the output of a CreateDeploymentPipeline operation.
type CreateDeploymentPipelineOutput struct {
_ struct{}
DeploymentPipeline *DeploymentPipelineOutput
}
// CreateDeploymentPipeline creates a new deployment pipeline resource. https://api.ilert.com/api-docs/#tag/deployment-pipelines/post/deployment-pipelines
func (c *Client) CreateDeploymentPipeline(input *CreateDeploymentPipelineInput) (*CreateDeploymentPipelineOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.DeploymentPipeline == nil {
return nil, errors.New("deployment pipeline input is required")
}
q := url.Values{}
for _, include := range input.Include {
q.Add("include", *include)
}
resp, err := c.httpClient.R().SetBody(input.DeploymentPipeline).Post(fmt.Sprintf("%s?%s", apiRoutes.deploymentPipelines, q.Encode()))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 201); apiErr != nil {
return nil, apiErr
}
deploymentPipeline := &DeploymentPipelineOutput{}
err = json.Unmarshal(resp.Body(), deploymentPipeline)
if err != nil {
return nil, err
}
return &CreateDeploymentPipelineOutput{DeploymentPipeline: deploymentPipeline}, nil
}
// GetDeploymentPipelineInput represents the input of a GetDeploymentPipeline operation.
type GetDeploymentPipelineInput struct {
_ struct{}
DeploymentPipelineID *int64
// describes optional properties that should be included in the response
// possible values: "integrationUrl"
Include []*string
}
// GetDeploymentPipelineOutput represents the output of a GetDeploymentPipeline operation.
type GetDeploymentPipelineOutput struct {
_ struct{}
DeploymentPipeline *DeploymentPipelineOutput
}
// GetDeploymentPipeline gets the deployment pipelines resource with specified id. https://api.ilert.com/api-docs/#tag/deployment-pipelines/get/deployment-pipelines/{id}
func (c *Client) GetDeploymentPipeline(input *GetDeploymentPipelineInput) (*GetDeploymentPipelineOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.DeploymentPipelineID == nil {
return nil, errors.New("deployment pipeline id is required")
}
q := url.Values{}
for _, include := range input.Include {
q.Add("include", *include)
}
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/%d?%s", apiRoutes.deploymentPipelines, *input.DeploymentPipelineID, q.Encode()))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
deploymentPipeline := &DeploymentPipelineOutput{}
err = json.Unmarshal(resp.Body(), deploymentPipeline)
if err != nil {
return nil, err
}
return &GetDeploymentPipelineOutput{DeploymentPipeline: deploymentPipeline}, nil
}
// GetDeploymentPipelinesInput represents the input of a GetDeploymentPipelines operation.
type GetDeploymentPipelinesInput struct {
_ struct{}
// an integer specifying the starting point (beginning with 0) when paging through a list of entities
StartIndex *int
// the maximum number of results when paging through a list of entities.
// Maximum: 100
MaxResults *int
}
// GetDeploymentPipelinesOutput represents the output of a GetDeploymentPipelines operation.
type GetDeploymentPipelinesOutput struct {
_ struct{}
DeploymentPipelines []*DeploymentPipelineOutput
}
// GetDeploymentPipelines lists existing deployment pipeline resources. https://api.ilert.com/api-docs/#tag/deployment-pipelines/get/deployment-pipelines
func (c *Client) GetDeploymentPipelines(input *GetDeploymentPipelinesInput) (*GetDeploymentPipelinesOutput, error) {
q := url.Values{}
if input.StartIndex != nil {
q.Add("start-index", strconv.Itoa(*input.StartIndex))
}
if input.MaxResults != nil {
q.Add("max-results", strconv.Itoa(*input.MaxResults))
}
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s?%s", apiRoutes.deploymentPipelines, q.Encode()))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
deploymentPipelines := make([]*DeploymentPipelineOutput, 0)
err = json.Unmarshal(resp.Body(), &deploymentPipelines)
if err != nil {
return nil, err
}
return &GetDeploymentPipelinesOutput{DeploymentPipelines: deploymentPipelines}, nil
}
// SearchDeploymentPipelineInput represents the input of a SearchDeploymentPipeline operation.
type SearchDeploymentPipelineInput struct {
_ struct{}
DeploymentPipelineName *string
}
// SearchDeploymentPipelineOutput represents the output of a SearchDeploymentPipeline operation.
type SearchDeploymentPipelineOutput struct {
_ struct{}
DeploymentPipeline *DeploymentPipelineOutput
}
// SearchDeploymentPipeline gets the deployment pipeline resource with specified name.
func (c *Client) SearchDeploymentPipeline(input *SearchDeploymentPipelineInput) (*SearchDeploymentPipelineOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.DeploymentPipelineName == nil {
return nil, errors.New("deployment pipeline name is required")
}
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.deploymentPipelines, *input.DeploymentPipelineName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
deploymentPipeline := &DeploymentPipelineOutput{}
err = json.Unmarshal(resp.Body(), deploymentPipeline)
if err != nil {
return nil, err
}
return &SearchDeploymentPipelineOutput{DeploymentPipeline: deploymentPipeline}, nil
}
// UpdateDeploymentPipelineInput represents the input of a UpdateDeploymentPipeline operation.
type UpdateDeploymentPipelineInput struct {
_ struct{}
DeploymentPipelineID *int64
DeploymentPipeline *DeploymentPipeline
// describes optional properties that should be included in the response
// possible values: "integrationUrl"
Include []*string
}
// UpdateDeploymentPipelineOutput represents the output of a UpdateDeploymentPipeline operation.
type UpdateDeploymentPipelineOutput struct {
_ struct{}
DeploymentPipeline *DeploymentPipelineOutput
}
// UpdateDeploymentPipeline updates an existing deployment pipeline resource. https://api.ilert.com/api-docs/#tag/deployment-pipelines/put/deployment-pipelines/{id}
func (c *Client) UpdateDeploymentPipeline(input *UpdateDeploymentPipelineInput) (*UpdateDeploymentPipelineOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.DeploymentPipeline == nil {
return nil, errors.New("deployment pipeline input is required")
}
if input.DeploymentPipelineID == nil {
return nil, errors.New("deployment pipeline id is required")
}
q := url.Values{}
for _, include := range input.Include {
q.Add("include", *include)
}
resp, err := c.httpClient.R().SetBody(input.DeploymentPipeline).Put(fmt.Sprintf("%s/%d?%s", apiRoutes.deploymentPipelines, *input.DeploymentPipelineID, q.Encode()))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
deploymentPipeline := &DeploymentPipelineOutput{}
err = json.Unmarshal(resp.Body(), deploymentPipeline)
if err != nil {
return nil, err
}
return &UpdateDeploymentPipelineOutput{DeploymentPipeline: deploymentPipeline}, nil
}
// DeleteDeploymentPipelineInput represents the input of a DeleteDeploymentPipeline operation.
type DeleteDeploymentPipelineInput struct {
_ struct{}
DeploymentPipelineID *int64
}
// DeleteDeploymentPipelineOutput represents the output of a DeleteDeploymentPipeline operation.
type DeleteDeploymentPipelineOutput struct {
_ struct{}
}
// DeleteDeploymentPipeline deletes the specified deployment pipeline resource. https://api.ilert.com/api-docs/#tag/deployment-pipelines/delete/deployment-pipelines/{id}
func (c *Client) DeleteDeploymentPipeline(input *DeleteDeploymentPipelineInput) (*DeleteDeploymentPipelineOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.DeploymentPipelineID == nil {
return nil, errors.New("deployment pipeline id is required")
}
resp, err := c.httpClient.R().Delete(fmt.Sprintf("%s/%d", apiRoutes.deploymentPipelines, *input.DeploymentPipelineID))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 204); apiErr != nil {
return nil, apiErr
}
return &DeleteDeploymentPipelineOutput{}, nil
}