Skip to content

Commit 1e8d95a

Browse files
committed
Added missing api methods for the integrations installation api
1 parent 2d22344 commit 1e8d95a

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

doc/integrations.md

Lines changed: 26 additions & 0 deletions
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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,52 @@ 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+
* @return array
34+
*/
35+
public function findInstallations()
36+
{
37+
return $this->get('/integration/installations');
38+
}
39+
40+
/**
41+
* List repositories that are accessible to the authenticated installation.
42+
*
43+
* @param int $userId
44+
*
45+
* @return array
46+
*/
47+
public function listRepositories($userId)
48+
{
49+
return $this->get('/installation/repositories', ['user_id' => $userId]);
50+
}
51+
52+
/**
53+
* Add a single repository to an installation.
54+
*
55+
* @param int $installationId
56+
* @param int $repositoryId
57+
*
58+
* @return array
59+
*/
60+
public function addRepository($installationId, $repositoryId)
61+
{
62+
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
63+
}
64+
65+
/**
66+
* Remove a single repository from an installation.
67+
*
68+
* @param int $installationId
69+
* @param int $repositoryId
70+
*
71+
* @return array
72+
*/
73+
public function removeRepository($installationId, $repositoryId)
74+
{
75+
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
76+
}
2977
}

lib/Github/Client.php

Lines changed: 2 additions & 0 deletions
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()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
$api = $this->getApiMock();
13+
$api->expects($this->once())
14+
->method('get')
15+
->with('/integration/installations');
16+
17+
$api->findInstallations();
18+
}
19+
20+
/**
21+
* @test
22+
*/
23+
public function shouldGetRepositoriesFromInstallation()
24+
{
25+
$api = $this->getApiMock();
26+
$api->expects($this->once())
27+
->method('get')
28+
->with('/installation/repositories');
29+
30+
$api->listRepositories('1234');
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function shouldAddRepositoryToInstallation()
37+
{
38+
$api = $this->getApiMock();
39+
$api->expects($this->once())
40+
->method('put')
41+
->with('/installations/1234/repositories/5678');
42+
43+
$api->addRepository('1234', '5678');
44+
}
45+
46+
/**
47+
* @test
48+
*/
49+
public function shouldRemoveRepositoryToInstallation()
50+
{
51+
$api = $this->getApiMock();
52+
$api->expects($this->once())
53+
->method('delete')
54+
->with('/installations/1234/repositories/5678');
55+
56+
$api->removeRepository('1234', '5678');
57+
}
58+
59+
60+
/**
61+
* @return string
62+
*/
63+
protected function getApiClass()
64+
{
65+
return \Github\Api\Integrations::class;
66+
}
67+
}

0 commit comments

Comments
 (0)