Skip to content

Commit 6f89e35

Browse files
committed
Added missing api methods for the integrations installation api
1 parent e94ce3d commit 6f89e35

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed

doc/integrations.md

+26
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,29 @@ To create an access token on behalf of a user with id 456 use:
1313
```php
1414
$token = $client->api('integrations')->createInstallationToken(123, 456);
1515
```
16+
17+
### Find all installations
18+
19+
Find all installations for the authenticated integration.
20+
```php
21+
Installations = $client->api('integrations')->findInstallations();
22+
```
23+
24+
### List repositories
25+
26+
List repositories that are accessible to the authenticated installation.
27+
```php
28+
$repositories = $client->api('integrations')->listRepositories(456);
29+
```
30+
31+
### Add repository to installation
32+
Add a single repository to an installation.
33+
```php
34+
$client->api('integrations')->addRepository(123);
35+
```
36+
37+
### Remove repository from installation
38+
Remove a single repository from an installation.
39+
```php
40+
$client->api('integrations')->removeRepository(123);
41+
```

lib/Github/Api/Integrations.php

+56
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,60 @@ public function createInstallationToken($installationId, $userId = null)
2626

2727
return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
2828
}
29+
30+
/**
31+
* Find all installations for the authenticated integration.
32+
*
33+
* @link https://developer.github.com/v3/integrations/#find-installations
34+
*
35+
* @return array
36+
*/
37+
public function findInstallations()
38+
{
39+
return $this->get('/integration/installations');
40+
}
41+
42+
/**
43+
* List repositories that are accessible to the authenticated installation.
44+
*
45+
* @link https://developer.github.com/v3/integrations/installations/#list-repositories
46+
*
47+
* @param int $userId
48+
*
49+
* @return array
50+
*/
51+
public function listRepositories($userId)
52+
{
53+
return $this->get('/installation/repositories', ['user_id' => $userId]);
54+
}
55+
56+
/**
57+
* Add a single repository to an installation.
58+
*
59+
* @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation
60+
*
61+
* @param int $installationId
62+
* @param int $repositoryId
63+
*
64+
* @return array
65+
*/
66+
public function addRepository($installationId, $repositoryId)
67+
{
68+
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
69+
}
70+
71+
/**
72+
* Remove a single repository from an installation.
73+
*
74+
* @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation
75+
*
76+
* @param int $installationId
77+
* @param int $repositoryId
78+
*
79+
* @return array
80+
*/
81+
public function removeRepository($installationId, $repositoryId)
82+
{
83+
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
84+
}
2985
}

lib/Github/Client.php

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* @method Api\GitData gitData()
2828
* @method Api\Gists gist()
2929
* @method Api\Gists gists()
30+
* @method Api\Integrations integration()
31+
* @method Api\Integrations integrations()
3032
* @method Api\Issue issue()
3133
* @method Api\Issue issues()
3234
* @method Api\Markdown markdown()
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
class IntegrationTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldFindRepositoriesForIntegration()
11+
{
12+
$result = ['installation1', 'installation2'];
13+
14+
$api = $this->getApiMock();
15+
$api->expects($this->once())
16+
->method('get')
17+
->with('/integration/installations')
18+
->willReturn($result);
19+
20+
$this->assertEquals($result, $api->findInstallations());
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function shouldGetRepositoriesFromInstallation()
27+
{
28+
$result = ['repo1', 'repo2'];
29+
30+
$api = $this->getApiMock();
31+
$api->expects($this->once())
32+
->method('get')
33+
->with('/installation/repositories', ['user_id' => '1234'])
34+
->willReturn($result);
35+
36+
$this->assertEquals($result, $api->listRepositories('1234'));
37+
}
38+
39+
/**
40+
* @test
41+
*/
42+
public function shouldAddRepositoryToInstallation()
43+
{
44+
$api = $this->getApiMock();
45+
$api->expects($this->once())
46+
->method('put')
47+
->with('/installations/1234/repositories/5678');
48+
49+
$api->addRepository('1234', '5678');
50+
}
51+
52+
/**
53+
* @test
54+
*/
55+
public function shouldRemoveRepositoryToInstallation()
56+
{
57+
$api = $this->getApiMock();
58+
$api->expects($this->once())
59+
->method('delete')
60+
->with('/installations/1234/repositories/5678');
61+
62+
$api->removeRepository('1234', '5678');
63+
}
64+
65+
66+
/**
67+
* @return string
68+
*/
69+
protected function getApiClass()
70+
{
71+
return \Github\Api\Integrations::class;
72+
}
73+
}

0 commit comments

Comments
 (0)