mirror of
https://github.com/google/go-github.git
synced 2026-10-28 16:34:37 +08:00
BREAKING CHANGE: All internal calls now provide `Context` via the `Request` itself.
88 lines
3.1 KiB
Go
88 lines
3.1 KiB
Go
// Copyright 2017 The go-github AUTHORS. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package github
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// ListOutsideCollaboratorsOptions specifies optional parameters to the
|
|
// OrganizationsService.ListOutsideCollaborators method.
|
|
type ListOutsideCollaboratorsOptions struct {
|
|
// Filter outside collaborators returned in the list. Possible values are:
|
|
// 2fa_disabled, all. Default is "all".
|
|
Filter string `url:"filter,omitempty"`
|
|
|
|
ListOptions
|
|
}
|
|
|
|
// ListOutsideCollaborators lists outside collaborators of organization's repositories.
|
|
// This will only work if the authenticated
|
|
// user is an owner of the organization.
|
|
//
|
|
// Warning: The API may change without advance notice during the preview period.
|
|
// Preview features are not supported for production use.
|
|
//
|
|
// GitHub API docs: https://docs.github.com/rest/orgs/outside-collaborators?apiVersion=2022-11-28#list-outside-collaborators-for-an-organization
|
|
//
|
|
//meta:operation GET /orgs/{org}/outside_collaborators
|
|
func (s *OrganizationsService) ListOutsideCollaborators(ctx context.Context, org string, opts *ListOutsideCollaboratorsOptions) ([]*User, *Response, error) {
|
|
u := fmt.Sprintf("orgs/%v/outside_collaborators", org)
|
|
u, err := addOptions(u, opts)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
req, err := s.client.NewRequest(ctx, "GET", u, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
var members []*User
|
|
resp, err := s.client.Do(req, &members)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return members, resp, nil
|
|
}
|
|
|
|
// RemoveOutsideCollaborator removes a user from the list of outside collaborators;
|
|
// consequently, removing them from all the organization's repositories.
|
|
//
|
|
// GitHub API docs: https://docs.github.com/rest/orgs/outside-collaborators?apiVersion=2022-11-28#remove-outside-collaborator-from-an-organization
|
|
//
|
|
//meta:operation DELETE /orgs/{org}/outside_collaborators/{username}
|
|
func (s *OrganizationsService) RemoveOutsideCollaborator(ctx context.Context, org, user string) (*Response, error) {
|
|
u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user)
|
|
req, err := s.client.NewRequest(ctx, "DELETE", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return s.client.Do(req, nil)
|
|
}
|
|
|
|
// ConvertMemberToOutsideCollaborator reduces the permission level of a member of the
|
|
// organization to that of an outside collaborator. Therefore, they will only
|
|
// have access to the repositories that their current team membership allows.
|
|
// Responses for converting a non-member or the last owner to an outside collaborator
|
|
// are listed in GitHub API docs.
|
|
//
|
|
// GitHub API docs: https://docs.github.com/rest/orgs/outside-collaborators?apiVersion=2022-11-28#convert-an-organization-member-to-outside-collaborator
|
|
//
|
|
//meta:operation PUT /orgs/{org}/outside_collaborators/{username}
|
|
func (s *OrganizationsService) ConvertMemberToOutsideCollaborator(ctx context.Context, org, user string) (*Response, error) {
|
|
u := fmt.Sprintf("orgs/%v/outside_collaborators/%v", org, user)
|
|
req, err := s.client.NewRequest(ctx, "PUT", u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return s.client.Do(req, nil)
|
|
}
|