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