-
Notifications
You must be signed in to change notification settings - Fork 75
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 the read half of the PR Review API #139
Changes from 12 commits
3db6512
80839bb
a6bf4a3
71e9b89
da817c3
11408bc
ea2934a
ec8fd76
3fe4cf2
04eb6e4
48bb78a
7ac88b5
abb7a87
8c59b89
9784ec6
dbbb7b9
8652b4b
737ac9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ with Github4s, you can: | |
- [List pull requests](#list-pull-requests) | ||
- [List the files in a pull request](#list-the-files-in-a-pull-request) | ||
- [Create a pull request](#create-a-pull-request) | ||
- [List reviews](#list-pull-request-reviews) | ||
- [Get a review](#get-an-individual-review) | ||
|
||
The following examples assume the following imports and token: | ||
|
||
|
@@ -128,6 +130,60 @@ createPullRequestIssue.exec[cats.Id, HttpResponse[String]]() match { | |
|
||
See [the API doc](https://developer.github.com/v3/pulls/#create-a-pull-request) for full reference. | ||
|
||
# Review API | ||
|
||
## List pull request reviews | ||
|
||
You can list the reviews for a pull request using `listReviews`, it takes as arguments: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reflecting #146: |
||
|
||
- the repository coordinates (`owner` and `name` of the repository). | ||
- the pull request id. | ||
|
||
As an example, if we wanted to see all the reviews for pull request 139 of `47deg/github4s`: | ||
|
||
```tut:silent | ||
val listReviews = Github(accessToken).pullRequests.listReviews( | ||
"47deg", | ||
"github4s", | ||
139) | ||
|
||
listReviews.exec[cats.Id, HttpResponse[String]]() match { | ||
case Left(e) => println("Something went wrong: s{e.getMessage}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be: case Left(e) => println(s"Something went wrong: ${e.getMessage}") |
||
case Right(r) => println(r.result) | ||
} | ||
``` | ||
|
||
The `result` on the right is the matching [List[PullRequestReview]][pr-scala]. | ||
|
||
See [the API doc](https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request) for full reference. | ||
|
||
## Get an individual review | ||
|
||
You can get an individual review for a pull request using `getReview`, it takes as arguments: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
|
||
- the repository coordinates (`owner` and `name` of the repository). | ||
- the pull request id. | ||
- the review id. | ||
|
||
As an example, if we wanted to see review 39355613 for pull request 139 of `47deg/github4s`: | ||
|
||
```tut:silent | ||
val review = Github(accessToken).pullRequests.getReview( | ||
"47deg", | ||
"github4s", | ||
139, | ||
39355613) | ||
|
||
review.exec[cats.Id, HttpResponse[String]]() match { | ||
case Left(e) => println("Something went wrong: s{e.getMessage}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
case Right(r) => println(r.result) | ||
} | ||
``` | ||
|
||
The `result` on the right is the matching [PullRequestReview][pr-scala]. | ||
|
||
See [the API doc](https://developer.github.com/v3/pulls/reviews/#get-a-single-review) for full reference. | ||
|
||
As you can see, a few features of the pull request endpoint are missing. As a result, if you'd like | ||
to see a feature supported, feel free to create an issue and/or a pull request! | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -598,29 +598,65 @@ trait MockGithubApiServer extends MockServerService with FakeResponses with Test | |
""".stripMargin))) | ||
.respond(response.withStatusCode(createdStatusCode).withBody(validCreatePullRequest)) | ||
|
||
//Issues >> list | ||
//PullRequests >> listReviews | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I screwed something up big here. |
||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath(s"/repos/$validRepoOwner/$validRepoName/issues") | ||
.withPath(s"/repos/$validRepoOwner/$validRepoName/pulls/$validPullRequestNumber/reviews") | ||
.withHeader("Authorization", tokenHeader)) | ||
.respond(response.withStatusCode(okStatusCode).withBody(listIssuesValidResponse)) | ||
.respond(response.withStatusCode(okStatusCode).withBody(listReviewsValidResponse)) | ||
|
||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath(s"/repos/$validRepoOwner/$validRepoName/issues") | ||
.withPath(s"/repos/$validRepoOwner/$validRepoName/pulls/$validPullRequestNumber/reviews") | ||
.withHeader(not("Authorization"))) | ||
.respond(response.withStatusCode(unauthorizedStatusCode).withBody(unauthorizedResponse)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're not using this endpoint in your tests, you can remove it 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still unused |
||
|
||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath(s"/repos/$validRepoOwner/$invalidRepoName/pulls/$validPullRequestNumber/reviews") | ||
.withHeader("Authorization", tokenHeader)) | ||
.respond(response.withStatusCode(notFoundStatusCode).withBody(notFoundResponse)) | ||
|
||
//PullRequests >> getReview | ||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath( | ||
s"/repos/$validRepoOwner/$validRepoName/pulls/$validPullRequestNumber/reviews/$validPullRequestReviewNumber") | ||
.withHeader("Authorization", tokenHeader)) | ||
.respond(response.withStatusCode(okStatusCode).withBody(getReviewValidResponse)) | ||
|
||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath( | ||
s"/repos/$validRepoOwner/$invalidRepoName/pulls/$validPullRequestNumber/reviews/$validPullRequestReviewNumber") | ||
.withHeader("Authorization", tokenHeader)) | ||
.respond(response.withStatusCode(notFoundStatusCode).withBody(notFoundResponse)) | ||
|
||
//Issues >> list | ||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath(s"/repos/$validRepoOwner/$validRepoName/issues") | ||
.withHeader("Authorization", tokenHeader)) | ||
.respond(response.withStatusCode(okStatusCode).withBody(listIssuesValidResponse)) | ||
|
||
mockServer | ||
.when( | ||
request | ||
.withMethod("GET") | ||
.withPath(s"/repos/$validRepoOwner/$invalidRepoName/issues") | ||
.withHeader(not("Authorization"))) | ||
.withHeader("Authorization", tokenHeader)) | ||
.respond(response.withStatusCode(notFoundStatusCode).withBody(notFoundResponse)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm I think things got mixed up because Issues >> List is testing for request without auth token: https://github.com/47deg/github4s/blob/master/github4s/jvm/src/test/scala/github4s/unit/ApiSpec.scala#L778-L782 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, there's a corresponding add for |
||
|
||
//Issues >> create | ||
|
@@ -637,7 +673,7 @@ trait MockGithubApiServer extends MockServerService with FakeResponses with Test | |
request | ||
.withMethod("POST") | ||
.withPath(s"/repos/$validRepoOwner/$validRepoName/issues") | ||
.withHeader(not("Authorization"))) | ||
.withHeader("Authorization", tokenHeader)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did this come from? This should fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you sort this out in the end? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, same as above: the difference here are strictly correct but don't reflect how I actually just added a block of text, instead trying to find the way to represent that with the minimum of changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll double check when I get home just to be sure though. |
||
.respond(response.withStatusCode(unauthorizedStatusCode).withBody(unauthorizedResponse)) | ||
|
||
mockServer | ||
|
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.
Since Reviews are a "sub-API" of the pull request API, we usually do subsections, so you'll end up with:
Pull request
List pull requests
...
Reviews
List reviews
Get an individual review