Skip to content
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

Added missing Apps endpoints #814

Merged
merged 8 commits into from
Nov 14, 2019
79 changes: 79 additions & 0 deletions lib/Github/Api/Apps.php
Expand Up @@ -53,6 +53,85 @@ public function findInstallations()
return $this->get('/app/installations');
}

/**
* Get an installation of the application.
*
* @link https://developer.github.com/v3/apps/#get-an-installation
*
* @param $installationId An integration installation id
*
* @return array
*/
public function getInstallation($installationId)
{
$this->configurePreviewHeader();

return $this->get('/app/installations/'.rawurldecode($installationId));
}

/**
* Get an installation of the application for an organization.
*
* @link https://developer.github.com/v3/apps/#get-an-organization-installation
*
* @param $org An organization
*
* @return array
*/
public function getInstallationForOrganization($org)
{
$this->configurePreviewHeader();

return $this->get('/org/'.rawurldecode($org).'/installation');
}

/**
* Get an installation of the application for a repository.
*
* @link https://developer.github.com/v3/apps/#get-a-repository-installation
*
* @param $owner the owner of a repository
* @param $repo the name of the repository
*
* @return array
*/
public function getInstallationForRepo($owner, $repo)
{
$this->configurePreviewHeader();

return $this->get('/repos/'.rawurldecode($owner).'/'.rawurldecode($repo).'/installation');
}

/**
* Get an installation of the application for a user.
*
* @link https://developer.github.com/v3/apps/#get-a-user-installation
*
* @param $username
*
* @return array
*/
public function getInstallationForUser($username)
{
$this->configurePreviewHeader();

return $this->get('/users/'.rawurldecode($username).'/installation');
}

/**
* Delete an installation of the application.
*
* @link https://developer.github.com/v3/apps/#delete-an-installation
*
* @param $installationId An integration installation id
*/
public function removeInstallation($installationId)
{
$this->configurePreviewHeader();

$this->delete('/app/installations/'.rawurldecode($installationId));
}

/**
* List repositories that are accessible to the authenticated installation.
*
Expand Down
80 changes: 79 additions & 1 deletion test/Github/Tests/Api/AppTest.php
Expand Up @@ -27,7 +27,7 @@ public function shouldCreateInstallationTokenForInstallation()
/**
* @test
*/
public function shouldFindRepositoriesForApplication()
public function shouldFindInstallationsForApplication()
{
$result = ['installation1', 'installation2'];

Expand All @@ -40,6 +40,84 @@ public function shouldFindRepositoriesForApplication()
$this->assertEquals($result, $api->findInstallations());
}

/**
* @test
*/
public function shouldGetInstallationForApplication()
{
$result = ['installation1'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/app/installations/1234')
->willReturn($result);

$this->assertEquals($result, $api->getInstallation('1234'));
}

/**
* @test
*/
public function shouldGetInstallationForOrganization()
{
$result = ['installation1'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/org/1234/installation')
->willReturn($result);

$this->assertEquals($result, $api->getInstallationForOrganization('1234'));
}

/**
* @test
*/
public function shouldGetInstallationForRepo()
{
$result = ['installation1'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/MyOrg/MyRepo/installation')
->willReturn($result);

$this->assertEquals($result, $api->getInstallationForRepo('MyOrg', 'MyRepo'));
}

/**
* @test
*/
public function shouldGetInstallationForUser()
{
$result = ['installation1'];

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/users/octocat/installation')
->willReturn($result);

$this->assertEquals($result, $api->getInstallationForUser('octocat'));
}

/**
* @test
*/
public function shouldDeleteInstallationForApplication()
{
$id = 123;
$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('/app/installations/'.$id);

$api->removeInstallation($id);
}

/**
* @test
*/
Expand Down