|
5 | 5 |
|
6 | 6 | package github
|
7 | 7 |
|
8 |
| -import "time" |
| 8 | +import ( |
| 9 | + "fmt" |
| 10 | + "time" |
| 11 | +) |
9 | 12 |
|
10 | 13 | // PullRequestReview represents a review of a pull request.
|
11 | 14 | type PullRequestReview struct {
|
12 |
| - ID *int `json:"id,omitempty"` |
13 |
| - User *User `json:"user,omitempty"` |
14 |
| - Body *string `json:"body,omitempty"` |
15 |
| - SubmittedAt *time.Time `json:"submitted_at,omitempty"` |
| 15 | + ID *int `json:"id,omitempty"` |
| 16 | + User *User `json:"user,omitempty"` |
| 17 | + Body *string `json:"body,omitempty"` |
| 18 | + SubmittedAt *time.Time `json:"submitted_at,omitempty"` |
| 19 | + CommitID *string `json:"commit_id,omitempty"` |
| 20 | + HTMLURL *string `json:"html_url,omitempty"` |
| 21 | + PullRequestURL *string `json:"pull_request_url,omitempty"` |
16 | 22 |
|
17 |
| - // State can be "approved", "rejected", or "commented". |
| 23 | + // State can be "ACCEPTED", "DISMISSED", "CHANGES_REQUESTED" or "COMMENTED". |
18 | 24 | State *string `json:"state,omitempty"`
|
19 | 25 | }
|
| 26 | + |
| 27 | +func (p PullRequestReview) String() string { |
| 28 | + return Stringify(p) |
| 29 | +} |
| 30 | + |
| 31 | +// ListReviews lists all reviews on the specified pull request. |
| 32 | +// |
| 33 | +// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request |
| 34 | +func (s *PullRequestsService) ListReviews(owner string, repo string, number int) ([]*PullRequestReview, *Response, error) { |
| 35 | + u := fmt.Sprintf("repos/%v/%v/pulls/%d/reviews", owner, repo, number) |
| 36 | + |
| 37 | + req, err := s.client.NewRequest("GET", u, nil) |
| 38 | + if err != nil { |
| 39 | + return nil, nil, err |
| 40 | + } |
| 41 | + |
| 42 | + // TODO: remove custom Accept header when this API fully launches |
| 43 | + req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) |
| 44 | + |
| 45 | + reviews := new([]*PullRequestReview) |
| 46 | + resp, err := s.client.Do(req, reviews) |
| 47 | + if err != nil { |
| 48 | + return nil, resp, err |
| 49 | + } |
| 50 | + |
| 51 | + return *reviews, resp, err |
| 52 | +} |
0 commit comments