From 4fe5c5fb223cb225c2ceba1b7de699bb73c8abaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 17 May 2013 14:02:59 +0200 Subject: [PATCH] Added pagination support for PullRequest --- lib/Github/Api/PullRequest.php | 12 ++++++++++-- test/Github/Tests/Api/PullRequestTest.php | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index 5cb9b6d96ec..aed711a6c34 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -21,12 +21,20 @@ class PullRequest extends AbstractApi * @param string $repository the repository * @param string $state the state of the fetched pull requests. * The API seems to automatically default to 'open' + * @param integer $page the page + * @param integer $perPage the per page * * @return array array of pull requests for the project */ - public function all($username, $repository, $state = null) + public function all($username, $repository, $state = null, $page = 1, $perPage = 30) { - return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', array('state' => $state)); + $parameters = array( + 'page' => $page, + 'per_page' => $perPage, + 'state' => $state, + ); + + return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $parameters); } /** diff --git a/test/Github/Tests/Api/PullRequestTest.php b/test/Github/Tests/Api/PullRequestTest.php index a25943d395f..99449ec16d3 100644 --- a/test/Github/Tests/Api/PullRequestTest.php +++ b/test/Github/Tests/Api/PullRequestTest.php @@ -30,7 +30,7 @@ public function shouldGetOpenPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open')) + ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'open')); @@ -46,7 +46,7 @@ public function shouldGetClosedPullRequests() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed')) + ->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1)) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'closed'));