diff --git a/doc/pull_request/review_request.md b/doc/pull_request/review_request.md new file mode 100644 index 00000000000..5b27c21a6b0 --- /dev/null +++ b/doc/pull_request/review_request.md @@ -0,0 +1,27 @@ +## Pull Requests / Review Requests API +[Back to the "Pull Requests API"](../pull_requests.md) | [Back to the navigation](../README.md) + +The Pull Request Review API is currently available for developers to preview. +To access the API during the preview period, you must provide a custom media type in the Accept header: + +```php +$client->api('pull_request')->reviewRequests()->configure(); +``` + +### List all review requests + +```php +$reviewRequests = $client->api('pull_request')->reviewRequests()->all('twbs', 'bootstrap', 12); +``` + +### Create a review request + +```php +$client->api('pull_request')->reviewRequests()->create('twbs', 'bootstrap', 12, array('user1', 'user2')); +``` + +### Remove a review request + +```php +$client->api('pull_request')->reviewRequests()->remove('twbs', 'bootstrap', 12, array('user1', 'user2')); +``` diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 52cc77fe348..c732b362b09 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -4,6 +4,7 @@ use Github\Api\PullRequest\Comments; use Github\Api\PullRequest\Review; +use Github\Api\PullRequest\ReviewRequest; use Github\Exception\MissingArgumentException; /** @@ -71,6 +72,11 @@ public function reviews() return new Review($this->client); } + public function reviewRequests() + { + return new ReviewRequest($this->client); + } + /** * Create a pull request. * diff --git a/lib/Github/Api/PullRequest/Review.php b/lib/Github/Api/PullRequest/Review.php index 8977bddf8dd..fdbf8d1e5bc 100644 --- a/lib/Github/Api/PullRequest/Review.php +++ b/lib/Github/Api/PullRequest/Review.php @@ -3,6 +3,7 @@ namespace Github\Api\PullRequest; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; @@ -14,6 +15,15 @@ */ class Review extends AbstractApi { + use AcceptHeaderTrait; + + public function configure() + { + $this->acceptHeaderValue = 'application/vnd.github.black-cat-preview+json'; + + return $this; + } + /** * Get a listing of a pull request's reviews by the username, repository and pull request number. * diff --git a/lib/Github/Api/PullRequest/ReviewRequest.php b/lib/Github/Api/PullRequest/ReviewRequest.php new file mode 100644 index 00000000000..a8b454b93d3 --- /dev/null +++ b/lib/Github/Api/PullRequest/ReviewRequest.php @@ -0,0 +1,66 @@ +acceptHeaderValue = 'application/vnd.github.black-cat-preview+json'; + + return $this; + } + + /** + * @link https://developer.github.com/v3/pulls/review_requests/#list-review-requests + * + * @param string $username + * @param string $repository + * @param int $pullRequest + * @param array $params + * + * @return array + */ + public function all($username, $repository, $pullRequest, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', $params); + } + + /** + * @link https://developer.github.com/v3/pulls/review_requests/#create-a-review-request + * + * @param string $username + * @param string $repository + * @param int $pullRequest + * @param array $reviewers + * + * @return string + */ + public function create($username, $repository, $pullRequest, array $reviewers) + { + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]); + } + + /** + * @link https://developer.github.com/v3/pulls/review_requests/#delete-a-review-request + * + * @param string $username + * @param string $repository + * @param int $pullRequest + * @param array $reviewers + * + * @return string + */ + public function remove($username, $repository, $pullRequest, array $reviewers) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/requested_reviewers', ['reviewers' => $reviewers]); + } +} diff --git a/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php b/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php new file mode 100644 index 00000000000..f6d98cb3a77 --- /dev/null +++ b/test/Github/Tests/Api/PullRequest/ReviewRequestTest.php @@ -0,0 +1,65 @@ + 80], + ['id' => 81], + ]; + + $api = $this->getApiMock(); + $api + ->expects($this->once()) + ->method('get') + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers') + ->willReturn($expectedValue); + + $this->assertSame($expectedValue, $api->all('octocat', 'Hello-World', 12)); + } + + /** + * @test + */ + public function shouldCreateReviewRequest() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser']]) + ; + + $api->create('octocat', 'Hello-World', 12, ['testuser']); + } + + /** + * @test + */ + public function shouldDeleteReviewRequest() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/octocat/Hello-World/pulls/12/requested_reviewers', ['reviewers' => ['testuser']]) + ; + + $api->remove('octocat', 'Hello-World', 12, ['testuser']); + } + + /** + * @return string + */ + protected function getApiClass() + { + return ReviewRequest::class; + } +}