-
Notifications
You must be signed in to change notification settings - Fork 59
/
team_pipelines.go
123 lines (96 loc) · 3.17 KB
/
team_pipelines.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
package buildkite
import (
"context"
"fmt"
)
// TeamPipelinesService handles communication with the team pipelines related
// methods of the buildkite API.
//
// Buildkite API docs: https://buildkite.com/docs/apis/rest-api/teams/pipelines
type TeamPipelinesService struct {
client *Client
}
type TeamPipeline struct {
ID string `json:"pipeline_id,omitempty"`
URL string `json:"pipeline_url,omitempty"`
AccessLevel string `json:"access_level,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}
type CreateTeamPipelines struct {
PipelineID string `json:"pipeline_id,omitempty"`
AccessLevel string `json:"access_level,omitempty"`
}
type UpdateTeamPipelines struct {
AccessLevel string `json:"access_level,omitempty"`
}
type TeamPipelinesListOptions struct {
ListOptions
}
func (tps *TeamPipelinesService) List(ctx context.Context, org string, id string, opt *TeamPipelinesListOptions) ([]TeamPipeline, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/pipelines", org, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := tps.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var teamPipelines []TeamPipeline
resp, err := tps.client.Do(req, &teamPipelines)
if err != nil {
return nil, resp, err
}
return teamPipelines, resp, err
}
func (tps *TeamPipelinesService) Get(ctx context.Context, org string, teamID string, pipelineID string) (TeamPipeline, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/pipelines/%s", org, teamID, pipelineID)
req, err := tps.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return TeamPipeline{}, nil, err
}
var tp TeamPipeline
resp, err := tps.client.Do(req, &tp)
if err != nil {
return TeamPipeline{}, resp, err
}
return tp, resp, err
}
func (tps *TeamPipelinesService) Create(ctx context.Context, org string, teamID string, ctp CreateTeamPipelines) (TeamPipeline, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/pipelines", org, teamID)
req, err := tps.client.NewRequest(ctx, "POST", u, ctp)
if err != nil {
return TeamPipeline{}, nil, err
}
var tp TeamPipeline
resp, err := tps.client.Do(req, &tp)
if err != nil {
return tp, resp, err
}
return tp, resp, err
}
func (tps *TeamPipelinesService) Update(ctx context.Context, org string, teamID string, pipelineID string, utp UpdateTeamPipelines) (TeamPipeline, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/pipelines/%s", org, teamID, pipelineID)
req, err := tps.client.NewRequest(ctx, "PATCH", u, utp)
if err != nil {
return TeamPipeline{}, nil, err
}
var tp TeamPipeline
resp, err := tps.client.Do(req, &tp)
if err != nil {
return TeamPipeline{}, resp, err
}
return tp, resp, err
}
func (tps *TeamPipelinesService) Delete(ctx context.Context, org string, teamID string, pipelineID string) (*Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/pipelines/%s", org, teamID, pipelineID)
req, err := tps.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
resp, err := tps.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}