From 5c3aee1f68509c91e9ae0d233f9dab37e315678a Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 20 Apr 2020 20:48:37 +0200 Subject: [PATCH 1/4] Add sort and direction for fetching organizations repos --- lib/Github/Api/Organization.php | 6 +++++- test/Github/Tests/Api/OrganizationTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 29b71d1480e..ded76c89feb 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -53,14 +53,18 @@ public function update($organization, array $params) * @param string $organization the user name * @param string $type the type of repositories * @param int $page the page + * @param string $sort sort by + * @param string $direction direction of sort, asc or desc * * @return array the repositories */ - public function repositories($organization, $type = 'all', $page = 1) + public function repositories($organization, $type = 'all', $page = 1, $sort = 'created', $direction = 'desc') { return $this->get('/orgs/'.rawurlencode($organization).'/repos', [ 'type' => $type, 'page' => $page, + 'sort' => $sort, + 'direction' => $direction ]); } diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 04f389c0337..ee6eb4425ba 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -62,7 +62,7 @@ public function shouldGetOrganizationRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1]) + ->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1, 'sort' => 'created', 'direction' => 'desc']) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('KnpLabs')); From 6aa74fbe88cb4e1fe73330622a33ba142c1f285d Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 20 Apr 2020 20:51:35 +0200 Subject: [PATCH 2/4] Fix styleci --- lib/Github/Api/Organization.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index ded76c89feb..6fbd5ca8d94 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -64,7 +64,7 @@ public function repositories($organization, $type = 'all', $page = 1, $sort = 'c 'type' => $type, 'page' => $page, 'sort' => $sort, - 'direction' => $direction + 'direction' => $direction, ]); } From 041af9203b50d43509b474c010c88f85c846dd60 Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 20 Apr 2020 21:34:50 +0200 Subject: [PATCH 3/4] Set new parameters as null instead of default values --- lib/Github/Api/Notification.php | 1 + lib/Github/Api/Organization.php | 18 +++++++++++++----- test/Github/Tests/Api/OrganizationTest.php | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/Github/Api/Notification.php b/lib/Github/Api/Notification.php index 0d73d6076c7..e8c9b246a11 100644 --- a/lib/Github/Api/Notification.php +++ b/lib/Github/Api/Notification.php @@ -23,6 +23,7 @@ class Notification extends AbstractApi * @param bool $includingRead * @param bool $participating * @param DateTime|null $since + * @param DateTime|null $before * * @return array array of notifications */ diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index 6fbd5ca8d94..e64588650fb 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -58,14 +58,22 @@ public function update($organization, array $params) * * @return array the repositories */ - public function repositories($organization, $type = 'all', $page = 1, $sort = 'created', $direction = 'desc') + public function repositories($organization, $type = 'all', $page = 1, $sort = null, $direction = null) { - return $this->get('/orgs/'.rawurlencode($organization).'/repos', [ + $parameters = [ 'type' => $type, 'page' => $page, - 'sort' => $sort, - 'direction' => $direction, - ]); + ]; + + if($sort !== null){ + $parameters['sort'] = $sort; + } + + if($direction !== null){ + $parameters['direction'] = $direction; + } + + return $this->get('/orgs/'.rawurlencode($organization).'/repos', $parameters); } /** diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index ee6eb4425ba..04f389c0337 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -62,7 +62,7 @@ public function shouldGetOrganizationRepositories() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1, 'sort' => 'created', 'direction' => 'desc']) + ->with('/orgs/KnpLabs/repos', ['type' => 'all', 'page' => 1]) ->will($this->returnValue($expectedArray)); $this->assertEquals($expectedArray, $api->repositories('KnpLabs')); From 304bd1904214aa220ea94ee90f804ed527d8bb7d Mon Sep 17 00:00:00 2001 From: Pierre Grimaud Date: Mon, 20 Apr 2020 21:35:58 +0200 Subject: [PATCH 4/4] Fix styleci --- lib/Github/Api/Organization.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index e64588650fb..32eba7d2d87 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -65,11 +65,11 @@ public function repositories($organization, $type = 'all', $page = 1, $sort = nu 'page' => $page, ]; - if($sort !== null){ + if ($sort !== null) { $parameters['sort'] = $sort; } - if($direction !== null){ + if ($direction !== null) { $parameters['direction'] = $direction; }