github.com/google/go-github/v65@v65.0.0/github/interactions_repos.go (about)

     1  // Copyright 2018 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  // GetRestrictionsForRepo fetches the interaction restrictions for a repository.
    14  //
    15  // GitHub API docs: https://docs.github.com/rest/interactions/repos#get-interaction-restrictions-for-a-repository
    16  //
    17  //meta:operation GET /repos/{owner}/{repo}/interaction-limits
    18  func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, repo string) (*InteractionRestriction, *Response, error) {
    19  	u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
    20  	req, err := s.client.NewRequest("GET", u, nil)
    21  	if err != nil {
    22  		return nil, nil, err
    23  	}
    24  
    25  	// TODO: remove custom Accept header when this API fully launches.
    26  	req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
    27  
    28  	repositoryInteractions := new(InteractionRestriction)
    29  
    30  	resp, err := s.client.Do(ctx, req, repositoryInteractions)
    31  	if err != nil {
    32  		return nil, resp, err
    33  	}
    34  
    35  	return repositoryInteractions, resp, nil
    36  }
    37  
    38  // UpdateRestrictionsForRepo adds or updates the interaction restrictions for a repository.
    39  //
    40  // limit specifies the group of GitHub users who can comment, open issues, or create pull requests
    41  // for the given repository.
    42  // Possible values are: "existing_users", "contributors_only", "collaborators_only".
    43  //
    44  // GitHub API docs: https://docs.github.com/rest/interactions/repos#set-interaction-restrictions-for-a-repository
    45  //
    46  //meta:operation PUT /repos/{owner}/{repo}/interaction-limits
    47  func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) {
    48  	u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
    49  
    50  	interaction := &InteractionRestriction{Limit: String(limit)}
    51  
    52  	req, err := s.client.NewRequest("PUT", u, interaction)
    53  	if err != nil {
    54  		return nil, nil, err
    55  	}
    56  
    57  	// TODO: remove custom Accept header when this API fully launches.
    58  	req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
    59  
    60  	repositoryInteractions := new(InteractionRestriction)
    61  
    62  	resp, err := s.client.Do(ctx, req, repositoryInteractions)
    63  	if err != nil {
    64  		return nil, resp, err
    65  	}
    66  
    67  	return repositoryInteractions, resp, nil
    68  }
    69  
    70  // RemoveRestrictionsFromRepo removes the interaction restrictions for a repository.
    71  //
    72  // GitHub API docs: https://docs.github.com/rest/interactions/repos#remove-interaction-restrictions-for-a-repository
    73  //
    74  //meta:operation DELETE /repos/{owner}/{repo}/interaction-limits
    75  func (s *InteractionsService) RemoveRestrictionsFromRepo(ctx context.Context, owner, repo string) (*Response, error) {
    76  	u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
    77  	req, err := s.client.NewRequest("DELETE", u, nil)
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  
    82  	// TODO: remove custom Accept header when this API fully launches.
    83  	req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
    84  
    85  	return s.client.Do(ctx, req, nil)
    86  }