Skip to content

Commit 61182f4

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

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

doc/integrations.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,22 @@ 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+
### List repositories
18+
19+
List repositories that are accessible to the authenticated installation.
20+
```php
21+
$repositories = $client->api('integrations')->listRepositories(456);
22+
```
23+
24+
### Add repository to installation
25+
Add a single repository to an installation.
26+
```php
27+
$client->api('integrations')->addRepository(123);
28+
```
29+
30+
### Remove repository from installation
31+
Remove a single repository from an installation.
32+
```php
33+
$client->api('integrations')->removeRepository(123);
34+
```

lib/Github/Api/Integrations.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,42 @@ public function createInstallationToken($installationId, $userId = null)
2626

2727
return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters);
2828
}
29+
30+
/**
31+
* List repositories that are accessible to the authenticated installation.
32+
*
33+
* @param int $userId
34+
*
35+
* @return array
36+
*/
37+
public function listRepositories($userId)
38+
{
39+
return $this->get('/installation/repositories', ['user_id' => $userId]);
40+
}
41+
42+
/**
43+
* Add a single repository to an installation.
44+
*
45+
* @param int $installationId
46+
* @param int $repositoryId
47+
*
48+
* @return array
49+
*/
50+
public function addRepository($installationId, $repositoryId)
51+
{
52+
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
53+
}
54+
55+
/**
56+
* Remove a single repository from an installation.
57+
*
58+
* @param int $installationId
59+
* @param int $repositoryId
60+
*
61+
* @return array
62+
*/
63+
public function removeRepository($installationId, $repositoryId)
64+
{
65+
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId));
66+
}
2967
}

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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
class IntegrationTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldGetRepositoriesFromInstallation()
11+
{
12+
$api = $this->getApiMock();
13+
$api->expects($this->once())
14+
->method('get')
15+
->with('/installation/repositories');
16+
17+
$api->listRepositories('1234');
18+
}
19+
20+
/**
21+
* @test
22+
*/
23+
public function shouldAddRepositoryToInstallation()
24+
{
25+
$api = $this->getApiMock();
26+
$api->expects($this->once())
27+
->method('put')
28+
->with('/installations/1234/repositories/5678');
29+
30+
$api->addRepository('1234', '5678');
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function shouldRemoveRepositoryToInstallation()
37+
{
38+
$api = $this->getApiMock();
39+
$api->expects($this->once())
40+
->method('delete')
41+
->with('/installations/1234/repositories/5678');
42+
43+
$api->removeRepository('1234', '5678');
44+
}
45+
46+
47+
/**
48+
* @return string
49+
*/
50+
protected function getApiClass()
51+
{
52+
return \Github\Api\Integrations::class;
53+
}
54+
}

0 commit comments

Comments
 (0)