github.com/google/go-github/v57@v57.0.0/github/actions_permissions_orgs.go (about) 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 // GetActionsPermissions gets the GitHub Actions permissions policy for repositories and allowed actions in an organization. 46 // 47 // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-github-actions-permissions-for-an-organization 48 // 49 //meta:operation GET /orgs/{org}/actions/permissions 50 func (s *ActionsService) GetActionsPermissions(ctx context.Context, org string) (*ActionsPermissions, *Response, error) { 51 u := fmt.Sprintf("orgs/%v/actions/permissions", org) 52 53 req, err := s.client.NewRequest("GET", u, nil) 54 if err != nil { 55 return nil, nil, err 56 } 57 58 permissions := new(ActionsPermissions) 59 resp, err := s.client.Do(ctx, req, permissions) 60 if err != nil { 61 return nil, resp, err 62 } 63 64 return permissions, resp, nil 65 } 66 67 // EditActionsPermissions sets the permissions policy for repositories and allowed actions in an organization. 68 // 69 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-github-actions-permissions-for-an-organization 70 // 71 //meta:operation PUT /orgs/{org}/actions/permissions 72 func (s *ActionsService) EditActionsPermissions(ctx context.Context, org string, actionsPermissions ActionsPermissions) (*ActionsPermissions, *Response, error) { 73 u := fmt.Sprintf("orgs/%v/actions/permissions", org) 74 req, err := s.client.NewRequest("PUT", u, actionsPermissions) 75 if err != nil { 76 return nil, nil, err 77 } 78 79 p := new(ActionsPermissions) 80 resp, err := s.client.Do(ctx, req, p) 81 if err != nil { 82 return nil, resp, err 83 } 84 85 return p, resp, nil 86 } 87 88 // ListEnabledReposInOrg lists the selected repositories that are enabled for GitHub Actions in an organization. 89 // 90 // GitHub API docs: https://docs.github.com/rest/actions/permissions#list-selected-repositories-enabled-for-github-actions-in-an-organization 91 // 92 //meta:operation GET /orgs/{org}/actions/permissions/repositories 93 func (s *ActionsService) ListEnabledReposInOrg(ctx context.Context, owner string, opts *ListOptions) (*ActionsEnabledOnOrgRepos, *Response, error) { 94 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner) 95 u, err := addOptions(u, opts) 96 if err != nil { 97 return nil, nil, err 98 } 99 100 req, err := s.client.NewRequest("GET", u, nil) 101 if err != nil { 102 return nil, nil, err 103 } 104 105 repos := &ActionsEnabledOnOrgRepos{} 106 resp, err := s.client.Do(ctx, req, repos) 107 if err != nil { 108 return nil, resp, err 109 } 110 111 return repos, resp, nil 112 } 113 114 // SetEnabledReposInOrg replaces the list of selected repositories that are enabled for GitHub Actions in an organization.. 115 // 116 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-selected-repositories-enabled-for-github-actions-in-an-organization 117 // 118 //meta:operation PUT /orgs/{org}/actions/permissions/repositories 119 func (s *ActionsService) SetEnabledReposInOrg(ctx context.Context, owner string, repositoryIDs []int64) (*Response, error) { 120 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories", owner) 121 122 req, err := s.client.NewRequest("PUT", u, struct { 123 IDs []int64 `json:"selected_repository_ids"` 124 }{IDs: repositoryIDs}) 125 if err != nil { 126 return nil, err 127 } 128 129 resp, err := s.client.Do(ctx, req, nil) 130 if err != nil { 131 return resp, err 132 } 133 134 return resp, nil 135 } 136 137 // AddEnabledReposInOrg adds a repository to the list of selected repositories that are enabled for GitHub Actions in an organization. 138 // 139 // GitHub API docs: https://docs.github.com/rest/actions/permissions#enable-a-selected-repository-for-github-actions-in-an-organization 140 // 141 //meta:operation PUT /orgs/{org}/actions/permissions/repositories/{repository_id} 142 func (s *ActionsService) AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) { 143 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID) 144 145 req, err := s.client.NewRequest("PUT", u, nil) 146 if err != nil { 147 return nil, err 148 } 149 150 resp, err := s.client.Do(ctx, req, nil) 151 if err != nil { 152 return resp, err 153 } 154 155 return resp, nil 156 } 157 158 // RemoveEnabledReposInOrg removes a single repository from the list of enabled repos for GitHub Actions in an organization. 159 // 160 // GitHub API docs: https://docs.github.com/rest/actions/permissions#disable-a-selected-repository-for-github-actions-in-an-organization 161 // 162 //meta:operation DELETE /orgs/{org}/actions/permissions/repositories/{repository_id} 163 func (s *ActionsService) RemoveEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*Response, error) { 164 u := fmt.Sprintf("orgs/%v/actions/permissions/repositories/%v", owner, repositoryID) 165 166 req, err := s.client.NewRequest("DELETE", u, nil) 167 if err != nil { 168 return nil, err 169 } 170 171 resp, err := s.client.Do(ctx, req, nil) 172 if err != nil { 173 return resp, err 174 } 175 176 return resp, nil 177 } 178 179 // GetActionsAllowed gets the actions that are allowed in an organization. 180 // 181 // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-allowed-actions-and-reusable-workflows-for-an-organization 182 // 183 //meta:operation GET /orgs/{org}/actions/permissions/selected-actions 184 func (s *ActionsService) GetActionsAllowed(ctx context.Context, org string) (*ActionsAllowed, *Response, error) { 185 u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org) 186 187 req, err := s.client.NewRequest("GET", u, nil) 188 if err != nil { 189 return nil, nil, err 190 } 191 192 actionsAllowed := new(ActionsAllowed) 193 resp, err := s.client.Do(ctx, req, actionsAllowed) 194 if err != nil { 195 return nil, resp, err 196 } 197 198 return actionsAllowed, resp, nil 199 } 200 201 // EditActionsAllowed sets the actions that are allowed in an organization. 202 // 203 // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-allowed-actions-and-reusable-workflows-for-an-organization 204 // 205 //meta:operation PUT /orgs/{org}/actions/permissions/selected-actions 206 func (s *ActionsService) EditActionsAllowed(ctx context.Context, org string, actionsAllowed ActionsAllowed) (*ActionsAllowed, *Response, error) { 207 u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org) 208 req, err := s.client.NewRequest("PUT", u, actionsAllowed) 209 if err != nil { 210 return nil, nil, err 211 } 212 213 p := new(ActionsAllowed) 214 resp, err := s.client.Do(ctx, req, p) 215 if err != nil { 216 return nil, resp, err 217 } 218 219 return p, resp, nil 220 }