github.com/google/go-github/v66@v66.0.0/github/repos_actions_allowed.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  // GetActionsAllowed gets the allowed actions and reusable workflows for a repository.
    14  //
    15  // GitHub API docs: https://docs.github.com/rest/actions/permissions#get-allowed-actions-and-reusable-workflows-for-a-repository
    16  //
    17  //meta:operation GET /repos/{owner}/{repo}/actions/permissions/selected-actions
    18  func (s *RepositoriesService) GetActionsAllowed(ctx context.Context, org, repo string) (*ActionsAllowed, *Response, error) {
    19  	u := fmt.Sprintf("repos/%v/%v/actions/permissions/selected-actions", org, repo)
    20  	req, err := s.client.NewRequest("GET", u, nil)
    21  	if err != nil {
    22  		return nil, nil, err
    23  	}
    24  
    25  	actionsAllowed := new(ActionsAllowed)
    26  	resp, err := s.client.Do(ctx, req, actionsAllowed)
    27  	if err != nil {
    28  		return nil, resp, err
    29  	}
    30  
    31  	return actionsAllowed, resp, nil
    32  }
    33  
    34  // EditActionsAllowed sets the allowed actions and reusable workflows for a repository.
    35  //
    36  // GitHub API docs: https://docs.github.com/rest/actions/permissions#set-allowed-actions-and-reusable-workflows-for-a-repository
    37  //
    38  //meta:operation PUT /repos/{owner}/{repo}/actions/permissions/selected-actions
    39  func (s *RepositoriesService) EditActionsAllowed(ctx context.Context, org, repo string, actionsAllowed ActionsAllowed) (*ActionsAllowed, *Response, error) {
    40  	u := fmt.Sprintf("repos/%v/%v/actions/permissions/selected-actions", org, repo)
    41  	req, err := s.client.NewRequest("PUT", u, actionsAllowed)
    42  	if err != nil {
    43  		return nil, nil, err
    44  	}
    45  
    46  	p := new(ActionsAllowed)
    47  	resp, err := s.client.Do(ctx, req, p)
    48  	if err != nil {
    49  		return nil, resp, err
    50  	}
    51  
    52  	return p, resp, nil
    53  }