Debian Codegraph @

github/actions_permissions_orgs.go

raw
1 // Copyright 2023 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 // ActionsPermissions represents a policy for repositories and allowed actions in an organization.
14 //
15 // GitHub API docs: https://docs.github.com/rest/actions/permissions
16 type ActionsPermissions struct {
17 EnabledRepositories *string `json:"enabled_repositories,omitempty"`
18 AllowedActions *string `json:"allowed_actions,omitempty"`
19 SelectedActionsURL *string `json:"selected_actions_url,omitempty"`
20 }
21
22 func (a ActionsPermissions) String() string {
23 return Stringify(a)
24 }
25
26 // ActionsEnabledOnOrgRepos represents all the repositories in an organization for which Actions is enabled.
27 type ActionsEnabledOnOrgRepos struct {
28 TotalCount int `json:"total_count"`
29 Repositories []*Repository `json:"repositories"`
30 }
31
32 // ActionsAllowed represents selected actions that are allowed.
33 //
34 // GitHub API docs: https://docs.github.com/rest/actions/permissions
35 type ActionsAllowed struct {
36 GithubOwnedAllowed *bool `json:"github_owned_allowed,omitempty"`
37 VerifiedAllowed *bool `json:"verified_allowed,omitempty"`
38 PatternsAllowed []string `json:"patterns_allowed,omitempty"`
39 }
40
41 func (a ActionsAllowed) String() string {
42 return Stringify(a)
43 }
44
45 // DefaultWorkflowPermissionOrganization represents the default permissions for GitHub Actions workflows for an organization.
46 //
47 // GitHub API docs: https://docs.github.com/rest/actions/permissions
48 type DefaultWorkflowPermissionOrganization struct {
49 DefaultWorkflowPermissions *string `json:"default_workflow_permissions,omitempty"`
50 CanApprovePullRequestReviews *bool `json:"can_approve_pull_request_reviews,omitempty"`
51 }
52
53 // GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in an organization.
54 //
55 // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-github-actions-permissions-for-an-organization
56 //
57 //meta:operation GET /orgs/{org}/actions/permissions
58 func (s *ActionsService) GetActionsPermissions(ctx context.Context, org string) (*ActionsPermissions, *Response, error) {
59 u := fmt.Sprintf("orgs/%v/actions/permissions", org)
60
61 req, err := s.client.NewRequest("GET", u, nil)
62 if err != nil {
63 return nil, nil, err
64 }
65
66 permissions := new(ActionsPermissions)
67 resp, err := s.client.Do(ctx, req, permissions)
68 if err != nil {
69 return nil, resp, err
70 }
71
72 return permissions, resp, nil
73 }
74
75 // EditActionsPermissions sets the permissions policy for repositories and allowed actions in an organization.
76 //
77 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-github-actions-permissions-for-an-organization
78 //
79 //meta:operation PUT /orgs/{org}/actions/permissions
80 func (s *ActionsService) EditActionsPermissions(ctx context.Context, org string, actionsPermissions ActionsPermissions) (*ActionsPermissions, *Response, error) {
81 u := fmt.Sprintf("orgs/%v/actions/permissions", org)
82 req, err := s.client.NewRequest("PUT", u, actionsPermissions)
83 if err != nil {
84 return nil, nil, err
85 }
86
87 p := new(ActionsPermissions)
88 resp, err := s.client.Do(ctx, req, p)
89 if err != nil {
90 return nil, resp, err
91 }
92
93 return p, resp, nil
94 }
95
96 // ListEnabledReposInOrg lists the selected repositories that are enabled for GitHub Actions in an organization.
97 //
98 // GitHub API docs: https://docs.github.com/rest/actions/permissions#list-selected-repositories-enabled-for-github-actions-in-an-organization
99 //
100 //meta:operation GET /orgs/{org}/actions/permissions/repositories
101 func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string, opts *ListOptions) (*ActionsEnabledOnOrgRepos, *Response, error) {
102 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
103 u, err := addOptions(u, opts)
104 if err != nil {
105 return nil, nil, err
106 }
107
108 req, err := s.client.NewRequest("GET", u, nil)
109 if err != nil {
110 return nil, nil, err
111 }
112
113 repos := &ActionsEnabledOnOrgRepos{}
114 resp, err := s.client.Do(ctx, req, repos)
115 if err != nil {
116 return nil, resp, err
117 }
118
119 return repos, resp, nil
120 }
121
122 // SetEnabledReposInOrg replaces the list of selected repositories that are enabled for GitHub Actions in an organization..
123 //
124 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-selected-repositories-enabled-for-github-actions-in-an-organization
125 //
126 //meta:operation PUT /orgs/{org}/actions/permissions/repositories
127 func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string, repositoryIDs []int64) (*Response, error) {
128 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner)
129
130 req, err := s.client.NewRequest("PUT", u, struct {
131 IDs []int64 `json:"selected_repository_ids"`
132 }{IDs: repositoryIDs})
133 if err != nil {
134 return nil, err
135 }
136
137 resp, err := s.client.Do(ctx, req, nil)
138 if err != nil {
139 return resp, err
140 }
141
142 return resp, nil
143 }
144
145 // AddEnabledReposInOrg adds a repository to the list of selected repositories that are enabled for GitHub Actions in an organization.
146 //
147 // GitHub API docs: https://docs.github.com/rest/actions/permissions#enable-a-selected-repository-for-github-actions-in-an-organization
148 //
149 //meta:operation PUT /orgs/{org}/actions/permissions/repositories/{repository_id}
150 func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
151 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
152
153 req, err := s.client.NewRequest("PUT", u, nil)
154 if err != nil {
155 return nil, err
156 }
157
158 resp, err := s.client.Do(ctx, req, nil)
159 if err != nil {
160 return resp, err
161 }
162
163 return resp, nil
164 }
165
166 // RemoveEnabledReposInOrg removes a single repository from the list of enabled repos for GitHub Actions in an organization.
167 //
168 // GitHub API docs: https://docs.github.com/rest/actions/permissions#disable-a-selected-repository-for-github-actions-in-an-organization
169 //
170 //meta:operation DELETE /orgs/{org}/actions/permissions/repositories/{repository_id}
171 func (s *ActionsService) RemoveEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) {
172 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID)
173
174 req, err := s.client.NewRequest("DELETE", u, nil)
175 if err != nil {
176 return nil, err
177 }
178
179 resp, err := s.client.Do(ctx, req, nil)
180 if err != nil {
181 return resp, err
182 }
183
184 return resp, nil
185 }
186
187 // GetActionsAllowed gets the actions that are allowed in an organization.
188 //
189 // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-allowed-actions-and-reusable-workflows-for-an-organization
190 //
191 //meta:operation GET /orgs/{org}/actions/permissions/selected-actions
192 func (s *ActionsService) GetActionsAllowed(ctx context.Context, org string) (*ActionsAllowed, *Response, error) {
193 u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org)
194
195 req, err := s.client.NewRequest("GET", u, nil)
196 if err != nil {
197 return nil, nil, err
198 }
199
200 actionsAllowed := new(ActionsAllowed)
201 resp, err := s.client.Do(ctx, req, actionsAllowed)
202 if err != nil {
203 return nil, resp, err
204 }
205
206 return actionsAllowed, resp, nil
207 }
208
209 // EditActionsAllowed sets the actions that are allowed in an organization.
210 //
211 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-allowed-actions-and-reusable-workflows-for-an-organization
212 //
213 //meta:operation PUT /orgs/{org}/actions/permissions/selected-actions
214 func (s *ActionsService) EditActionsAllowed(ctx context.Context, org string, actionsAllowed ActionsAllowed) (*ActionsAllowed, *Response, error) {
215 u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org)
216 req, err := s.client.NewRequest("PUT", u, actionsAllowed)
217 if err != nil {
218 return nil, nil, err
219 }
220
221 p := new(ActionsAllowed)
222 resp, err := s.client.Do(ctx, req, p)
223 if err != nil {
224 return nil, resp, err
225 }
226
227 return p, resp, nil
228 }
229
230 // GetDefaultWorkflowPermissionsInOrganization gets the GitHub Actions default workflow permissions for an organization.
231 //
232 // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-default-workflow-permissions-for-an-organization
233 //
234 //meta:operation GET /orgs/{org}/actions/permissions/workflow
235 func (s *ActionsService) GetDefaultWorkflowPermissionsInOrganization(ctx context.Context, org string) (*DefaultWorkflowPermissionOrganization, *Response, error) {
236 u := fmt.Sprintf("orgs/%v/actions/permissions/workflow", org)
237
238 req, err := s.client.NewRequest("GET", u, nil)
239 if err != nil {
240 return nil, nil, err
241 }
242
243 permissions := new(DefaultWorkflowPermissionOrganization)
244 resp, err := s.client.Do(ctx, req, permissions)
245 if err != nil {
246 return nil, resp, err
247 }
248
249 return permissions, resp, nil
250 }
251
252 // EditDefaultWorkflowPermissionsInOrganization sets the GitHub Actions default workflow permissions for an organization.
253 //
254 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-default-workflow-permissions-for-an-organization
255 //
256 //meta:operation PUT /orgs/{org}/actions/permissions/workflow
257 func (s *ActionsService) EditDefaultWorkflowPermissionsInOrganization(ctx context.Context, org string, permissions DefaultWorkflowPermissionOrganization) (*DefaultWorkflowPermissionOrganization, *Response, error) {
258 u := fmt.Sprintf("orgs/%v/actions/permissions/workflow", org)
259 req, err := s.client.NewRequest("PUT", u, permissions)
260 if err != nil {
261 return nil, nil, err
262 }
263
264 p := new(DefaultWorkflowPermissionOrganization)
265 resp, err := s.client.Do(ctx, req, p)
266 if err != nil {
267 return nil, resp, err
268 }
269
270 return p, resp, nil
271 }