Skip to content

Commit 4fe5c5f

Browse files
committed
Added pagination support for PullRequest
1 parent 8eafe2e commit 4fe5c5f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Github/Api/PullRequest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ class PullRequest extends AbstractApi
2121
* @param string $repository the repository
2222
* @param string $state the state of the fetched pull requests.
2323
* The API seems to automatically default to 'open'
24+
* @param integer $page the page
25+
* @param integer $perPage the per page
2426
*
2527
* @return array array of pull requests for the project
2628
*/
27-
public function all($username, $repository, $state = null)
29+
public function all($username, $repository, $state = null, $page = 1, $perPage = 30)
2830
{
29-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', array('state' => $state));
31+
$parameters = array(
32+
'page' => $page,
33+
'per_page' => $perPage,
34+
'state' => $state,
35+
);
36+
37+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/pulls', $parameters);
3038
}
3139

3240
/**

test/Github/Tests/Api/PullRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function shouldGetOpenPullRequests()
3030
$api = $this->getApiMock();
3131
$api->expects($this->once())
3232
->method('get')
33-
->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open'))
33+
->with('repos/ezsystems/ezpublish/pulls', array('state' => 'open', 'per_page' => 30, 'page' => 1))
3434
->will($this->returnValue($expectedArray));
3535

3636
$this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'open'));
@@ -46,7 +46,7 @@ public function shouldGetClosedPullRequests()
4646
$api = $this->getApiMock();
4747
$api->expects($this->once())
4848
->method('get')
49-
->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed'))
49+
->with('repos/ezsystems/ezpublish/pulls', array('state' => 'closed', 'per_page' => 30, 'page' => 1))
5050
->will($this->returnValue($expectedArray));
5151

5252
$this->assertEquals($expectedArray, $api->all('ezsystems', 'ezpublish', 'closed'));

0 commit comments

Comments
 (0)