-
-
Notifications
You must be signed in to change notification settings - Fork 598
Added environments #1103
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
Merged
Merged
Added environments #1103
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
75c7930
Added environments
SergkeiM 329c72f
environment
SergkeiM b163de2
fixes
SergkeiM e9da726
fixes
SergkeiM 536ac08
Fixed Tests
SergkeiM 48da337
Fixed tests
SergkeiM 6c79b05
Removed trait for custom beta accept header,
SergkeiM 7c97a2c
removed unready changes
SergkeiM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
<?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 | ||
{ | ||
use AcceptHeaderTrait; | ||
|
||
/** | ||
* 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 hidden or 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 hidden or 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->create('KnpLabs', 'php-github-api'); | ||
} | ||
|
||
/** | ||
* @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 = ['name' => 123]; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/environments/123') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDeleteEnvironment() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/repos/KnpLabs/php-github-api/environments/123') | ||
->will($this->returnValue(null)); | ||
|
||
$this->assertNull($api->remove('KnpLabs', 'php-github-api', 123)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\Environment::class; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.