-
-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #1103 Added environments (Froxz)
This PR was squashed before being merged into the 3.9.x-dev branch. Discussion ---------- Added support for environments #1102 Commits ------- 75c7930 Added environments 329c72f environment b163de2 fixes e9da726 fixes 536ac08 Fixed Tests 48da337 Fixed tests 6c79b05 Removed trait for custom beta accept header, 7c97a2c removed unready changes
- Loading branch information
Showing
5 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Repo / Environments API | ||
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) | ||
|
||
Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28). | ||
|
||
#### List all environments. | ||
|
||
```php | ||
$environments = $client->api('environment')->all('KnpLabs', 'php-github-api'); | ||
``` | ||
|
||
### Get one environment. | ||
|
||
```php | ||
$environment = $client->api('environment')->show('KnpLabs', 'php-github-api', $name); | ||
``` | ||
|
||
#### Create or update environment. | ||
|
||
```php | ||
$data = $client->api('environment')->createOrUpdate('KnpLabs', 'php-github-api', $name); | ||
``` | ||
|
||
#### Delete a existing environment. | ||
|
||
```php | ||
$environment = $client->api('environment')->remove('KnpLabs', 'php-github-api', $name); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Github\Api; | ||
|
||
/** | ||
* Listing, creating and updating environments. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28# | ||
*/ | ||
class Environment extends AbstractApi | ||
{ | ||
/** | ||
* List environments for a particular repository. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28##list-environments | ||
* | ||
* @param string $username the username of the user who owns the repository | ||
* @param string $repository the name of the repository | ||
* @param array $params query parameters to filter environments by (see link) | ||
* | ||
* @return array the environments requested | ||
*/ | ||
public function all($username, $repository, array $params = []) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); | ||
} | ||
|
||
/** | ||
* Get a environment in selected repository. | ||
* | ||
* @param string $username the user who owns the repo | ||
* @param string $repository the name of the repo | ||
* @param string $name the name of the environment | ||
* | ||
* @return array | ||
*/ | ||
public function show($username, $repository, $name) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); | ||
} | ||
|
||
/** | ||
* Create or update a environment for the given username and repo. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#create-or-update-an-environment | ||
* | ||
* @param string $username the username | ||
* @param string $repository the repository | ||
* @param string $name the name of the environment | ||
* @param array $params the new environment data | ||
* | ||
* @return array information about the environment | ||
*/ | ||
public function createOrUpdate($username, $repository, $name, array $params = []) | ||
{ | ||
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments', $params); | ||
} | ||
|
||
/** | ||
* Delete a environment for the given username and repo. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#delete-an-environment | ||
* | ||
* @return mixed null on success, array on error with 'message' | ||
*/ | ||
public function remove(string $username, string $repository, string $name) | ||
{ | ||
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api; | ||
|
||
class EnvironmentTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateOrUpdateEnvironment() | ||
{ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('put') | ||
->with('/repos/KnpLabs/php-github-api/environments'); | ||
|
||
$api->createOrUpdate('KnpLabs', 'php-github-api', 'production'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetAllEnvironments() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/environments'); | ||
|
||
$api->all('KnpLabs', 'php-github-api'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldShowEnvironment() | ||
{ | ||
$expectedValue = 'production'; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/environments/production') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'production')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDeleteEnvironment() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/repos/KnpLabs/php-github-api/environments/production') | ||
->will($this->returnValue(null)); | ||
|
||
$this->assertNull($api->remove('KnpLabs', 'php-github-api', 'production')); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\Environment::class; | ||
} | ||
} |