-
Notifications
You must be signed in to change notification settings - Fork 59
/
clusters.go
136 lines (113 loc) · 3.9 KB
/
clusters.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
package buildkite
import (
"context"
"fmt"
)
// ClustersService handles communication with cluster related
// methods of the Buildkite API.
//
// Buildkite API docs: https://buildkite.com/docs/apis/rest-api/clusters#clusters
type ClustersService struct {
client *Client
}
type ClusterCreate struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Emoji string `json:"emoji,omitempty"`
Color string `json:"color,omitempty"`
}
type ClusterUpdate struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Emoji string `json:"emoji,omitempty"`
Color string `json:"color,omitempty"`
DefaultQueueID string `json:"default_queue_id,omitempty"`
}
type Cluster struct {
ID string `json:"id,omitempty"`
GraphQLID string `json:"graphql_id,omitempty"`
DefaultQueueID string `json:"default_queue_id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Emoji string `json:"emoji,omitempty"`
Color string `json:"color,omitempty"`
URL string `json:"url,omitempty"`
WebURL string `json:"web_url,omitempty"`
QueuesURL string `json:"queues_url,omitempty"`
DefaultQueueURL string `json:"default_queue_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
CreatedBy ClusterCreator `json:"created_by,omitempty"`
}
type ClusterCreator 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 ClustersListOptions struct{ ListOptions }
func (cs *ClustersService) List(ctx context.Context, org string, opt *ClustersListOptions) ([]Cluster, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters", org)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := cs.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var clusters []Cluster
resp, err := cs.client.Do(req, &clusters)
if err != nil {
return nil, resp, err
}
return clusters, resp, err
}
func (cs *ClustersService) Get(ctx context.Context, org, id string) (Cluster, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s", org, id)
req, err := cs.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return Cluster{}, nil, err
}
var cluster Cluster
resp, err := cs.client.Do(req, &cluster)
if err != nil {
return Cluster{}, resp, err
}
return cluster, resp, err
}
func (cs *ClustersService) Create(ctx context.Context, org string, cc ClusterCreate) (Cluster, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters", org)
req, err := cs.client.NewRequest(ctx, "POST", u, cc)
if err != nil {
return Cluster{}, nil, err
}
var cluster Cluster
resp, err := cs.client.Do(req, &cluster)
if err != nil {
return Cluster{}, resp, err
}
return cluster, resp, err
}
func (cs *ClustersService) Update(ctx context.Context, org, id string, cu ClusterUpdate) (Cluster, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s", org, id)
req, err := cs.client.NewRequest(ctx, "PATCH", u, cu)
if err != nil {
return Cluster{}, nil, nil
}
var cluster Cluster
resp, err := cs.client.Do(req, &cluster)
if err != nil {
return Cluster{}, resp, err
}
return cluster, resp, err
}
func (cs *ClustersService) Delete(ctx context.Context, org, id string) (*Response, error) {
u := fmt.Sprintf("v2/organizations/%s/clusters/%s", org, id)
req, err := cs.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
return cs.client.Do(req, nil)
}