1 // Copyright 2017 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 // ListOutsideCollaboratorsOptions specifies optional parameters to the 14 // OrganizationsService.ListOutsideCollaborators method. 15 type ListOutsideCollaboratorsOptions struct { 16 // Filter outside collaborators returned in the list. Possible values are: 17 // 2fa_disabled, all. Default is "all". 18 Filter string `url:"filter,omitempty"` 19 20 ListOptions 21 } 22 23 // ListOutsideCollaborators lists outside collaborators of organization's repositories. 24 // This will only work if the authenticated 25 // user is an owner of the organization. 26 // 27 // Warning: The API may change without advance notice during the preview period. 28 // Preview features are not supported for production use. 29 // 30 // GitHub API docs: https://docs.github.com/en/rest/orgs/outside-collaborators#list-outside-collaborators-for-an-organization 31 func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org string, opts *ListOutsideCollaboratorsOptions) ([]*User, *Response, error) { 32 u := fmt.Sprintf("orgs/%v/outside_collaborators", org) 33 u, err := addOptions(u, opts) 34 if err != nil { 35 return nil, nil, err 36 } 37 38 req, err := s.client.NewRequest("GET", u, nil) 39 if err != nil { 40 return nil, nil, err 41 } 42 43 var members []*User 44 resp, err := s.client.Do(ctx, req, &members) 45 if err != nil { 46 return nil, resp, err 47 } 48 49 return members, resp, nil 50 } 51 52 // RemoveOutsideCollaborator removes a user from the list of outside collaborators; 53 // consequently, removing them from all the organization's repositories. 54 // 55 // GitHub API docs: https://docs.github.com/en/rest/orgs/outside-collaborators#remove-outside-collaborator-from-an-organization 56 func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) { 57 u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user) 58 req, err := s.client.NewRequest("DELETE", u, nil) 59 if err != nil { 60 return nil, err 61 } 62 63 return s.client.Do(ctx, req, nil) 64 } 65 66 // ConvertMemberToOutsideCollaborator reduces the permission level of a member of the 67 // organization to that of an outside collaborator. Therefore, they will only 68 // have access to the repositories that their current team membership allows. 69 // Responses for converting a non-member or the last owner to an outside collaborator 70 // are listed in GitHub API docs. 71 // 72 // GitHub API docs: https://docs.github.com/en/rest/orgs/outside-collaborators#convert-an-organization-member-to-outside-collaborator 73 func (s *OrganizationsService) ConvertMemberToOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) { 74 u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user) 75 req, err := s.client.NewRequest("PUT", u, nil) 76 if err != nil { 77 return nil, err 78 } 79 80 return s.client.Do(ctx, req, nil) 81 } 82