Skip to content

Commit 275ce09

Browse files
pbarsalloacrobat
authored andcommitted
Add Ability to Update a Pull Request Review (KnpLabs#792)
* Add Ability to Update Pull Request Review * test case * stycle ci fixes * docs
1 parent 8c26dc8 commit 275ce09

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

doc/pull_request/reviews.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ $client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $review
4444
```php
4545
$client->api('pull_request')->reviews()->remove('twbs', 'bootstrap', 12, $reviewId);
4646
```
47+
48+
### Update a review
49+
```php
50+
$client->api('pull_request')->reviews()->update('twbs', 'bootstrap', 12, $reviewId, 'Review body (mandatory)')
51+
```

lib/Github/Api/PullRequest/Review.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,32 @@ public function dismiss($username, $repository, $pullRequest, $id, $message)
174174
'message' => $message,
175175
]);
176176
}
177+
178+
/**
179+
* Update a pull request review by the username, repository, pull request number and the review id.
180+
*
181+
* @link https://developer.github.com/v3/pulls/reviews/#update-a-pull-request-review
182+
*
183+
* @param string $username the username
184+
* @param string $repository the repository
185+
* @param int $pullRequest the pull request number
186+
* @param int $id the review id
187+
* @param string $body a mandatory dismissal message
188+
*
189+
* @return array|string
190+
*/
191+
public function update($username, $repository, $pullRequest, $id, $body)
192+
{
193+
if (!is_string($body)) {
194+
throw new InvalidArgumentException(sprintf('"body" must be a valid string ("%s" given).', gettype($body)));
195+
}
196+
197+
if (empty($body)) {
198+
throw new InvalidArgumentException('"body" is mandatory and cannot be empty');
199+
}
200+
201+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$pullRequest.'/reviews/'.$id, [
202+
'body' => $body,
203+
]);
204+
}
177205
}

test/Github/Tests/Api/PullRequest/ReviewTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,59 @@ public function shouldDismissReview()
394394
$this->assertSame($expectedValue, $api->dismiss('octocat', 'Hello-World', 12, 80, 'Dismiss reason'));
395395
}
396396

397+
/**
398+
* @test
399+
*/
400+
public function shouldUpdateReviewComment()
401+
{
402+
$expectedValue = [
403+
'id' => 80,
404+
'node_id' => 'MDE3OlB1bGxSZXF1ZXN0UmV2aWV3ODA=',
405+
'user' => [
406+
'login' => 'octocat',
407+
'id' => 1,
408+
'avatar_url' => 'https://github.com/images/error/octocat_happy.gif',
409+
'gravatar_id' => '',
410+
'url' => 'https://api.github.com/users/octocat',
411+
'html_url' => 'https://github.com/octocat',
412+
'followers_url' => 'https://api.github.com/users/octocat/followers',
413+
'following_url' => 'https://api.github.com/users/octocat/following{/other_user}',
414+
'gists_url' => 'https://api.github.com/users/octocat/gists{/gist_id}',
415+
'starred_url' => 'https://api.github.com/users/octocat/starred{/owner}{/repo}',
416+
'subscriptions_url' => 'https://api.github.com/users/octocat/subscriptions',
417+
'organizations_url' => 'https://api.github.com/users/octocat/orgs',
418+
'repos_url' => 'https://api.github.com/users/octocat/repos',
419+
'events_url' => 'https://api.github.com/users/octocat/events{/privacy}',
420+
'received_events_url' => 'https://api.github.com/users/octocat/received_events',
421+
'type' => 'User',
422+
'site_admin' => false,
423+
],
424+
'body' => 'Great stuff',
425+
'commit_id' => 'ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091',
426+
'state' => 'CHANGES_REQUESTED',
427+
'html_url' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80',
428+
'pull_request_url' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12',
429+
'_links' => [
430+
'html' => [
431+
'href' => 'https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80',
432+
],
433+
'pull_request' => [
434+
'href' => 'https://api.github.com/repos/octocat/Hello-World/pulls/12',
435+
],
436+
],
437+
];
438+
$body = 'Nice change';
439+
440+
$api = $this->getApiMock();
441+
$api
442+
->expects($this->once())
443+
->method('put')
444+
->with('/repos/octocat/Hello-World/pulls/12/reviews/80')
445+
->willReturn($expectedValue);
446+
447+
$this->assertSame($expectedValue, $api->update('octocat', 'Hello-World', 12, 80, $body));
448+
}
449+
397450
protected function getApiClass()
398451
{
399452
return Review::class;

0 commit comments

Comments
 (0)