1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 "time"
12 )
13
14
15
16
17
18 type OrganizationsService service
19
20
21 type Organization struct {
22 Login *string `json:"login,omitempty"`
23 ID *int64 `json:"id,omitempty"`
24 NodeID *string `json:"node_id,omitempty"`
25 AvatarURL *string `json:"avatar_url,omitempty"`
26 HTMLURL *string `json:"html_url,omitempty"`
27 Name *string `json:"name,omitempty"`
28 Company *string `json:"company,omitempty"`
29 Blog *string `json:"blog,omitempty"`
30 Location *string `json:"location,omitempty"`
31 Email *string `json:"email,omitempty"`
32 TwitterUsername *string `json:"twitter_username,omitempty"`
33 Description *string `json:"description,omitempty"`
34 PublicRepos *int `json:"public_repos,omitempty"`
35 PublicGists *int `json:"public_gists,omitempty"`
36 Followers *int `json:"followers,omitempty"`
37 Following *int `json:"following,omitempty"`
38 CreatedAt *time.Time `json:"created_at,omitempty"`
39 UpdatedAt *time.Time `json:"updated_at,omitempty"`
40 TotalPrivateRepos *int `json:"total_private_repos,omitempty"`
41 OwnedPrivateRepos *int `json:"owned_private_repos,omitempty"`
42 PrivateGists *int `json:"private_gists,omitempty"`
43 DiskUsage *int `json:"disk_usage,omitempty"`
44 Collaborators *int `json:"collaborators,omitempty"`
45 BillingEmail *string `json:"billing_email,omitempty"`
46 Type *string `json:"type,omitempty"`
47 Plan *Plan `json:"plan,omitempty"`
48 TwoFactorRequirementEnabled *bool `json:"two_factor_requirement_enabled,omitempty"`
49 IsVerified *bool `json:"is_verified,omitempty"`
50 HasOrganizationProjects *bool `json:"has_organization_projects,omitempty"`
51 HasRepositoryProjects *bool `json:"has_repository_projects,omitempty"`
52
53
54
55 DefaultRepoPermission *string `json:"default_repository_permission,omitempty"`
56
57
58 DefaultRepoSettings *string `json:"default_repository_settings,omitempty"`
59
60
61 MembersCanCreateRepos *bool `json:"members_can_create_repositories,omitempty"`
62
63
64 MembersCanCreatePublicRepos *bool `json:"members_can_create_public_repositories,omitempty"`
65 MembersCanCreatePrivateRepos *bool `json:"members_can_create_private_repositories,omitempty"`
66 MembersCanCreateInternalRepos *bool `json:"members_can_create_internal_repositories,omitempty"`
67
68
69
70
71
72
73
74 MembersAllowedRepositoryCreationType *string `json:"members_allowed_repository_creation_type,omitempty"`
75
76
77 URL *string `json:"url,omitempty"`
78 EventsURL *string `json:"events_url,omitempty"`
79 HooksURL *string `json:"hooks_url,omitempty"`
80 IssuesURL *string `json:"issues_url,omitempty"`
81 MembersURL *string `json:"members_url,omitempty"`
82 PublicMembersURL *string `json:"public_members_url,omitempty"`
83 ReposURL *string `json:"repos_url,omitempty"`
84 }
85
86
87 type OrganizationInstallations struct {
88 TotalCount *int `json:"total_count,omitempty"`
89 Installations []*Installation `json:"installations,omitempty"`
90 }
91
92 func (o Organization) String() string {
93 return Stringify(o)
94 }
95
96
97 type Plan struct {
98 Name *string `json:"name,omitempty"`
99 Space *int `json:"space,omitempty"`
100 Collaborators *int `json:"collaborators,omitempty"`
101 PrivateRepos *int `json:"private_repos,omitempty"`
102 FilledSeats *int `json:"filled_seats,omitempty"`
103 Seats *int `json:"seats,omitempty"`
104 }
105
106 func (p Plan) String() string {
107 return Stringify(p)
108 }
109
110
111
112 type OrganizationsListOptions struct {
113
114 Since int64 `url:"since,omitempty"`
115
116
117
118
119 ListOptions
120 }
121
122
123
124
125
126
127
128
129 func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsListOptions) ([]*Organization, *Response, error) {
130 u, err := addOptions("organizations", opts)
131 if err != nil {
132 return nil, nil, err
133 }
134
135 req, err := s.client.NewRequest("GET", u, nil)
136 if err != nil {
137 return nil, nil, err
138 }
139
140 orgs := []*Organization{}
141 resp, err := s.client.Do(ctx, req, &orgs)
142 if err != nil {
143 return nil, resp, err
144 }
145 return orgs, resp, nil
146 }
147
148
149
150
151
152
153 func (s *OrganizationsService) List(ctx context.Context, user string, opts *ListOptions) ([]*Organization, *Response, error) {
154 var u string
155 if user != "" {
156 u = fmt.Sprintf("users/%v/orgs", user)
157 } else {
158 u = "user/orgs"
159 }
160 u, err := addOptions(u, opts)
161 if err != nil {
162 return nil, nil, err
163 }
164
165 req, err := s.client.NewRequest("GET", u, nil)
166 if err != nil {
167 return nil, nil, err
168 }
169
170 var orgs []*Organization
171 resp, err := s.client.Do(ctx, req, &orgs)
172 if err != nil {
173 return nil, resp, err
174 }
175
176 return orgs, resp, nil
177 }
178
179
180
181
182 func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) {
183 u := fmt.Sprintf("orgs/%v", org)
184 req, err := s.client.NewRequest("GET", u, nil)
185 if err != nil {
186 return nil, nil, err
187 }
188
189
190 req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview)
191
192 organization := new(Organization)
193 resp, err := s.client.Do(ctx, req, organization)
194 if err != nil {
195 return nil, resp, err
196 }
197
198 return organization, resp, nil
199 }
200
201
202
203
204 func (s *OrganizationsService) GetByID(ctx context.Context, id int64) (*Organization, *Response, error) {
205 u := fmt.Sprintf("organizations/%d", id)
206 req, err := s.client.NewRequest("GET", u, nil)
207 if err != nil {
208 return nil, nil, err
209 }
210
211 organization := new(Organization)
212 resp, err := s.client.Do(ctx, req, organization)
213 if err != nil {
214 return nil, resp, err
215 }
216
217 return organization, resp, nil
218 }
219
220
221
222
223 func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) {
224 u := fmt.Sprintf("orgs/%v", name)
225 req, err := s.client.NewRequest("PATCH", u, org)
226 if err != nil {
227 return nil, nil, err
228 }
229
230
231 req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview)
232
233 o := new(Organization)
234 resp, err := s.client.Do(ctx, req, o)
235 if err != nil {
236 return nil, resp, err
237 }
238
239 return o, resp, nil
240 }
241
242
243
244
245 func (s *OrganizationsService) ListInstallations(ctx context.Context, org string, opts *ListOptions) (*OrganizationInstallations, *Response, error) {
246 u := fmt.Sprintf("orgs/%v/installations", org)
247
248 u, err := addOptions(u, opts)
249 if err != nil {
250 return nil, nil, err
251 }
252
253 req, err := s.client.NewRequest("GET", u, nil)
254 if err != nil {
255 return nil, nil, err
256 }
257
258 result := new(OrganizationInstallations)
259 resp, err := s.client.Do(ctx, req, result)
260 if err != nil {
261 return nil, resp, err
262 }
263
264 return result, resp, nil
265 }
266
View as plain text