本站源代码
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.

73 lines
2.2KB

  1. // Copyright 2014 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. // PromoteSiteAdmin promotes a user to a site administrator of a GitHub Enterprise instance.
  11. //
  12. // GitHub API docs: https://developer.github.com/enterprise/v3/enterprise-admin/users/#promote-an-ordinary-user-to-a-site-administrator
  13. func (s *UsersService) PromoteSiteAdmin(ctx context.Context, user string) (*Response, error) {
  14. u := fmt.Sprintf("users/%v/site_admin", user)
  15. req, err := s.client.NewRequest("PUT", u, nil)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return s.client.Do(ctx, req, nil)
  20. }
  21. // DemoteSiteAdmin demotes a user from site administrator of a GitHub Enterprise instance.
  22. //
  23. // GitHub API docs: https://developer.github.com/enterprise/v3/enterprise-admin/users/#demote-a-site-administrator-to-an-ordinary-user
  24. func (s *UsersService) DemoteSiteAdmin(ctx context.Context, user string) (*Response, error) {
  25. u := fmt.Sprintf("users/%v/site_admin", user)
  26. req, err := s.client.NewRequest("DELETE", u, nil)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return s.client.Do(ctx, req, nil)
  31. }
  32. // UserSuspendOptions represents the reason a user is being suspended.
  33. type UserSuspendOptions struct {
  34. Reason *string `json:"reason,omitempty"`
  35. }
  36. // Suspend a user on a GitHub Enterprise instance.
  37. //
  38. // GitHub API docs: https://developer.github.com/enterprise/v3/enterprise-admin/users/#suspend-a-user
  39. func (s *UsersService) Suspend(ctx context.Context, user string, opt *UserSuspendOptions) (*Response, error) {
  40. u := fmt.Sprintf("users/%v/suspended", user)
  41. req, err := s.client.NewRequest("PUT", u, opt)
  42. if err != nil {
  43. return nil, err
  44. }
  45. return s.client.Do(ctx, req, nil)
  46. }
  47. // Unsuspend a user on a GitHub Enterprise instance.
  48. //
  49. // GitHub API docs: https://developer.github.com/enterprise/v3/enterprise-admin/users/#unsuspend-a-user
  50. func (s *UsersService) Unsuspend(ctx context.Context, user string) (*Response, error) {
  51. u := fmt.Sprintf("users/%v/suspended", user)
  52. req, err := s.client.NewRequest("DELETE", u, nil)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return s.client.Do(ctx, req, nil)
  57. }
上海开阖软件有限公司 沪ICP备12045867号-1