-
-
Notifications
You must be signed in to change notification settings - Fork 598
add support for the pull request reviews API #517
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
namespace Github\Api\PullRequest; | ||
|
||
use Github\Api\AbstractApi; | ||
use Github\Exception\InvalidArgumentException; | ||
use Github\Exception\MissingArgumentException; | ||
|
||
/** | ||
* API for accessing Pull Request Reviews from your Git/Github repositories. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/ | ||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de> | ||
*/ | ||
class Review extends AbstractApi | ||
{ | ||
/** | ||
* Get a listing of a pull request's reviews by the username, repository and pull request number. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param array $params a list of extra parameters. | ||
* | ||
* @return array array of pull request reviews for the pull request | ||
*/ | ||
public function all($username, $repository, $pullRequest, array $params = []) | ||
{ | ||
$parameters = array_merge([ | ||
'page' => 1, | ||
'per_page' => 30 | ||
], $params); | ||
|
||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $parameters); | ||
} | ||
|
||
/** | ||
* Get a single pull request review by the username, repository, pull request number and the review id. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#get-a-single-review | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param int $id the review id | ||
* | ||
* @return array the pull request review | ||
*/ | ||
public function show($username, $repository, $pullRequest, $id) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id); | ||
} | ||
|
||
/** | ||
* Delete a single pull request review by the username, repository, pull request number and the review id. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#delete-a-pending-review | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param int $id the review id | ||
* | ||
* @return array|string | ||
*/ | ||
public function remove($username, $repository, $pullRequest, $id) | ||
{ | ||
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id); | ||
} | ||
|
||
/** | ||
* Get comments for a single pull request review. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#get-comments-for-a-single-review | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param int $id the review id | ||
* | ||
* @return array|string | ||
*/ | ||
public function comments($username, $repository, $pullRequest, $id) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($pullRequest).'/reviews/'.rawurlencode($id).'/comments'); | ||
} | ||
|
||
/** | ||
* Create a pull request review by the username, repository and pull request number. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#create-a-pull-request-review | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param array $params a list of extra parameters. | ||
* | ||
* @throws MissingArgumentException | ||
* | ||
* @return array the pull request review | ||
*/ | ||
public function create($username, $repository, $pullRequest, array $params = []) | ||
{ | ||
if (!isset($params['event'])) { | ||
throw new MissingArgumentException('event'); | ||
} | ||
|
||
if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { | ||
throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); | ||
} | ||
|
||
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews', $params); | ||
} | ||
|
||
/** | ||
* Submit a pull request review by the username, repository, pull request number and the review id. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#submit-a-pull-request-review | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param int $id the review id | ||
* @param array $params a list of extra parameters. | ||
* | ||
* @throws MissingArgumentException | ||
* | ||
* @return array the pull request review | ||
*/ | ||
public function submit($username, $repository, $pullRequest, $id, array $params = []) | ||
{ | ||
if (!isset($params['event'])) { | ||
throw new MissingArgumentException('event'); | ||
} | ||
|
||
if (!in_array($params['event'], ["APPROVE", "REQUEST_CHANGES", "COMMENT"], true)) { | ||
throw new InvalidArgumentException(sprintf('"event" must be one of ["APPROVE", "REQUEST_CHANGES", "COMMENT"] ("%s" given).', $params['event'])); | ||
} | ||
|
||
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/events', $params); | ||
} | ||
|
||
/** | ||
* Dismiss a pull request review by the username, repository, pull request number and the review id. | ||
* | ||
* @link https://developer.github.com/v3/pulls/reviews/#dismiss-a-pull-request-review | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param int $pullRequest the pull request number | ||
* @param int $id the review id | ||
* | ||
* @return array|string | ||
*/ | ||
public function dismiss($username, $repository, $pullRequest, $id) | ||
{ | ||
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id.'/dismissals'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul | |
))); | ||
|
||
$this->apiVersion = $apiVersion ?: 'v3'; | ||
$builder->addHeaders(['Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion)]); | ||
$builder->addHeaderValue('Accept', sprintf('application/vnd.github.%s+json', $this->apiVersion)); | ||
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. Why? 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. Otherwise we wouldn't be able to add the custom |
||
|
||
if ($enterpriseUrl) { | ||
$this->setEnterpriseUrl($enterpriseUrl); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change is not really a part of the PR, right?
Let's keep it anyways (for this time)
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.
Actually, it's there to allow https://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository which is not directly related to the reviews, but needed if you want to fully leverage the reviews API. But I can move it to its own PR nonetheless. What do you think?
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.
Okey, I stand corrected.
Lets keep it.