...

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

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

     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/en/rest/interactions/orgs#get-interaction-restrictions-for-an-organization
    16  func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organization string) (*InteractionRestriction, *Response, error) {
    17  	u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
    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  	organizationInteractions := new(InteractionRestriction)
    27  
    28  	resp, err := s.client.Do(ctx, req, organizationInteractions)
    29  	if err != nil {
    30  		return nil, resp, err
    31  	}
    32  
    33  	return organizationInteractions, resp, nil
    34  }
    35  
    36  // UpdateRestrictionsForOrg adds or updates the interaction restrictions for an organization.
    37  //
    38  // limit specifies the group of GitHub users who can comment, open issues, or create pull requests
    39  // in public repositories for the given organization.
    40  // Possible values are: "existing_users", "contributors_only", "collaborators_only".
    41  //
    42  // GitHub API docs: https://docs.github.com/en/rest/interactions/orgs#set-interaction-restrictions-for-an-organization
    43  func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, organization, limit string) (*InteractionRestriction, *Response, error) {
    44  	u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
    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  	organizationInteractions := new(InteractionRestriction)
    57  
    58  	resp, err := s.client.Do(ctx, req, organizationInteractions)
    59  	if err != nil {
    60  		return nil, resp, err
    61  	}
    62  
    63  	return organizationInteractions, resp, nil
    64  }
    65  
    66  // RemoveRestrictionsFromOrg removes the interaction restrictions for an organization.
    67  //
    68  // GitHub API docs: https://docs.github.com/en/rest/interactions/orgs#remove-interaction-restrictions-for-an-organization
    69  func (s *InteractionsService) RemoveRestrictionsFromOrg(ctx context.Context, organization string) (*Response, error) {
    70  	u := fmt.Sprintf("orgs/%v/interaction-limits", organization)
    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  }
    81  

View as plain text