Debian Codegraph @

github/orgs.go

raw
1 // Copyright 2013 The go-github AUTHORS. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13 // OrganizationsService provides access to the organization related functions
14 // in the GitHub API.
15 //
16 // GitHub API docs: https://docs.github.com/rest/orgs/
17 type OrganizationsService service
18
19 // Organization represents a GitHub organization account.
20 type Organization struct {
21 Login *string `json:"login,omitempty"`
22 ID *int64 `json:"id,omitempty"`
23 NodeID *string `json:"node_id,omitempty"`
24 AvatarURL *string `json:"avatar_url,omitempty"`
25 HTMLURL *string `json:"html_url,omitempty"`
26 Name *string `json:"name,omitempty"`
27 Company *string `json:"company,omitempty"`
28 Blog *string `json:"blog,omitempty"`
29 Location *string `json:"location,omitempty"`
30 Email *string `json:"email,omitempty"`
31 TwitterUsername *string `json:"twitter_username,omitempty"`
32 Description *string `json:"description,omitempty"`
33 PublicRepos *int `json:"public_repos,omitempty"`
34 PublicGists *int `json:"public_gists,omitempty"`
35 Followers *int `json:"followers,omitempty"`
36 Following *int `json:"following,omitempty"`
37 CreatedAt *Timestamp `json:"created_at,omitempty"`
38 UpdatedAt *Timestamp `json:"updated_at,omitempty"`
39 TotalPrivateRepos *int64 `json:"total_private_repos,omitempty"`
40 OwnedPrivateRepos *int64 `json:"owned_private_repos,omitempty"`
41 PrivateGists *int `json:"private_gists,omitempty"`
42 DiskUsage *int `json:"disk_usage,omitempty"`
43 Collaborators *int `json:"collaborators,omitempty"`
44 BillingEmail *string `json:"billing_email,omitempty"`
45 Type *string `json:"type,omitempty"`
46 Plan *Plan `json:"plan,omitempty"`
47 TwoFactorRequirementEnabled *bool `json:"two_factor_requirement_enabled,omitempty"`
48 IsVerified *bool `json:"is_verified,omitempty"`
49 HasOrganizationProjects *bool `json:"has_organization_projects,omitempty"`
50 HasRepositoryProjects *bool `json:"has_repository_projects,omitempty"`
51
52 // DefaultRepoPermission can be one of: "read", "write", "admin", or "none". (Default: "read").
53 // It is only used in OrganizationsService.Edit.
54 DefaultRepoPermission *string `json:"default_repository_permission,omitempty"`
55 // DefaultRepoSettings can be one of: "read", "write", "admin", or "none". (Default: "read").
56 // It is only used in OrganizationsService.Get.
57 DefaultRepoSettings *string `json:"default_repository_settings,omitempty"`
58
59 // MembersCanCreateRepos default value is true and is only used in Organizations.Edit.
60 MembersCanCreateRepos *bool `json:"members_can_create_repositories,omitempty"`
61
62 // https://developer.github.com/changes/2019-12-03-internal-visibility-changes/#rest-v3-api
63 MembersCanCreatePublicRepos *bool `json:"members_can_create_public_repositories,omitempty"`
64 MembersCanCreatePrivateRepos *bool `json:"members_can_create_private_repositories,omitempty"`
65 MembersCanCreateInternalRepos *bool `json:"members_can_create_internal_repositories,omitempty"`
66
67 // MembersCanForkPrivateRepos toggles whether organization members can fork private organization repositories.
68 MembersCanForkPrivateRepos *bool `json:"members_can_fork_private_repositories,omitempty"`
69
70 // MembersAllowedRepositoryCreationType denotes if organization members can create repositories
71 // and the type of repositories they can create. Possible values are: "all", "private", or "none".
72 //
73 // Deprecated: Use MembersCanCreatePublicRepos, MembersCanCreatePrivateRepos, MembersCanCreateInternalRepos
74 // instead. The new fields overrides the existing MembersAllowedRepositoryCreationType during 'edit'
75 // operation and does not consider 'internal' repositories during 'get' operation
76 MembersAllowedRepositoryCreationType *string `json:"members_allowed_repository_creation_type,omitempty"`
77
78 // MembersCanCreatePages toggles whether organization members can create GitHub Pages sites.
79 MembersCanCreatePages *bool `json:"members_can_create_pages,omitempty"`
80 // MembersCanCreatePublicPages toggles whether organization members can create public GitHub Pages sites.
81 MembersCanCreatePublicPages *bool `json:"members_can_create_public_pages,omitempty"`
82 // MembersCanCreatePrivatePages toggles whether organization members can create private GitHub Pages sites.
83 MembersCanCreatePrivatePages *bool `json:"members_can_create_private_pages,omitempty"`
84 // WebCommitSignoffRequire toggles
85 WebCommitSignoffRequired *bool `json:"web_commit_signoff_required,omitempty"`
86 // AdvancedSecurityAuditLogEnabled toggles whether the advanced security audit log is enabled.
87 AdvancedSecurityEnabledForNewRepos *bool `json:"advanced_security_enabled_for_new_repositories,omitempty"`
88 // DependabotAlertsEnabled toggles whether dependabot alerts are enabled.
89 DependabotAlertsEnabledForNewRepos *bool `json:"dependabot_alerts_enabled_for_new_repositories,omitempty"`
90 // DependabotSecurityUpdatesEnabled toggles whether dependabot security updates are enabled.
91 DependabotSecurityUpdatesEnabledForNewRepos *bool `json:"dependabot_security_updates_enabled_for_new_repositories,omitempty"`
92 // DependabotGraphEnabledForNewRepos toggles whether dependabot graph is enabled on new repositories.
93 DependencyGraphEnabledForNewRepos *bool `json:"dependency_graph_enabled_for_new_repositories,omitempty"`
94 // SecretScanningEnabled toggles whether secret scanning is enabled on new repositories.
95 SecretScanningEnabledForNewRepos *bool `json:"secret_scanning_enabled_for_new_repositories,omitempty"`
96 // SecretScanningPushProtectionEnabledForNewRepos toggles whether secret scanning push protection is enabled on new repositories.
97 SecretScanningPushProtectionEnabledForNewRepos *bool `json:"secret_scanning_push_protection_enabled_for_new_repositories,omitempty"`
98 // SecretScanningValidityChecksEnabled toggles whether secret scanning validity check is enabled.
99 SecretScanningValidityChecksEnabled *bool `json:"secret_scanning_validity_checks_enabled,omitempty"`
100
101 // API URLs
102 URL *string `json:"url,omitempty"`
103 EventsURL *string `json:"events_url,omitempty"`
104 HooksURL *string `json:"hooks_url,omitempty"`
105 IssuesURL *string `json:"issues_url,omitempty"`
106 MembersURL *string `json:"members_url,omitempty"`
107 PublicMembersURL *string `json:"public_members_url,omitempty"`
108 ReposURL *string `json:"repos_url,omitempty"`
109 }
110
111 // OrganizationInstallations represents GitHub app installations for an organization.
112 type OrganizationInstallations struct {
113 TotalCount *int `json:"total_count,omitempty"`
114 Installations []*Installation `json:"installations,omitempty"`
115 }
116
117 func (o Organization) String() string {
118 return Stringify(o)
119 }
120
121 // Plan represents the payment plan for an account. See plans at https://github.com/plans.
122 type Plan struct {
123 Name *string `json:"name,omitempty"`
124 Space *int `json:"space,omitempty"`
125 Collaborators *int `json:"collaborators,omitempty"`
126 PrivateRepos *int64 `json:"private_repos,omitempty"`
127 FilledSeats *int `json:"filled_seats,omitempty"`
128 Seats *int `json:"seats,omitempty"`
129 }
130
131 func (p Plan) String() string {
132 return Stringify(p)
133 }
134
135 // OrganizationsListOptions specifies the optional parameters to the
136 // OrganizationsService.ListAll method.
137 type OrganizationsListOptions struct {
138 // Since filters Organizations by ID.
139 Since int64 `url:"since,omitempty"`
140
141 // Note: Pagination is powered exclusively by the Since parameter,
142 // ListOptions.Page has no effect.
143 // ListOptions.PerPage controls an undocumented GitHub API parameter.
144 ListOptions
145 }
146
147 // ListAll lists all organizations, in the order that they were created on GitHub.
148 //
149 // Note: Pagination is powered exclusively by the since parameter. To continue
150 // listing the next set of organizations, use the ID of the last-returned organization
151 // as the opts.Since parameter for the next call.
152 //
153 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#list-organizations
154 //
155 //meta:operation GET /organizations
156 func (s *OrganizationsService) ListAll(ctx context.Context, opts *OrganizationsListOptions) ([]*Organization, *Response, error) {
157 u, err := addOptions("organizations", opts)
158 if err != nil {
159 return nil, nil, err
160 }
161
162 req, err := s.client.NewRequest("GET", u, nil)
163 if err != nil {
164 return nil, nil, err
165 }
166
167 orgs := []*Organization{}
168 resp, err := s.client.Do(ctx, req, &orgs)
169 if err != nil {
170 return nil, resp, err
171 }
172 return orgs, resp, nil
173 }
174
175 // List the organizations for a user. Passing the empty string will list
176 // organizations for the authenticated user.
177 //
178 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#list-organizations-for-a-user
179 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#list-organizations-for-the-authenticated-user
180 //
181 //meta:operation GET /user/orgs
182 //meta:operation GET /users/{username}/orgs
183 func (s *OrganizationsService) List(ctx context.Context, user string, opts *ListOptions) ([]*Organization, *Response, error) {
184 var u string
185 if user != "" {
186 u = fmt.Sprintf("users/%v/orgs", user)
187 } else {
188 u = "user/orgs"
189 }
190 u, err := addOptions(u, opts)
191 if err != nil {
192 return nil, nil, err
193 }
194
195 req, err := s.client.NewRequest("GET", u, nil)
196 if err != nil {
197 return nil, nil, err
198 }
199
200 var orgs []*Organization
201 resp, err := s.client.Do(ctx, req, &orgs)
202 if err != nil {
203 return nil, resp, err
204 }
205
206 return orgs, resp, nil
207 }
208
209 // Get fetches an organization by name.
210 //
211 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#get-an-organization
212 //
213 //meta:operation GET /orgs/{org}
214 func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organization, *Response, error) {
215 u := fmt.Sprintf("orgs/%v", org)
216 req, err := s.client.NewRequest("GET", u, nil)
217 if err != nil {
218 return nil, nil, err
219 }
220
221 // TODO: remove custom Accept header when this API fully launches.
222 req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview)
223
224 organization := new(Organization)
225 resp, err := s.client.Do(ctx, req, organization)
226 if err != nil {
227 return nil, resp, err
228 }
229
230 return organization, resp, nil
231 }
232
233 // GetByID fetches an organization.
234 //
235 // Note: GetByID uses the undocumented GitHub API endpoint "GET /organizations/{organization_id}".
236 //
237 //meta:operation GET /organizations/{organization_id}
238 func (s *OrganizationsService) GetByID(ctx context.Context, id int64) (*Organization, *Response, error) {
239 u := fmt.Sprintf("organizations/%d", id)
240 req, err := s.client.NewRequest("GET", u, nil)
241 if err != nil {
242 return nil, nil, err
243 }
244
245 organization := new(Organization)
246 resp, err := s.client.Do(ctx, req, organization)
247 if err != nil {
248 return nil, resp, err
249 }
250
251 return organization, resp, nil
252 }
253
254 // Edit an organization.
255 //
256 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#update-an-organization
257 //
258 //meta:operation PATCH /orgs/{org}
259 func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organization) (*Organization, *Response, error) {
260 u := fmt.Sprintf("orgs/%v", name)
261 req, err := s.client.NewRequest("PATCH", u, org)
262 if err != nil {
263 return nil, nil, err
264 }
265
266 // TODO: remove custom Accept header when this API fully launches.
267 req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview)
268
269 o := new(Organization)
270 resp, err := s.client.Do(ctx, req, o)
271 if err != nil {
272 return nil, resp, err
273 }
274
275 return o, resp, nil
276 }
277
278 // Delete an organization by name.
279 //
280 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#delete-an-organization
281 //
282 //meta:operation DELETE /orgs/{org}
283 func (s *OrganizationsService) Delete(ctx context.Context, org string) (*Response, error) {
284 u := fmt.Sprintf("orgs/%v", org)
285 req, err := s.client.NewRequest("DELETE", u, nil)
286 if err != nil {
287 return nil, err
288 }
289
290 return s.client.Do(ctx, req, nil)
291 }
292
293 // ListInstallations lists installations for an organization.
294 //
295 // GitHub API docs: https://docs.github.com/rest/orgs/orgs#list-app-installations-for-an-organization
296 //
297 //meta:operation GET /orgs/{org}/installations
298 func (s *OrganizationsService) ListInstallations(ctx context.Context, org string, opts *ListOptions) (*OrganizationInstallations, *Response, error) {
299 u := fmt.Sprintf("orgs/%v/installations", org)
300
301 u, err := addOptions(u, opts)
302 if err != nil {
303 return nil, nil, err
304 }
305
306 req, err := s.client.NewRequest("GET", u, nil)
307 if err != nil {
308 return nil, nil, err
309 }
310
311 result := new(OrganizationInstallations)
312 resp, err := s.client.Do(ctx, req, result)
313 if err != nil {
314 return nil, resp, err
315 }
316
317 return result, resp, nil
318 }