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