From 1831db1bd1a673ed9f2b1c51bed1ced8b74e512f Mon Sep 17 00:00:00 2001 From: Sean Taylor Date: Fri, 20 Nov 2020 13:42:05 +0000 Subject: [PATCH] feature #938 Add parameters to PullRequest commits method (seanmtaylor) This PR was squashed before being merged into the 2.x branch. Discussion ---------- Add a `$parameters` parameter to the `PullRequest::commits()` method to allow for pagination. As per the docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#list-commits-on-a-pull-request Commits ------- 2069be213d3fc1b102a4559482a63c6260b7d550 Add parameters to PullRequest commits method 86b531f3f2e4237afeb401fc8abb8028e141f809 Add shouldShowCommitsFromPullRequestForPage --- lib/Github/Api/PullRequest.php | 4 ++-- test/Github/Tests/Api/PullRequestTest.php | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index ffc713ba4a3..fcc46c84104 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -80,9 +80,9 @@ public function show($username, $repository, $id) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.$id); } - public function commits($username, $repository, $id) + public function commits($username, $repository, $id, array $parameters = []) { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits'); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pulls/'.rawurlencode($id).'/commits', $parameters); } public function files($username, $repository, $id, array $parameters = []) diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index 660368fd4f5..90505535ff9 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -87,6 +87,22 @@ public function shouldShowCommitsFromPullRequest() $this->assertEquals($expectedArray, $api->commits('ezsystems', 'ezpublish', '15')); } + /** + * @test + */ + public function shouldShowCommitsFromPullRequestForPage() + { + $expectedArray = [['id' => 'id', 'sha' => '123123']]; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/ezsystems/ezpublish/pulls/15/commits', ['page' => 2, 'per_page' => 30]) + ->willReturn($expectedArray); + + $this->assertEquals($expectedArray, $api->commits('ezsystems', 'ezpublish', '15', ['page' => 2, 'per_page' => 30])); + } + /** * @test */