From 4bf2472b2828caf2dcbbb20fe4ce364f1eab8b54 Mon Sep 17 00:00:00 2001 From: Justin Burger Date: Wed, 22 May 2013 12:49:23 -0700 Subject: [PATCH] Fixed issue where some repositories were not returned The newer versions of the Github API includes pagination. It means, without passing per_page, it's defaulting to the first 25 items. This causes issues if a user has more than 25 repositories. Or more than 25 open pull requests. --- .gitignore | 18 ++++++++++++++++++ lib/Github/Client.php | 2 ++ lib/Github/HttpClient/HttpClient.php | 8 +++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fbeabd9bcd2..f1d7db7f73f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,21 @@ phpunit.xml composer.lock composer.phar vendor/* + +.idea/.name + +.idea/encodings.xml + +.idea/misc.xml + +.idea/modules.xml + +.idea/php-github-api.iml + +.idea/scopes/scope_settings.xml + +.idea/vcs.xml + +.idea/workspace.xml + +test_client.php diff --git a/lib/Github/Client.php b/lib/Github/Client.php index cafe5554186..b690dd76444 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -55,6 +55,8 @@ class Client 'api_limit' => 5000, 'api_version' => 'beta', + 'per_page' => 500, + 'cache_dir' => null ); diff --git a/lib/Github/HttpClient/HttpClient.php b/lib/Github/HttpClient/HttpClient.php index ef82a2a0044..dc9b5db5ec0 100644 --- a/lib/Github/HttpClient/HttpClient.php +++ b/lib/Github/HttpClient/HttpClient.php @@ -34,6 +34,8 @@ class HttpClient implements HttpClientInterface 'api_limit' => 5000, 'api_version' => 'beta', + 'per_page' => 500, + 'cache_dir' => null ); /** @@ -119,10 +121,15 @@ public function addListener(ListenerInterface $listener) */ public function get($path, array $parameters = array(), array $headers = array()) { + if(is_int($this->options['per_page']) && $this->options['per_page'] > 0){ + $parameters['per_page'] = $this->options['per_page']; + } + if (0 < count($parameters)) { $path .= (false === strpos($path, '?') ? '?' : '&').http_build_query($parameters, '', '&'); } + return $this->request($path, array(), 'GET', $headers); } @@ -164,7 +171,6 @@ public function put($path, array $parameters = array(), array $headers = array() public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) { $path = trim($this->options['base_url'].$path, '/'); - $request = $this->createRequest($httpMethod, $path); $request->addHeaders($headers); if (count($parameters) > 0) {