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

81 lines
2.8KB

  1. // Copyright 2018 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. // GetRestrictionsForRepo fetches the interaction restrictions for a repository.
  11. //
  12. // GitHub API docs: https://developer.github.com/v3/interactions/repos/#get-interaction-restrictions-for-a-repository
  13. func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, repo string) (*InteractionRestriction, *Response, error) {
  14. u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
  15. req, err := s.client.NewRequest("GET", u, nil)
  16. if err != nil {
  17. return nil, nil, err
  18. }
  19. // TODO: remove custom Accept header when this API fully launches.
  20. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
  21. repositoryInteractions := new(InteractionRestriction)
  22. resp, err := s.client.Do(ctx, req, repositoryInteractions)
  23. if err != nil {
  24. return nil, resp, err
  25. }
  26. return repositoryInteractions, resp, nil
  27. }
  28. // UpdateRestrictionsForRepo adds or updates the interaction restrictions for a repository.
  29. //
  30. // limit specifies the group of GitHub users who can comment, open issues, or create pull requests
  31. // for the given repository.
  32. // Possible values are: "existing_users", "contributors_only", "collaborators_only".
  33. //
  34. // GitHub API docs: https://developer.github.com/v3/interactions/repos/#add-or-update-interaction-restrictions-for-a-repository
  35. func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, owner, repo, limit string) (*InteractionRestriction, *Response, error) {
  36. u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
  37. interaction := &InteractionRestriction{Limit: String(limit)}
  38. req, err := s.client.NewRequest("PUT", u, interaction)
  39. if err != nil {
  40. return nil, nil, err
  41. }
  42. // TODO: remove custom Accept header when this API fully launches.
  43. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
  44. repositoryInteractions := new(InteractionRestriction)
  45. resp, err := s.client.Do(ctx, req, repositoryInteractions)
  46. if err != nil {
  47. return nil, resp, err
  48. }
  49. return repositoryInteractions, resp, nil
  50. }
  51. // RemoveRestrictionsFromRepo removes the interaction restrictions for a repository.
  52. //
  53. // GitHub API docs: https://developer.github.com/v3/interactions/repos/#remove-interaction-restrictions-for-a-repository
  54. func (s *InteractionsService) RemoveRestrictionsFromRepo(ctx context.Context, owner, repo string) (*Response, error) {
  55. u := fmt.Sprintf("repos/%v/%v/interaction-limits", owner, repo)
  56. req, err := s.client.NewRequest("DELETE", u, nil)
  57. if err != nil {
  58. return nil, err
  59. }
  60. // TODO: remove custom Accept header when this API fully launches.
  61. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview)
  62. return s.client.Do(ctx, req, nil)
  63. }
上海开阖软件有限公司 沪ICP备12045867号-1