1 // Copyright 2022 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 // RepositoryActionsAccessLevel represents the repository actions access level. 14 // 15 // GitHub API docs: https://docs.github.com/en/rest/actions/permissions#set-the-level-of-access-for-workflows-outside-of-the-repository 16 type RepositoryActionsAccessLevel struct { 17 // AccessLevel specifies the level of access that workflows outside of the repository have 18 // to actions and reusable workflows within the repository. 19 // Possible values are: "none", "organization" "enterprise". 20 AccessLevel *string `json:"access_level,omitempty"` 21 } 22 23 // GetActionsAccessLevel gets the level of access that workflows outside of the repository have 24 // to actions and reusable workflows in the repository. 25 // 26 // GitHub API docs: https://docs.github.com/en/rest/actions/permissions#get-the-level-of-access-for-workflows-outside-of-the-repository 27 func (s *RepositoriesService) GetActionsAccessLevel(ctx context.Context, owner, repo string) (*RepositoryActionsAccessLevel, *Response, error) { 28 u := fmt.Sprintf("repos/%v/%v/actions/permissions/access", owner, repo) 29 req, err := s.client.NewRequest("GET", u, nil) 30 if err != nil { 31 return nil, nil, err 32 } 33 34 raal := new(RepositoryActionsAccessLevel) 35 resp, err := s.client.Do(ctx, req, raal) 36 if err != nil { 37 return nil, resp, err 38 } 39 40 return raal, resp, nil 41 } 42 43 // EditActionsAccessLevel sets the level of access that workflows outside of the repository have 44 // to actions and reusable workflows in the repository. 45 // 46 // GitHub API docs: https://docs.github.com/en/rest/actions/permissions#set-the-level-of-access-for-workflows-outside-of-the-repository 47 func (s *RepositoriesService) EditActionsAccessLevel(ctx context.Context, owner, repo string, repositoryActionsAccessLevel RepositoryActionsAccessLevel) (*Response, error) { 48 u := fmt.Sprintf("repos/%v/%v/actions/permissions/access", owner, repo) 49 req, err := s.client.NewRequest("PUT", u, repositoryActionsAccessLevel) 50 if err != nil { 51 return nil, err 52 } 53 54 return s.client.Do(ctx, req, nil) 55 } 56