You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

orgs_outside_collaborators.go 2.8KB

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