Debian Codegraph @

github/orgs_outside_collaborators.go

raw
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/rest/orgs/outside-collaborators#list-outside-collaborators-for-an-organization
31 //
32 //meta:operation GET /orgs/{org}/outside_collaborators
33 func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org string, opts *ListOutsideCollaboratorsOptions) ([]*User, *Response, error) {
34 u := fmt.Sprintf("orgs/%v/outside_collaborators", org)
35 u, err := addOptions(u, opts)
36 if err != nil {
37 return nil, nil, err
38 }
39
40 req, err := s.client.NewRequest("GET", u, nil)
41 if err != nil {
42 return nil, nil, err
43 }
44
45 var members []*User
46 resp, err := s.client.Do(ctx, req, &members)
47 if err != nil {
48 return nil, resp, err
49 }
50
51 return members, resp, nil
52 }
53
54 // RemoveOutsideCollaborator removes a user from the list of outside collaborators;
55 // consequently, removing them from all the organization's repositories.
56 //
57 // GitHub API docs: https://docs.github.com/rest/orgs/outside-collaborators#remove-outside-collaborator-from-an-organization
58 //
59 //meta:operation DELETE /orgs/{org}/outside_collaborators/{username}
60 func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) {
61 u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user)
62 req, err := s.client.NewRequest("DELETE", u, nil)
63 if err != nil {
64 return nil, err
65 }
66
67 return s.client.Do(ctx, req, nil)
68 }
69
70 // ConvertMemberToOutsideCollaborator reduces the permission level of a member of the
71 // organization to that of an outside collaborator. Therefore, they will only
72 // have access to the repositories that their current team membership allows.
73 // Responses for converting a non-member or the last owner to an outside collaborator
74 // are listed in GitHub API docs.
75 //
76 // GitHub API docs: https://docs.github.com/rest/orgs/outside-collaborators#convert-an-organization-member-to-outside-collaborator
77 //
78 //meta:operation PUT /orgs/{org}/outside_collaborators/{username}
79 func (s *OrganizationsService) ConvertMemberToOutsideCollaborator(ctx context.Context, org string, user string) (*Response, error) {
80 u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user)
81 req, err := s.client.NewRequest("PUT", u, nil)
82 if err != nil {
83 return nil, err
84 }
85
86 return s.client.Do(ctx, req, nil)
87 }