From 5de0a80e0c5bfbe0fb17ef44f0147eea3a4d5db1 Mon Sep 17 00:00:00 2001 From: Benoit Del Basso Date: Thu, 4 May 2017 22:41:00 +0800 Subject: [PATCH] add the ability to fetch repositories for a specific installation and user --- doc/integrations.md | 14 +++++++++++++- lib/Github/Api/CurrentUser.php | 11 +++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 18 +++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/doc/integrations.md b/doc/integrations.md index f3b1c1e8c6c..6e7413dde1d 100644 --- a/doc/integrations.md +++ b/doc/integrations.md @@ -18,7 +18,13 @@ $token = $client->api('integrations')->createInstallationToken(123, 456); Find all installations for the authenticated integration. ```php -Installations = $client->api('integrations')->findInstallations(); +$installations = $client->api('integrations')->findInstallations(); +``` + +### Find installations for a user + +```php +$installations = $client->api('current_user')->installations(); ``` ### List repositories @@ -28,6 +34,12 @@ List repositories that are accessible to the authenticated installation. $repositories = $client->api('integrations')->listRepositories(456); ``` +### List repositories for a given installation and user + +``` +$repositories = $client->api('current_user')->repositoriesByInstallation(456); +``` + ### Add repository to installation Add a single repository to an installation. ```php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 62bb8b33610..53dfb0dc226 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -178,4 +178,15 @@ public function installations(array $params = array()) { return $this->get('/user/installations', array_merge(array('page' => 1), $params)); } + + /** + * @link https://developer.github.com/v3/integrations/installations/#list-repositories-accessible-to-the-user-for-an-installation + * + * @param string $installationId the ID of the Installation + * @param array $params + */ + public function repositoriesByInstallation($installationId, array $params = array()) + { + return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(array('page' => 1), $params)); + } } diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 6a14f29d338..b93d94ed1bd 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -87,7 +87,7 @@ public function shouldGetWatchedRepositories() /** * @test */ - public function shouldGetInstallationsForUser() + public function shouldGetInstallations() { $result = ['installation1', 'installation2']; @@ -100,6 +100,22 @@ public function shouldGetInstallationsForUser() $this->assertEquals($result, $api->installations()); } + /** + * @test + */ + public function shouldGetRepositoriesByInstallation() + { + $expectedArray = array(array('id' => 1, 'name' => 'l3l0repo')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/user/installations/42/repositories', array('page' => 1)) + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->repositoriesByInstallation(42)); + } + /** * @test */