-
Notifications
You must be signed in to change notification settings - Fork 59
/
organizations.go
76 lines (65 loc) · 2.2 KB
/
organizations.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
package buildkite
import (
"context"
"fmt"
)
// OrganizationsService handles communication with the organization related
// methods of the buildkite API.
//
// buildkite API docs: https://buildkite.com/docs/api/organizations
type OrganizationsService struct {
client *Client
}
// Organization represents a buildkite organization.
type Organization struct {
ID string `json:"id,omitempty"`
GraphQLID string `json:"graphql_id,omitempty"`
URL string `json:"url,omitempty"`
WebURL string `json:"web_url,omitempty"`
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
Repository string `json:"repository,omitempty"`
PipelinesURL string `json:"pipelines_url,omitempty"`
EmojisURL string `json:"emojis_url,omitempty"`
AgentsURL string `json:"agents_url,omitempty"`
CreatedAt *Timestamp `json:"created_at,omitempty"`
}
// OrganizationListOptions specifies the optional parameters to the
// OrganizationsService.List method.
type OrganizationListOptions struct{ ListOptions }
// List the organizations for the current user.
//
// buildkite API docs: https://buildkite.com/docs/api/organizations#list-organizations
func (os *OrganizationsService) List(ctx context.Context, opt *OrganizationListOptions) ([]Organization, *Response, error) {
u := "v2/organizations"
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := os.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return nil, nil, err
}
var orgs []Organization
resp, err := os.client.Do(req, &orgs)
if err != nil {
return nil, resp, err
}
return orgs, resp, err
}
// Get fetches an organization
//
// buildkite API docs: https://buildkite.com/docs/api/organizations#get-an-organization
func (os *OrganizationsService) Get(ctx context.Context, slug string) (Organization, *Response, error) {
u := fmt.Sprintf("v2/organizations/%s", slug)
req, err := os.client.NewRequest(ctx, "GET", u, nil)
if err != nil {
return Organization{}, nil, err
}
var organization Organization
resp, err := os.client.Do(req, &organization)
if err != nil {
return Organization{}, resp, err
}
return organization, resp, err
}