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 MembersCanForkPrivateRepos *bool `json:"members_can_fork_private_repositories,omitempty"`
70
71
72
73
74
75
76
77 MembersAllowedRepositoryCreationType *string `json:"members_allowed_repository_creation_type,omitempty"`
78
79
80 MembersCanCreatePages *bool `json:"members_can_create_pages,omitempty"`
81
82 MembersCanCreatePublicPages *bool `json:"members_can_create_public_pages,omitempty"`
83
84 MembersCanCreatePrivatePages *bool `json:"members_can_create_private_pages,omitempty"`
85
86 WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"`
87
88 AdvancedSecurityEnabledForNewRepos *bool `json:"advanced_security_enabled_for_new_repositories,omitempty"`
89
90 DependabotAlertsEnabledForNewRepos *bool `json:"dependabot_alerts_enabled_for_new_repositories,omitempty"`
91
92 DependabotSecurityUpdatesEnabledForNewRepos *bool `json:"dependabot_security_updates_enabled_for_new_repositories,omitempty"`
93
94 DependencyGraphEnabledForNewRepos *bool `json:"dependency_graph_enabled_for_new_repositories,omitempty"`
95
96 SecretScanningEnabledForNewRepos *bool `json:"secret_scanning_enabled_for_new_repositories,omitempty"`
97
98 SecretScanningPushProtectionEnabledForNewRepos *bool `json:"secret_scanning_push_protection_enabled_for_new_repositories,omitempty"`
99
100
101 URL *string `json:"url,omitempty"`
102 EventsURL *string `json:"events_url,omitempty"`
103 HooksURL *string `json:"hooks_url,omitempty"`
104 IssuesURL *string `json:"issues_url,omitempty"`
105 MembersURL *string `json:"members_url,omitempty"`
106 PublicMembersURL *string `json:"public_members_url,omitempty"`
107 ReposURL *string `json:"repos_url,omitempty"`
108 }
109
110
111 type OrganizationInstallations struct {
112 TotalCount *int `json:"total_count,omitempty"`
113 Installations []*Installation `json:"installations,omitempty"`
114 }
115
116 func (o Organization) String() string {
117 return Stringify(o)
118 }
119
120
121 type Plan struct {
122 Name *string `json:"name,omitempty"`
123 Space *int `json:"space,omitempty"`
124 Collaborators *int `json:"collaborators,omitempty"`
125 PrivateRepos *int `json:"private_repos,omitempty"`
126 FilledSeats *int `json:"filled_seats,omitempty"`
127 Seats *int `json:"seats,omitempty"`
128 }
129
130 func (p Plan) String() string {
131 return Stringify(p)
132 }
133
134
135
136 type OrganizationsListOptions struct {
137
138 Since int64 `url:"since,omitempty"`
139
140
141
142
143 ListOptions
144 }
145
146
147
148
149
150
151
152
153 func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsListOptions) ([]*Organization, *Response, error) {
154 u, err := addOptions("organizations", opts)
155 if err != nil {
156 return nil, nil, err
157 }
158
159 req, err := s.client.NewRequest("GET", u, nil)
160 if err != nil {
161 return nil, nil, err
162 }
163
164 orgs := []*Organization{}
165 resp, err := s.client.Do(ctx, req, &orgs)
166 if err != nil {
167 return nil, resp, err
168 }
169 return orgs, resp, nil
170 }
171
172
173
174
175
176
177 func (s *OrganizationsService) List(ctx context.Context, user string, opts *ListOptions) ([]*Organization, *Response, error) {
178 var u string
179 if user != "" {
180 u = fmt.Sprintf("users/%v/orgs", user)
181 } else {
182 u = "user/orgs"
183 }
184 u, err := addOptions(u, opts)
185 if err != nil {
186 return nil, nil, err
187 }
188
189 req, err := s.client.NewRequest("GET", u, nil)
190 if err != nil {
191 return nil, nil, err
192 }
193
194 var orgs []*Organization
195 resp, err := s.client.Do(ctx, req, &orgs)
196 if err != nil {
197 return nil, resp, err
198 }
199
200 return orgs, resp, nil
201 }
202
203
204
205
206 func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) {
207 u := fmt.Sprintf("orgs/%v", org)
208 req, err := s.client.NewRequest("GET", u, nil)
209 if err != nil {
210 return nil, nil, err
211 }
212
213
214 req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview)
215
216 organization := new(Organization)
217 resp, err := s.client.Do(ctx, req, organization)
218 if err != nil {
219 return nil, resp, err
220 }
221
222 return organization, resp, nil
223 }
224
225
226
227
228 func (s *OrganizationsService) GetByID(ctx context.Context, id int64) (*Organization, *Response, error) {
229 u := fmt.Sprintf("organizations/%d", id)
230 req, err := s.client.NewRequest("GET", u, nil)
231 if err != nil {
232 return nil, nil, err
233 }
234
235 organization := new(Organization)
236 resp, err := s.client.Do(ctx, req, organization)
237 if err != nil {
238 return nil, resp, err
239 }
240
241 return organization, resp, nil
242 }
243
244
245
246
247 func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) {
248 u := fmt.Sprintf("orgs/%v", name)
249 req, err := s.client.NewRequest("PATCH", u, org)
250 if err != nil {
251 return nil, nil, err
252 }
253
254
255 req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview)
256
257 o := new(Organization)
258 resp, err := s.client.Do(ctx, req, o)
259 if err != nil {
260 return nil, resp, err
261 }
262
263 return o, resp, nil
264 }
265
266
267
268
269 func (s *OrganizationsService) ListInstallations(ctx context.Context, org string, opts *ListOptions) (*OrganizationInstallations, *Response, error) {
270 u := fmt.Sprintf("orgs/%v/installations", org)
271
272 u, err := addOptions(u, opts)
273 if err != nil {
274 return nil, nil, err
275 }
276
277 req, err := s.client.NewRequest("GET", u, nil)
278 if err != nil {
279 return nil, nil, err
280 }
281
282 result := new(OrganizationInstallations)
283 resp, err := s.client.Do(ctx, req, result)
284 if err != nil {
285 return nil, resp, err
286 }
287
288 return result, resp, nil
289 }
290
View as plain text