github.com/google/go-github/v60@v60.0.0/github/repos_actions_access.go (about)

     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/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/rest/actions/permissions#get-the-level-of-access-for-workflows-outside-of-the-repository
    27  //
    28  //meta:operation GET /repos/{owner}/{repo}/actions/permissions/access
    29  func (s *RepositoriesService) GetActionsAccessLevel(ctx context.Context, owner, repo string) (*RepositoryActionsAccessLevel, *Response, error) {
    30  	u := fmt.Sprintf("repos/%v/%v/actions/permissions/access", owner, repo)
    31  	req, err := s.client.NewRequest("GET", u, nil)
    32  	if err != nil {
    33  		return nil, nil, err
    34  	}
    35  
    36  	raal := new(RepositoryActionsAccessLevel)
    37  	resp, err := s.client.Do(ctx, req, raal)
    38  	if err != nil {
    39  		return nil, resp, err
    40  	}
    41  
    42  	return raal, resp, nil
    43  }
    44  
    45  // EditActionsAccessLevel sets the level of access that workflows outside of the repository have
    46  // to actions and reusable workflows in the repository.
    47  //
    48  // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-the-level-of-access-for-workflows-outside-of-the-repository
    49  //
    50  //meta:operation PUT /repos/{owner}/{repo}/actions/permissions/access
    51  func (s *RepositoriesService) EditActionsAccessLevel(ctx context.Context, owner, repo string, repositoryActionsAccessLevel RepositoryActionsAccessLevel) (*Response, error) {
    52  	u := fmt.Sprintf("repos/%v/%v/actions/permissions/access", owner, repo)
    53  	req, err := s.client.NewRequest("PUT", u, repositoryActionsAccessLevel)
    54  	if err != nil {
    55  		return nil, err
    56  	}
    57  
    58  	return s.client.Do(ctx, req, nil)
    59  }