-
-
Notifications
You must be signed in to change notification settings - Fork 598
Added missing api methods for the integrations installation api #527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,60 @@ public function createInstallationToken($installationId, $userId = null) | |
|
||
return $this->post('/installations/'.rawurlencode($installationId).'/access_tokens', $parameters); | ||
} | ||
|
||
/** | ||
* Find all installations for the authenticated integration. | ||
* | ||
* @link https://developer.github.com/v3/integrations/#find-installations | ||
* | ||
* @return array | ||
*/ | ||
public function findInstallations() | ||
{ | ||
return $this->get('/integration/installations'); | ||
} | ||
|
||
/** | ||
* List repositories that are accessible to the authenticated installation. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* @link https://developer.github.com/v3/integrations/installations/#list-repositories | ||
* | ||
* @param int $userId | ||
* | ||
* @return array | ||
*/ | ||
public function listRepositories($userId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $userId should be optional, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No if you call the api without the userId you just get a 403 error irc. The repositories are also always checked for the current installation and the repo's the user has access to. I guess github will change this api route in the future so the userId is part of the uri. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okey. Good. I guess I misunderstood the docs. |
||
{ | ||
return $this->get('/installation/repositories', ['user_id' => $userId]); | ||
} | ||
|
||
/** | ||
* Add a single repository to an installation. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* @link https://developer.github.com/v3/integrations/installations/#add-repository-to-installation | ||
* | ||
* @param int $installationId | ||
* @param int $repositoryId | ||
* | ||
* @return array | ||
*/ | ||
public function addRepository($installationId, $repositoryId) | ||
{ | ||
return $this->put('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); | ||
} | ||
|
||
/** | ||
* Remove a single repository from an installation. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
* @link https://developer.github.com/v3/integrations/installations/#remove-repository-from-installation | ||
* | ||
* @param int $installationId | ||
* @param int $repositoryId | ||
* | ||
* @return array | ||
*/ | ||
public function removeRepository($installationId, $repositoryId) | ||
{ | ||
return $this->delete('/installations/'.rawurlencode($installationId).'/repositories/'.rawurlencode($repositoryId)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api; | ||
|
||
class IntegrationTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldFindRepositoriesForIntegration() | ||
{ | ||
$result = ['installation1', 'installation2']; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/integration/installations') | ||
->willReturn($result); | ||
|
||
$this->assertEquals($result, $api->findInstallations()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetRepositoriesFromInstallation() | ||
{ | ||
$result = ['repo1', 'repo2']; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/installation/repositories', ['user_id' => '1234']) | ||
->willReturn($result); | ||
|
||
$this->assertEquals($result, $api->listRepositories('1234')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldAddRepositoryToInstallation() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('put') | ||
->with('/installations/1234/repositories/5678'); | ||
|
||
$api->addRepository('1234', '5678'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldRemoveRepositoryToInstallation() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/installations/1234/repositories/5678'); | ||
|
||
$api->removeRepository('1234', '5678'); | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\Integrations::class; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
@link https://developer.github.com/v3/integrations/#find-installations