From 92f4207f3a653a70a03591adffde48d7fb1168f3 Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 18 Mar 2018 19:32:05 +0100 Subject: [PATCH] Added check to avoid github 422 error --- lib/Github/Api/CurrentUser.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 1ed98a65eae..0c858b078b4 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -119,15 +119,25 @@ public function teams() * * @return array */ - public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = 'all', $affiliation = 'owner,collaborator,organization_member') + public function repositories($type = 'owner', $sort = 'full_name', $direction = 'asc', $visibility = null, $affiliation = null) { - return $this->get('/user/repos', [ + $params = [ 'type' => $type, 'sort' => $sort, 'direction' => $direction, - 'visibility' => $visibility, - 'affiliation' => $affiliation, - ]); + ]; + + if (null !== $visibility) { + unset($params['type']); + $params['visibility'] = $visibility; + } + + if (null !== $affiliation) { + unset($params['type']); + $params['affiliation'] = $affiliation; + } + + return $this->get('/user/repos', $params); } /**