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

80 lines
2.5KB

  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. // ReviewersRequest specifies users and teams for a pull request review request.
  11. type ReviewersRequest struct {
  12. Reviewers []string `json:"reviewers,omitempty"`
  13. TeamReviewers []string `json:"team_reviewers,omitempty"`
  14. }
  15. // Reviewers represents reviewers of a pull request.
  16. type Reviewers struct {
  17. Users []*User `json:"users,omitempty"`
  18. Teams []*Team `json:"teams,omitempty"`
  19. }
  20. // RequestReviewers creates a review request for the provided reviewers for the specified pull request.
  21. //
  22. // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#create-a-review-request
  23. func (s *PullRequestsService) RequestReviewers(ctx context.Context, owner, repo string, number int, reviewers ReviewersRequest) (*PullRequest, *Response, error) {
  24. u := fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, number)
  25. req, err := s.client.NewRequest("POST", u, &reviewers)
  26. if err != nil {
  27. return nil, nil, err
  28. }
  29. r := new(PullRequest)
  30. resp, err := s.client.Do(ctx, req, r)
  31. if err != nil {
  32. return nil, resp, err
  33. }
  34. return r, resp, nil
  35. }
  36. // ListReviewers lists reviewers whose reviews have been requested on the specified pull request.
  37. //
  38. // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#list-review-requests
  39. func (s *PullRequestsService) ListReviewers(ctx context.Context, owner, repo string, number int, opt *ListOptions) (*Reviewers, *Response, error) {
  40. u := fmt.Sprintf("repos/%v/%v/pulls/%d/requested_reviewers", owner, repo, number)
  41. u, err := addOptions(u, opt)
  42. if err != nil {
  43. return nil, nil, err
  44. }
  45. req, err := s.client.NewRequest("GET", u, nil)
  46. if err != nil {
  47. return nil, nil, err
  48. }
  49. reviewers := new(Reviewers)
  50. resp, err := s.client.Do(ctx, req, reviewers)
  51. if err != nil {
  52. return nil, resp, err
  53. }
  54. return reviewers, resp, nil
  55. }
  56. // RemoveReviewers removes the review request for the provided reviewers for the specified pull request.
  57. //
  58. // GitHub API docs: https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request
  59. func (s *PullRequestsService) RemoveReviewers(ctx context.Context, owner, repo string, number int, reviewers ReviewersRequest) (*Response, error) {
  60. u := fmt.Sprintf("repos/%s/%s/pulls/%d/requested_reviewers", owner, repo, number)
  61. req, err := s.client.NewRequest("DELETE", u, &reviewers)
  62. if err != nil {
  63. return nil, err
  64. }
  65. return s.client.Do(ctx, req, nil)
  66. }
上海开阖软件有限公司 沪ICP备12045867号-1