-
Notifications
You must be signed in to change notification settings - Fork 59
/
team_member.go
126 lines (101 loc) · 3.4 KB
/
team_member.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
package buildkite
import (
"context"
"fmt"
)
// TeamMemberService handles communication with the teams related
// methods of the buildkite API.
//
// buildkite API docs: https://buildkite.com/docs/api
type TeamMemberService struct {
client *Client
}
// TeamMember represents a member of a team.
type TeamMember struct {
ID string `json:"user_id,omitempty"`
UserName string `json:"user_name,omitempty"`
Role string `json:"role,omitempty"`
CreatedAt Timestamp `json:"created_at,omitempty"`
}
// CreateTeamMember represents a request to create a team member.
type CreateTeamMember struct {
UserID string `json:"user_id,omitempty"`
Role string `json:"role,omitempty"`
}
// TeamMembersListOptions specifies the optional parameters to the ListTeamMembers method.
type TeamMembersListOptions struct {
ListOptions
}
// ListTeamMembers lists the members of a team.
func (ts *TeamMemberService) ListTeamMembers(ctx context.Context, org string, id string, opt *TeamMembersListOptions) ([]TeamMember, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/members", org, id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := ts.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var teamMembers []TeamMember
resp, err := ts.client.Do(req, &teamMembers)
if err != nil {
return nil, resp, err
}
return teamMembers, resp, err
}
// GetTeamMember gets a team member.
func (ts *TeamMemberService) GetTeamMember(ctx context.Context, org string, teamID string, userID string) (TeamMember, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/members/%s", org, teamID, userID)
req, err := ts.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return TeamMember{}, err
}
var teamMember TeamMember
_, err = ts.client.Do(req, &teamMember)
if err != nil {
return teamMember, err
}
return teamMember, err
}
// CreateTeamMember creates a team member.
func (ts *TeamMemberService) CreateTeamMember(ctx context.Context, org string, teamID string, t CreateTeamMember) (TeamMember, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/members", org, teamID)
req, err := ts.client.NewRequest(ctx, "POST", u, t)
if err != nil {
return TeamMember{}, nil, err
}
var teamMember TeamMember
resp, err := ts.client.Do(req, &teamMember)
if err != nil {
return teamMember, resp, err
}
return teamMember, resp, err
}
// UpdateTeamMember updates a team member.
func (ts *TeamMemberService) UpdateTeamMember(ctx context.Context, org string, teamID string, userID string, role string) (TeamMember, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/members/%s", org, teamID, userID)
req, err := ts.client.NewRequest(ctx, "PATCH", u, map[string]string{"role": role})
if err != nil {
return TeamMember{}, nil, err
}
var teamMember TeamMember
resp, err := ts.client.Do(req, &teamMember)
if err != nil {
return teamMember, resp, err
}
return teamMember, resp, err
}
// DeleteTeamMember deletes a team member.
func (ts *TeamMemberService) DeleteTeamMember(ctx context.Context, org string, teamID string, userID string) (*Response, error) {
u := fmt.Sprintf("v2/organizations/%s/teams/%s/members/%s", org, teamID, userID)
req, err := ts.client.NewRequest(ctx, "DELETE", u, nil)
if err != nil {
return nil, err
}
resp, err := ts.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}