-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for new pull request review API #497
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start, @sahildua2305!
I've left minor comments that you should address for this endpoint, and keep them in mind for next ones.
But feel free to keep going, you're definitely on the right track. Thanks!
github/pulls_reviews.go
Outdated
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request | ||
func (s *PullRequestsService) ListReviews(owner string, repo string, number int) ([]*PullRequestReview, *Response, error) { | ||
u := fmt.Sprintf("repos/%v/%v/pulls/%v/reviews", owner, repo, number) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use "%d" instead of "%v" for number (but keep "%v" for owner and repo), in order to be more consistent with the rest of the code in this repository. See:
Line 212 in 466070b
u := fmt.Sprintf("repos/%v/%v/pulls/%d/files", owner, repo, number) |
github/pulls_reviews.go
Outdated
return nil, nil, err | ||
} | ||
|
||
req.Header.Set("Accept", mediaTypePullRequestReview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a // TODO: This header will be unnecessary when the API is no longer in preview.
comment above this line, for consistency.
github/pulls_reviews_test.go
Outdated
t.Errorf("PullRequests.ListComments returned error: %v", err) | ||
} | ||
|
||
want := []*PullRequestReview{{ID: Int(1)}, {ID: Int(2)}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor thought, but I'd make it more visible there are 2 reviews here by using multiple lines, like so:
want := []*PullRequestReview{
{ID: Int(1)},
{ID: Int(2)},
}
For example, see here.
github/pulls_reviews_test.go
Outdated
|
||
want := []*PullRequestReview{{ID: Int(1)}, {ID: Int(2)}} | ||
if !reflect.DeepEqual(reviews, want) { | ||
t.Errorf("PullRequests.ListComments returned %+v, want %+v", reviews, want) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean PullRequests.ListReviews
here, not ListComments
. :)
github/pulls_reviews_test.go
Outdated
|
||
reviews, _, err := client.PullRequests.ListReviews("o", "r", 1) | ||
if err != nil { | ||
t.Errorf("PullRequests.ListComments returned error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also typo here, ListComments
should be ListReviews
.
github/github.go
Outdated
@@ -91,6 +91,9 @@ const ( | |||
|
|||
// https://developer.github.com/changes/2016-09-14-Integrations-Early-Access/ | |||
mediaTypeIntegrationPreview = "application/vnd.github.machine-man-preview+json" | |||
|
|||
// https://developer.github.com/changes/2016-12-14-reviews-api/ | |||
mediaTypePullRequestReview = "application/vnd.github.black-cat-preview+json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a mouthful, but, there should be a Preview
stuffix at the end. These are all preview APIs, this one happens to be named "Pull Request Reviews". So:
mediaTypePullRequestReviewsPreview = ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice works!
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// PullRequestReview represents a review of a pull request. | ||
type PullRequestReview struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request
Some fields of list review API response are missing.
- commit_id
- html_url
- pull_request_url
You can see similar fields in PullRequestComment
go-github/github/pulls_comments.go
Line 14 in 7b47f69
type PullRequestComment struct { |
And "state" seems UPPRECASE and can be "APPROVED", "DISMISSED", "COMMENTED".
PullRequestReview is also used in PullRequestReviewEvent https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent , so maybe we should check consistencies and give feed backs to GitHub support perhaps if the differences are not reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"state" also can be "CHANGES_REQUESTED"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mean, "state" can be "ACCEPTED", "DISMISSED", "CHANGES_REQUESTED" or "COMMENTED" for Rest API we are working with now, but "state" also can be "approved", "rejected", or "commented" for pull-request event API. https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent
PullRequestReview is used here as a field of event API.
go-github/github/event_types.go
Line 338 in 7b47f69
Review *PullRequestReview `json:"review,omitempty"` |
So, it's not a good idea to remove existed comment, i guess.
Or, we can remove this comment completely and leave users to check GitHub API document, but i'm not sure.
And, there is a typo. s/ACCEPTED/APPROVED/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will prefer removing this comment totally. @haya14busa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I think it's ok to remove it.
7b47f69
to
38a474f
Compare
@shurcooL @haya14busa please review again. Made changes according to the initial feedback 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for ListReviews feature!
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// PullRequestReview represents a review of a pull request. | ||
type PullRequestReview struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I mean, "state" can be "ACCEPTED", "DISMISSED", "CHANGES_REQUESTED" or "COMMENTED" for Rest API we are working with now, but "state" also can be "approved", "rejected", or "commented" for pull-request event API. https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent
PullRequestReview is used here as a field of event API.
go-github/github/event_types.go
Line 338 in 7b47f69
Review *PullRequestReview `json:"review,omitempty"` |
So, it's not a good idea to remove existed comment, i guess.
Or, we can remove this comment completely and leave users to check GitHub API document, but i'm not sure.
And, there is a typo. s/ACCEPTED/APPROVED/
The changes look great, thanks! One suggestion. Since you're still iterating on this PR and making progress, it's better to push additional commits without rewriting history and squashing everything into a single commit. That way, when a reviewer is reviewing new changes, it's a lot easier to see what has changed since the last time they've looked. Otherwise, the reviewer has to review the entire thing from beginning, instead of just what's changed. Squashing during PR isn't needed because we can easily do that at the end, when merging. |
@shurcooL Got it! I'll push in separate commits from now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've discovered an issue with the GitHub API documentation for 2 of the new endpoints. See inline comments.
There are 2 things we should do:
-
Update the code to have
repo
parameter, because it's needed for successful operation (confirmed by hitting real API). -
It would be good to report this issue to GitHub so they fix their documentation. See the last paragraph of https://developer.github.com/changes/2016-12-14-reviews-api/:
If you have any questions or feedback, please let us know!
@sahildua2305, would you like to contact them and let them know?
github/pulls_reviews.go
Outdated
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments | ||
func (s *PullRequestsService) ListReviewComments(owner string, number int, id int) ([]*PullRequestReviewComment, *Response, error) { | ||
u := fmt.Sprintf("repos/%v/pulls/%d/reviews/%d/comments", owner, number, id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint is missing the repo
parameter too. We should add it, because it doesn't work otherwise.
github/pulls_reviews.go
Outdated
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-review | ||
func (s *PullRequestsService) GetReview(owner string, number int, id int) (*PullRequestReview, *Response, error) { | ||
u := fmt.Sprintf("repos/%v/pulls/%d/reviews/%d", owner, number, id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub API documentation has a mistake for this endpoint and the one below. They're both missing the repo
argument.
I've tested the API, and confirmed it's a documentation issue.
For example, listing reviews with owner and repo parameters works okay:
curl -i -H "Accept: application/vnd.github.black-cat-preview+json" 'https://api.github.com/repos/google/go-github/pulls/497/reviews'
One if the IDs it returns is 13441488
. Then, if we use GitHub API docs to get that single URL, without the repo parameter, it's a 404:
$ curl -i -H "Accept: application/vnd.github.black-cat-preview+json" 'https://api.github.com/repos/google/pulls/497/reviews/13441488'
HTTP/1.1 404 Not Found
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
But if we include repo (as one would expect... it makes no sense to specify a PR with just owner and PR number, without repo name), it works:
$ curl -i -H "Accept: application/vnd.github.black-cat-preview+json" 'https://api.github.com/repos/google/go-github/pulls/497/reviews/13441488'
HTTP/1.1 200 OK
{
"id": 13441488,
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing this @shurcooL! Even I was suspicious at the time of writing that method however, didn't delve deeper.
I have contacted GitHub about the error in their documentation. I will update the endpoint in our code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thank you @sahildua2305!
There are 15 structs in go-github that end with "Request". We want to use a similar pattern. There'll be a new struct for creating new PR reviews, named For example, see the
So I'd expect a |
@shurcooL thanks for the detailed response! I think I got it. I will implement |
03eeede
to
fbc15ca
Compare
@shurcooL @haya14busa This is ready for review 🙂 |
github/pulls_reviews.go
Outdated
// ListReviewComments lists all the comments for the specified review | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments | ||
func (s *PullRequestsService) ListReviewComments(owner string, number int, id int) ([]*PullRequestReviewComment, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test this actual endpoint? It seems it doesn't work.
curl -i -H "Accept: application/vnd.github.black-cat-preview+json" 'https://api.github.com/repos/google/go-github/pulls/497/reviews/13455186/comments'
{
"message": "Validation Failed",
"errors": [
"Cannot return null for non-nullable field PullRequestReviewComment.position"
],
"documentation_url": "https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments"
}
Maybe, we should report this to GitHub support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind. It's not go-github implementation issue. I reported to GitHub support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the error you're getting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error:
$ curl -v -H "Accept: application/vnd.github.black-cat-preview+json" 'https://api.github.com/repos/google/go-github/pulls/497/reviews/13441488/comments'
* Trying 192.30.253.117...
* Connected to api.github.com (192.30.253.117) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=*.github.com
* start date: Apr 8 00:00:00 2014 GMT
* expire date: Apr 12 12:00:00 2017 GMT
* subjectAltName: host "api.github.com" matched cert's "*.github.com"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
> GET /repos/google/go-github/pulls/497/reviews/13441488/comments HTTP/1.1
> Host: api.github.com
> User-Agent: curl/7.50.0-DEV
> Accept: application/vnd.github.black-cat-preview+json
>
< HTTP/1.1 422 Unprocessable Entity
< Server: GitHub.com
< Date: Thu, 22 Dec 2016 08:54:11 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 573
< Status: 422 Unprocessable Entity
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 20
< X-RateLimit-Reset: 1482399467
< X-GitHub-Media-Type: github.black-cat-preview; format=json
< Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
< Access-Control-Allow-Origin: *
< Content-Security-Policy: default-src 'none'
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-XSS-Protection: 1; mode=block
< X-GitHub-Request-Id: 31680E9E:C366:4D04E48:585B94B2
<
{
"message": "Validation Failed",
"errors": [
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position"
],
"documentation_url": "https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments"
}
I already reported this problem to GitHub support but it seems it's not fixed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub fixed this problem! ❤️
github/pulls_reviews.go
Outdated
// GetReview fetches the specified pull request review. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-review | ||
func (s *PullRequestsService) GetReview(owner string, number int, id int) (*PullRequestReview, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] I prefer reviewID
instead of id
, because users cannot tell what is number
and id
from signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that even in issues_comments.go
, all methods use id
. I kept as id
to make the code consistent. Do we want to change there as well?
github/pulls_reviews.go
Outdated
return Stringify(p) | ||
} | ||
|
||
// PullRequestReviewComment represents a comment left on a pull request review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] period missing, including other comments.
github/pulls_reviews.go
Outdated
Comments []DraftReviewComment `json:"comments,omitempty"` | ||
|
||
// Message is used (optionally) while dismissing a review | ||
Message *string `json:"message,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I think it's better to create another struct like PullRequestReviewDissmisalRequest
or PullRequestReviewDissmisal
because the format is completely different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was confused between the two approaches (making a new struct and adding an optional field in PullRequestReviewRequest
struct). I will make a new struct 👍
github/pulls_reviews.go
Outdated
type PullRequestReviewRequest struct { | ||
Body *string `json:"body,omitempty"` | ||
Event *string `json:"event,omitempty"` | ||
Comments []DraftReviewComment `json:"comments,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be Comments []*DraftReviewComment
for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are any of the fields optional? They should only be pointers with ,omitempty
if they're optional. Otherwise, plain values and no ,omitempty
would be more fitting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested this because I rememerbed go-github API changes from []T
to []*T
like ([]github.PullRequestComment
-> []*github.PullRequestComment
) several month ago.
The pull-request is this. #375
But, on second thought, PullRequestReviewRequest
is only used as a request, not as a response.
So, I agree with you. Pointer is not needed here.
github/pulls_reviews.go
Outdated
|
||
// State can be "approved", "rejected", or "commented". | ||
// State can be "ACCEPTED", "DISMISSED", "CHANGES_REQUESTED" or "COMMENTED". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or "PENDING" for pending reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add 👍
github/pulls_reviews.go
Outdated
type PullRequestReviewRequest struct { | ||
Body *string `json:"body,omitempty"` | ||
Event *string `json:"event,omitempty"` | ||
Comments []DraftReviewComment `json:"comments,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested this because I rememerbed go-github API changes from []T
to []*T
like ([]github.PullRequestComment
-> []*github.PullRequestComment
) several month ago.
The pull-request is this. #375
But, on second thought, PullRequestReviewRequest
is only used as a request, not as a response.
So, I agree with you. Pointer is not needed here.
github/pulls_reviews.go
Outdated
|
||
// SubmitReview submits a specified review on the specified pull request | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI: I reported a problem regarding this API as below. We cannot left "event" empty.
If left blank, the review will be in the PENDING state.
-- https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review
Document says we can left "event" field for "Submit a pull request review" API as "PENDING" stete, but API doesn't support it.
Response:
{
"message": "Invalid request. "event" wasn't supplied.",
"documentation_url": "https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review"
}
// TODO: remove custom Accept header when this API fully launches | ||
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) | ||
|
||
r := new(PullRequestReview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep variable name consistent. In GetReview
, The variable name is "review".
In Go, short name is preferred if it makes senses, so I think it's ok to use r
, but in this case, i like "review".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, "review" is used as argument. Please ignore this.
As I posted request and error response example (#497 (comment)), error format for review API is not same as http://developer.github.com/v3/#client-errors "errors" is list of string for review API. {
"message": "Validation Failed",
"errors": [
"Cannot return null for non-nullable field PullRequestReviewComment.position"
],
"documentation_url": "https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments"
} Corresponding go-github struct ( Line 463 in fbc15ca
Because I'll report this problem to GitHub support, but this review API error fromat could be intentional. |
@haya14busa I have updated the PR accordingly. Please review again. (\cc: @shurcooL) |
github/pulls_reviews.go
Outdated
} | ||
|
||
// PullRequestReviewComment represents a comment left on a pull request review. | ||
type PullRequestReviewComment struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add String()
method for this type as well, including other new added structs.
func (p PullRequestReviewComment) String() string {
return Stringify(p)
}
In addition, we can test String()
method in func TestString
go-github/github/strings_test.go
Line 87 in 4dcd653
func TestString(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
github/pulls_reviews.go
Outdated
Body *string `json:"body,omitempty"` | ||
} | ||
|
||
// PullRequestReviewRequest represents a request to create a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not go-github implementation issue, but GitHub API one, but I wonder why we cannot specify CommitID
to DraftReviewComment
nor PullRequestReviewRequest
.
Create a Pull Request comment API support commit_id https://developer.github.com/v3/pulls/comments/#create-a-comment
When passing the commit_id, use the SHA of the latest commit in the pull request or your comment may appear as "outdated" if the specified position has been modified in a subsequent commit.
As document noted, commit_id is important to specify a line because subsequent commit may overwrite it.
It might be better to contact to GitHub support about this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you contact GitHub about this issue? So, we will have to wait till they fix it before we can merge it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not, yet. Will do. (edit: sent a report)
So, we will have to wait till they fix it before we can merge it?
No, I think we don't have to wait fix(?) about this problem. We can add a field later after merging.
However, I think it's better to wait for the fix or response about the error format problem. #497 (comment)
If it's intentional, go-github should support the new error format as well.
if !reflect.DeepEqual(reviews, want) { | ||
t.Errorf("PullRequests.ListReviews returned %+v, want %+v", reviews, want) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that there are test cases for invalid request for other API.
e.g.
go-github/github/pulls_comments_test.go
Line 71 in 4dcd653
func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) { |
func TestPullRequestsService_ListComments_invalidOwner(t *testing.T) {
_, _, err := client.PullRequests.ListComments("%", "r", 1, nil)
testURLParseError(t, err)
}
I think it's not so important test but it might be better to add similar tests for review API as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some of the tests, not for all new methods however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice! Thanks 👍 8c7f0fb
Could you please adding similar tests for the rest of methods for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
github/pulls_reviews.go
Outdated
// ListReviewComments lists all the comments for the specified review | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments | ||
func (s *PullRequestsService) ListReviewComments(owner string, number int, id int) ([]*PullRequestReviewComment, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error:
$ curl -v -H "Accept: application/vnd.github.black-cat-preview+json" 'https://api.github.com/repos/google/go-github/pulls/497/reviews/13441488/comments'
* Trying 192.30.253.117...
* Connected to api.github.com (192.30.253.117) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=*.github.com
* start date: Apr 8 00:00:00 2014 GMT
* expire date: Apr 12 12:00:00 2017 GMT
* subjectAltName: host "api.github.com" matched cert's "*.github.com"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
> GET /repos/google/go-github/pulls/497/reviews/13441488/comments HTTP/1.1
> Host: api.github.com
> User-Agent: curl/7.50.0-DEV
> Accept: application/vnd.github.black-cat-preview+json
>
< HTTP/1.1 422 Unprocessable Entity
< Server: GitHub.com
< Date: Thu, 22 Dec 2016 08:54:11 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 573
< Status: 422 Unprocessable Entity
< X-RateLimit-Limit: 60
< X-RateLimit-Remaining: 20
< X-RateLimit-Reset: 1482399467
< X-GitHub-Media-Type: github.black-cat-preview; format=json
< Access-Control-Expose-Headers: ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
< Access-Control-Allow-Origin: *
< Content-Security-Policy: default-src 'none'
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< X-Content-Type-Options: nosniff
< X-Frame-Options: deny
< X-XSS-Protection: 1; mode=block
< X-GitHub-Request-Id: 31680E9E:C366:4D04E48:585B94B2
<
{
"message": "Validation Failed",
"errors": [
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position",
"Cannot return null for non-nullable field PullRequestReviewComment.position"
],
"documentation_url": "https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments"
}
I already reported this problem to GitHub support but it seems it's not fixed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job! Sorry for the repetitive reviews, but I left some new comments.
I found integration tests which doesn't need GitHub API token. e.g. TestPullRequests_ListCommits
https://github.com/google/go-github/blob/4dcd653e8d6b7aa32a6d50d938cecca80a8b4b61/tests/integration/pulls_test.go
I tested some methods like this, but I guess it's awesome if you add intergration tests, for method which doens't require GitHub API token.
https://gist.github.com/haya14busa/b561b5c0df8475b34799d076253600e5#file-2016-12-22-173545-go
I think it's not strictly required to write intergration tests, but it helps a alot and worth adding it.
As for the method which requires GitHub API token, I think we have to test them at least once like the gist example I posted above (link).
Did you write something like that?
github/pulls_reviews.go
Outdated
// ListReviewComments lists all the comments for the specified review. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments | ||
func (s *PullRequestsService) ListReviewComments(owner string, repo string, number int, reviewID int) ([]*PullRequestReviewComment, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returned type should be ([]*PullRequestComment, *Response, error)
doc: https://developer.github.com/v3/pulls/reviews/#get-a-single-reviews-comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Fixed
@shurcooL @haya14busa please review again. |
Just FYI: I reported a GitHub Review API problem regarding cannceling or adding line comments to a pending review as follow, it's not go-github one but I just let you know I reported a problem regarding GitHub Review API. Cannot cancel a pending review nor add line comments (draft review comment) to a pending review via Review API. It seems that we cannot canncel a pending review via API nor add line comments, although we can do it via Web UI. So, once we create a pending review via Create a pull request review API, I think Reivew API should support to cancel a pending review or/and add a line comments to a pending review. Thanks in advance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for your great work 👍
It might be better to wait for the responce from GitHub supports for some problems like this one #497 (comment) before merging this pull-request, but LGTM for now 💯
I confirmed each methods works as expected at least once. https://gist.github.com/haya14busa/6eae0c71a6dbbb652e90d227817dc8fd#file-create_review-go
ref: #497 (review)
Please fix the problem I described in this comment https://github.com/google/go-github/pull/497/files#r92924211 and fix the merge conflict.
github/pulls_reviews.go
Outdated
return r, resp, err | ||
} | ||
|
||
// SubmitReview submits a specified review on the specified pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI: I reported a GitHub Review API problem as follow, it's not go-github one but I just let you know I reported a problem regarding this API.
Cannot use Submit a pull request review for public repositories with API token which has only public_repo
as a scope.
It seems the API token needs repo
scope (Full control of private repositories).
I confirmed this behavior by toggling the scope of the API token.
With API token which only has public_repo
as a scope, "Submit a pull request review" API returns NotFound, API token which has repo scope works as expected.
Not Found error:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review"
}
On the other hands, Create a pull request review works as expected with API token which only has public_repo
as a scope.
"Submit a pull request review" API should work with API token which only has public_repo
.
Thanks in advance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reporting it to GitHub support @haya14busa and looking into it.
If I'm reading this right, it sounds like the problem is a purely permissions one and is on their backend. If they resolve it by changing the permission requirements, then there wouldn't be any API changes on our side, would there?
If so, I would suggest we lean towards not letting this issue block the PR from being merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, I would suggest we lean towards not letting this issue block the PR from being merged.
Agree. I just let you know to share the problem not to make you get into the same problem.
However, as for the different problem I described in this comment #497 (comment) , it's might be better to wait the response because it's related go-github implementation.
It will be really hard to get error messages via go-github at current implementation.
But i'm not sure. We can also merge p-r and fix it later. I leave it to you.
GitHub support kindly contacted me several times, but they didn't fix it yet.
They may overlook this problem because I reported several other problems.
May I ping them about the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinging after some time should be fine. If they're already on it, they'll let you know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, while we wait for them to respond/fix the issue, should we go ahead with this PR and land it? It's been hanging around for a while now 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with landing this sooner as long as the affected endpoints have the problem documented and a TODO comment saying what needs to be followed up with.
But if the problem is serious enough to affect all endpoints, we may want to hold a bit more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll ping them a few hours later. We want to know the error format is expected or not at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @haya14busa. Let us know once you hear back from them 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@haya14busa did you get any update?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub support tells me that he contacted to developer teams to share the problem, but no document or implementation fix yet.
1ad2f71
to
0d9faa8
Compare
@haya14busa thanks for green signal 💚 @shurcooL please check 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked over this and I did not spot any issues. LGTM.
Huge thanks @sahildua2305 and @haya14busa for working on this!
From what I can see, the only blocking issue before merging this is the potentially misbehaving SubmitReview
endpoint, is that right?
I left a comment about it. My recommendation would be to try to get this PR merged sooner rather than wait for a complete resolution there. Reasons being:
- it sounds like the problem resolution (if any) would not have significant/any effect on the API
- this is an preview API, meaning it's not considered stable yet. there may be additional problems on github backend. our responsibility in go-github is to map the Go methods to the correct endpoints and structs.
- merging this sooner means more people can start trying out and beta-testing these new endpoints, potentially uncovering problems sooner
- it's less work to merge sooner than later
GitHub usually has very quick turnaround, so I expect it'll take somewhere between a day~a week. But I'd rather us not be blocked unnecessarily.
The only thing we should do to make the PR merge-able now is to document the known issue with the SubmitReview
endpoint and add a TODO comment to follow it up. Then it can safely be merged sooner.
Thanks for the review @shurcooL :) Where do we add the corresponding TODO as you mentioned in the review? |
No. As I said in this comment, the only thing we should care about is problem about error response format. I think we can ignore other problems because they are not related with go-github implementation. |
- Change return type of ListReviewComments method to PullRequestComment. - Corresponding changes in unit tests. - Remove type PullRequestReviewComment. - Remove string test for PullRequestReviewComment.
- Added new API endpoint for deleting a pending review. - Wrote unit tests for the same.
48e9d90
to
91cc8ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, since it's been one week, did you hear back from GitHub support?
GitHub Supports said that they doesn't share public timeline to fix the problem nor tell me the direction to fix it (document fix or implementation fix).
They will get in touch with me once there are some progress.
I looked at the document about error format https://developer.github.com/v3/#client-errors again, but there are no document fix yet at least right now.
I assume (or I should say I hope) they are going to fix the problem by implementation fix, because documentation fix must be easy and it doen't take lots of time. But, your guess is as good as mine.
I think it's ok to merge this p-r, but could you please adding comments to each method about this problem?
github/pulls_reviews.go
Outdated
// Note: There is a known issue with this preview endpoint. | ||
// Read more about it here - https://github.com/google/go-github/pull/497#discussion_r94593877 | ||
// | ||
// TODO: Remove this once we arrive at resolution with GitHub Support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed now. Can you confirm and remove this?
github/pulls_reviews.go
Outdated
// DeletePendingReview deletes the specified pull request pending review. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review | ||
func (s *PullRequestsService) DeletePendingReview(owner string, repo string, number int, reviewID int) (*PullRequestReview, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great, @sahildua2305!
I have just a few minor tweaks... and please be aware that these are not mistakes you have made... I went ahead and changed some things out from under you in the repo while you were working on this.
If you don't wish to address them, that is fine too, and I can make the changes in a separate PR... your call.
Thank you, @shurcooL and @haya14busa for your continued reviews on this PR... they are greatly appreciated!
github/pulls_reviews.go
Outdated
type PullRequestReviewRequest struct { | ||
Body *string `json:"body,omitempty"` | ||
Event *string `json:"event,omitempty"` | ||
Comments []DraftReviewComment `json:"comments,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use slice of pointers, not slice of values:
Comments []*DraftReviewComment `json:"comments,omitempty"`
github/pulls_reviews.go
Outdated
// ListReviews lists all reviews on the specified pull request. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request | ||
func (s *PullRequestsService) ListReviews(owner string, repo string, number int) ([]*PullRequestReview, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(owner, repo string, number int)
github/pulls_reviews.go
Outdated
// TODO: remove custom Accept header when this API fully launches | ||
req.Header.Set("Accept", mediaTypePullRequestReviewsPreview) | ||
|
||
reviews := new([]*PullRequestReview) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var reviews []*PullRequestReview
resp, err := s.client.Do(req, &reviews)
if err != nil {
return nil, resp, err
}
return reviews, resp, nil
github/pulls_reviews.go
Outdated
// GetReview fetches the specified pull request review. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#get-a-single-review | ||
func (s *PullRequestsService) GetReview(owner string, repo string, number int, reviewID int) (*PullRequestReview, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(owner, repo string, number, reviewID int)
github/pulls_reviews.go
Outdated
return nil, resp, err | ||
} | ||
|
||
return review, resp, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return review, resp, nil
github/pulls_reviews.go
Outdated
// TODO: Remove this once we arrive at resolution with GitHub Support. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review | ||
func (s *PullRequestsService) SubmitReview(owner string, repo string, number int, reviewID int, review *PullRequestReviewRequest) (*PullRequestReview, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(owner, repo string, number, reviewID int, review *PullRequestReviewRequest)
github/pulls_reviews.go
Outdated
return nil, resp, err | ||
} | ||
|
||
return r, resp, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return r, resp, nil
github/pulls_reviews.go
Outdated
// DismissReview dismisses a specified review on the specified pull request. | ||
// | ||
// GitHub API docs: https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review | ||
func (s *PullRequestsService) DismissReview(owner string, repo string, number int, reviewID int, review *PullRequestReviewDismissalRequest) (*PullRequestReview, *Response, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(owner, repo string, number, reviewID int, review *PullRequestReviewDismissalRequest)
} | ||
|
||
// PullRequestReviewDismissalRequest represents a request to dismiss a review. | ||
type PullRequestReviewDismissalRequest struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could reduce the stutter on this type... it reminds me too much of Java. 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I can think of is to use PRReviewDismissalRequest
but that will disturb the consistency. 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I couldn't think of a better alternative. I was just lamenting. 😄
github/pulls_reviews.go
Outdated
|
||
// State can be "approved", "rejected", or "commented". | ||
State *string `json:"state,omitempty"` | ||
return r, resp, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return r, resp, nil
- Includes majorly the changes of return err to return nil when err is nil.
@gmlewis thanks for the review. I went ahead and fixed all the minor issues. Please review again 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you, @sahildua2305!
I'll wait for @shurcooL to LGTM before merging in case I've provided feedback that he doesn't agree with.
Could you please adding comments for known issues as well? |
Still LGTM, I don't have change requests from myself. However, I think the point @haya14busa is making should be addressed (it's just a documentation change). |
@haya14busa according to our previous discussion, all endpoints in this PR have the aforementioned issue except list reviews and create review. Is that right? |
No. Create review endpoint also has the same problem. You might be able to skip |
@haya14busa done 😄 |
Thank you for the fix @sahildua2305 👍 👍 👍 |
github/pulls_reviews.go
Outdated
// TODO: Follow up with GitHub support about an issue with this method's | ||
// returned error format and remove this comment once it's fixed. | ||
// Read mroe about it here - | ||
// https://github.com/google/go-github/pull/497#issuecomment-267810912 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo here, "mroe" should be "more".
Instead of linking to the middle of this PR with 100+ of comments, let's use a new issue to track this and point people at it. This will be much friendlier.
I've made #540 - please link to it instead.
@shurcooL Done! Fixed 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you, @sahildua2305!
Merging. |
Integrated in 27c7c32 |
Fixes google#495. Closes google#497. Change-Id: If266972e7a20f83afaa842d54c22846bbb435328
fixes #495
@shurcooL @haya14busa please review. 🙂