...

Source file src/github.com/google/go-github/v55/github/orgs_actions_allowed.go

Documentation: github.com/google/go-github/v55/github

     1  // Copyright 2021 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  // ActionsAllowed represents selected actions that are allowed.
    14  //
    15  // GitHub API docs: https://docs.github.com/en/rest/actions/permissions
    16  type ActionsAllowed struct {
    17  	GithubOwnedAllowed *bool    `json:"github_owned_allowed,omitempty"`
    18  	VerifiedAllowed    *bool    `json:"verified_allowed,omitempty"`
    19  	PatternsAllowed    []string `json:"patterns_allowed,omitempty"`
    20  }
    21  
    22  func (a ActionsAllowed) String() string {
    23  	return Stringify(a)
    24  }
    25  
    26  // GetActionsAllowed gets the actions that are allowed in an organization.
    27  //
    28  // GitHub API docs: https://docs.github.com/en/rest/actions/permissions#get-allowed-actions-and-reusable-workflows-for-an-organization
    29  func (s *OrganizationsService) GetActionsAllowed(ctx context.Context, org string) (*ActionsAllowed, *Response, error) {
    30  	u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org)
    31  
    32  	req, err := s.client.NewRequest("GET", u, nil)
    33  	if err != nil {
    34  		return nil, nil, err
    35  	}
    36  
    37  	actionsAllowed := new(ActionsAllowed)
    38  	resp, err := s.client.Do(ctx, req, actionsAllowed)
    39  	if err != nil {
    40  		return nil, resp, err
    41  	}
    42  
    43  	return actionsAllowed, resp, nil
    44  }
    45  
    46  // EditActionsAllowed sets the actions that are allowed in an organization.
    47  //
    48  // GitHub API docs: https://docs.github.com/en/rest/actions/permissions#set-allowed-actions-and-reusable-workflows-for-an-organization
    49  func (s *OrganizationsService) EditActionsAllowed(ctx context.Context, org string, actionsAllowed ActionsAllowed) (*ActionsAllowed, *Response, error) {
    50  	u := fmt.Sprintf("orgs/%v/actions/permissions/selected-actions", org)
    51  	req, err := s.client.NewRequest("PUT", u, actionsAllowed)
    52  	if err != nil {
    53  		return nil, nil, err
    54  	}
    55  
    56  	p := new(ActionsAllowed)
    57  	resp, err := s.client.Do(ctx, req, p)
    58  	if err != nil {
    59  		return nil, resp, err
    60  	}
    61  
    62  	return p, resp, nil
    63  }
    64  

View as plain text