Skip to content

Add Ability to Update a Pull Request Review #792

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 4 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/pull_request/reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ $client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $review
```php
$client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $reviewId);
```

### Update a review
```php
$client->api('pull_request')->reviews()->update('twbs', 'bootstrap', 12, $reviewId, 'Review body (mandatory)')
```
28 changes: 28 additions & 0 deletions lib/Github/Api/PullRequest/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,32 @@ public function dismiss($username, $repository, $pullRequest, $id, $message)
'message' => $message,
]);
}

/**
* Update a pull request review by the username, repository, pull request number and the review id.
*
* @link https://developer.github.com/v3/pulls/reviews/#update-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 string $body a mandatory dismissal message
*
* @return array|string
*/
public function update($username, $repository, $pullRequest, $id, $body)
{
if (!is_string($body)) {
throw new InvalidArgumentException(sprintf('"body" must be a valid string ("%s" given).', gettype($body)));
}

if (empty($body)) {
throw new InvalidArgumentException('"body" is mandatory and cannot be empty');
}

return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id, [
'body' => $body,
]);
}
}
53 changes: 53 additions & 0 deletions test/Github/Tests/Api/PullRequest/ReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,59 @@ public function shouldDismissReview()
$this->assertSame($expectedValue, $api->dismiss('octocat', 'Hello-World', 12, 80, 'Dismiss reason'));
}

/**
* @test
*/
public function shouldUpdateReviewComment()
{
$expectedValue = [
'id' => 80,
'node_id' => 'MDE3OlB1bGxSZXF1ZXN0UmV2aWV3ODA=',
'user' => [
'login' => 'octocat',
'id' => 1,
'avatar_url' => 'https://github.com/images/error/octocat_happy.gif',
'gravatar_id' => '',
'url' => 'https://api.github.com/users/octocat',
'html_url' => 'https://github.com/octocat',
'followers_url' => 'https://api.github.com/users/octocat/followers',
'following_url' => 'https://api.github.com/users/octocat/following{/other_user}',
'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}',
'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}',
'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions',
'organizations_url' => 'https://api.github.com/users/octocat/orgs',
'repos_url' => 'https://api.github.com/users/octocat/repos',
'events_url' => 'https://api.github.com/users/octocat/events{/privacy}',
'received_events_url' => 'https://api.github.com/users/octocat/received_events',
'type' => 'User',
'site_admin' => false,
],
'body' => 'Great stuff',
'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091',
'state' => 'CHANGES_REQUESTED',
'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80',
'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12',
'_links' => [
'html' => [
'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80',
],
'pull_request' => [
'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12',
],
],
];
$body = 'Nice change';

$api = $this->getApiMock();
$api
->expects($this->once())
->method('put')
->with('/repos/octocat/Hello-World/pulls/12/reviews/80')
->willReturn($expectedValue);

$this->assertSame($expectedValue, $api->update('octocat', 'Hello-World', 12, 80, $body));
}

protected function getApiClass()
{
return Review::class;
Expand Down