Skip to content

Commit 5de0a80

Browse files
author
Benoit Del Basso
committed
add the ability to fetch repositories for a specific installation and
user
1 parent 155bc01 commit 5de0a80

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

doc/integrations.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ $token = $client->api('integrations')->createInstallationToken(123, 456);
1818

1919
Find all installations for the authenticated integration.
2020
```php
21-
Installations = $client->api('integrations')->findInstallations();
21+
$installations = $client->api('integrations')->findInstallations();
22+
```
23+
24+
### Find installations for a user
25+
26+
```php
27+
$installations = $client->api('current_user')->installations();
2228
```
2329

2430
### List repositories
@@ -28,6 +34,12 @@ List repositories that are accessible to the authenticated installation.
2834
$repositories = $client->api('integrations')->listRepositories(456);
2935
```
3036

37+
### List repositories for a given installation and user
38+
39+
```
40+
$repositories = $client->api('current_user')->repositoriesByInstallation(456);
41+
```
42+
3143
### Add repository to installation
3244
Add a single repository to an installation.
3345
```php

lib/Github/Api/CurrentUser.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,15 @@ public function installations(array $params = array())
178178
{
179179
return $this->get('/user/installations', array_merge(array('page' => 1), $params));
180180
}
181+
182+
/**
183+
* @link https://developer.github.com/v3/integrations/installations/#list-repositories-accessible-to-the-user-for-an-installation
184+
*
185+
* @param string $installationId the ID of the Installation
186+
* @param array $params
187+
*/
188+
public function repositoriesByInstallation($installationId, array $params = array())
189+
{
190+
return $this->get(sprintf('/user/installations/%s/repositories', $installationId), array_merge(array('page' => 1), $params));
191+
}
181192
}

test/Github/Tests/Api/CurrentUserTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function shouldGetWatchedRepositories()
8787
/**
8888
* @test
8989
*/
90-
public function shouldGetInstallationsForUser()
90+
public function shouldGetInstallations()
9191
{
9292
$result = ['installation1', 'installation2'];
9393

@@ -100,6 +100,22 @@ public function shouldGetInstallationsForUser()
100100
$this->assertEquals($result, $api->installations());
101101
}
102102

103+
/**
104+
* @test
105+
*/
106+
public function shouldGetRepositoriesByInstallation()
107+
{
108+
$expectedArray = array(array('id' => 1, 'name' => 'l3l0repo'));
109+
110+
$api = $this->getApiMock();
111+
$api->expects($this->once())
112+
->method('get')
113+
->with('/user/installations/42/repositories', array('page' => 1))
114+
->will($this->returnValue($expectedArray));
115+
116+
$this->assertEquals($expectedArray, $api->repositoriesByInstallation(42));
117+
}
118+
103119
/**
104120
* @test
105121
*/

0 commit comments

Comments
 (0)