github.com/google/go-github/v68@v68.0.0/github/interactions_orgs.go (about) 1 // Copyright 2019 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 // GetRestrictionsForOrg fetches the interaction restrictions for an organization. 14 // 15 // GitHub API docs: https://docs.github.com/rest/interactions/orgs#get-interaction-restrictions-for-an-organization 16 // 17 //meta:operation GET /orgs/{org}/interaction-limits 18 func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organization string) (*InteractionRestriction, *Response, error) { 19 u := fmt.Sprintf("orgs/%v/interaction-limits", organization) 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 organizationInteractions := new(InteractionRestriction) 29 30 resp, err := s.client.Do(ctx, req, organizationInteractions) 31 if err != nil { 32 return nil, resp, err 33 } 34 35 return organizationInteractions, resp, nil 36 } 37 38 // UpdateRestrictionsForOrg adds or updates the interaction restrictions for an organization. 39 // 40 // limit specifies the group of GitHub users who can comment, open issues, or create pull requests 41 // in public repositories for the given organization. 42 // Possible values are: "existing_users", "contributors_only", "collaborators_only". 43 // 44 // GitHub API docs: https://docs.github.com/rest/interactions/orgs#set-interaction-restrictions-for-an-organization 45 // 46 //meta:operation PUT /orgs/{org}/interaction-limits 47 func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, organization, limit string) (*InteractionRestriction, *Response, error) { 48 u := fmt.Sprintf("orgs/%v/interaction-limits", organization) 49 50 interaction := &InteractionRestriction{Limit: Ptr(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 organizationInteractions := new(InteractionRestriction) 61 62 resp, err := s.client.Do(ctx, req, organizationInteractions) 63 if err != nil { 64 return nil, resp, err 65 } 66 67 return organizationInteractions, resp, nil 68 } 69 70 // RemoveRestrictionsFromOrg removes the interaction restrictions for an organization. 71 // 72 // GitHub API docs: https://docs.github.com/rest/interactions/orgs#remove-interaction-restrictions-for-an-organization 73 // 74 //meta:operation DELETE /orgs/{org}/interaction-limits 75 func (s *InteractionsService) RemoveRestrictionsFromOrg(ctx context.Context, organization string) (*Response, error) { 76 u := fmt.Sprintf("orgs/%v/interaction-limits", organization) 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 }