-
Notifications
You must be signed in to change notification settings - Fork 59
/
pipeline_templates.go
131 lines (107 loc) · 3.86 KB
/
pipeline_templates.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
package buildkite
import (
"context"
"fmt"
)
// PipelineTemplatesService handles communication with pipeline template related
// methods of the Buildkite API.
//
// Buildkite API docs: <to-fill>
type PipelineTemplatesService struct {
client *Client
}
type PipelineTemplate struct {
UUID string `json:"uuid,omitempty"`
GraphQLID string `json:"graphql_id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Configuration string `json:"configuration,omitempty"`
Available bool `json:"available"`
URL string `json:"url,omitempty"`
WebURL string `json:"web_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
CreatedBy PipelineTemplateCreator `json:"created_by,omitempty"`
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
UpdatedBy PipelineTemplateCreator `json:"updated_by,omitempty"`
}
type PipelineTemplateCreateUpdate struct {
Name string `json:"name,omitempty"`
Configuration string `json:"configuration,omitempty"`
Description string `json:"description,omitempty"`
Available bool `json:"available"`
}
type PipelineTemplateCreator struct {
ID string `json:"id,omitempty"`
GraphQLID string `json:"graphql_id,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}
type PipelineTemplateListOptions struct {
ListOptions
}
func (pts *PipelineTemplatesService) List(ctx context.Context, org string, opt *PipelineTemplateListOptions) ([]PipelineTemplate, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/pipeline-templates", org)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := pts.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var templates []PipelineTemplate
resp, err := pts.client.Do(req, &templates)
if err != nil {
return nil, resp, err
}
return templates, resp, err
}
func (pts *PipelineTemplatesService) Get(ctx context.Context, org, templateUUID string) (PipelineTemplate, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/pipeline-templates/%s", org, templateUUID)
req, err := pts.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return PipelineTemplate{}, nil, err
}
var template PipelineTemplate
resp, err := pts.client.Do(req, &template)
if err != nil {
return PipelineTemplate{}, resp, err
}
return template, resp, err
}
func (pts *PipelineTemplatesService) Create(ctx context.Context, org string, ptc PipelineTemplateCreateUpdate) (PipelineTemplate, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/pipeline-templates", org)
req, err := pts.client.NewRequest(ctx, "POST", u, ptc)
if err != nil {
return PipelineTemplate{}, nil, err
}
var template PipelineTemplate
resp, err := pts.client.Do(req, &template)
if err != nil {
return PipelineTemplate{}, resp, err
}
return template, resp, err
}
func (pts *PipelineTemplatesService) Update(ctx context.Context, org, templateUUID string, ptu PipelineTemplateCreateUpdate) (PipelineTemplate, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/pipeline-templates/%s", org, templateUUID)
req, err := pts.client.NewRequest(ctx, "PATCH", u, ptu)
if err != nil {
return PipelineTemplate{}, nil, err
}
var template PipelineTemplate
resp, err := pts.client.Do(req, &template)
if err != nil {
return PipelineTemplate{}, resp, err
}
return template, resp, err
}
func (pts *PipelineTemplatesService) Delete(ctx context.Context, org, templateUUID string) (*Response, error) {
u := fmt.Sprintf("v2/organizations/%s/pipeline-templates/%s", org, templateUUID)
req, err := pts.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
return pts.client.Do(req, nil)
}