Skip to content

Added pagination support for PullRequest #53

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 1 commit into from
Jun 5, 2013
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
12 changes: 10 additions & 2 deletions lib/Github/Api/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/Github/Tests/Api/PullRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand Down