-
-
Notifications
You must be signed in to change notification settings - Fork 598
Deployment branch policies #1108
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
acrobat
merged 7 commits into
KnpLabs:master
from
SergkeiM:feature/deployment-branch-policies
Mar 10, 2023
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9734d23
Deployment branch policies
SergkeiM c72fdae
removed params validation
SergkeiM a61fe84
StyleCI fixes
SergkeiM c30050c
styleCI fixes
SergkeiM 5d7048f
Merge branch 'master' into feature/deployment-branch-policies
SergkeiM f657c3f
StyleCi fixes
SergkeiM d9f0195
Changes to docs
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
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,38 @@ | ||
## Repo / Deployment branch policies API | ||
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md) | ||
|
||
Provides information about deployment branch policies. Wraps [GitHub Deployment branch policies API](https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#about-deployment-branch-policies). | ||
|
||
#### List deployment branch policies. | ||
|
||
```php | ||
$policies = $client->deployment()->policies()->all('KnpLabs', 'php-github-api', 'production'); | ||
``` | ||
|
||
### Get one environment. | ||
|
||
```php | ||
$policy = $client->deployment()->policies()->show('KnpLabs', 'php-github-api', 'production', $branchPolicyId); | ||
``` | ||
|
||
#### Create policy. | ||
|
||
```php | ||
$data = $client->deployment()->policies()->create('KnpLabs', 'php-github-api', 'production', [ | ||
'name' => 'name' | ||
]); | ||
``` | ||
|
||
#### Update policy. | ||
|
||
```php | ||
$data = $client->deployment()->policies()->update('KnpLabs', 'php-github-api', 'production', $branchPolicyId, [ | ||
'name' => 'name' | ||
]); | ||
``` | ||
|
||
#### Delete a existing policy. | ||
|
||
```php | ||
$policy = $client->deployment()->policies()->remove('KnpLabs', 'php-github-api', 'production', $branchPolicyId); | ||
``` |
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
6 changes: 4 additions & 2 deletions
6
lib/Github/Api/Environment.php → lib/Github/Api/Deployment/Environments.php
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,108 @@ | ||
<?php | ||
|
||
namespace Github\Api\Deployment; | ||
|
||
use Github\Api\AbstractApi; | ||
use Github\Exception\MissingArgumentException; | ||
|
||
/** | ||
* Listing, creating and updating deployments. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#list-deployment-branch-policies | ||
*/ | ||
class Policies extends AbstractApi | ||
{ | ||
/** | ||
* List deployment branch policies | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#list-deployment-branch-policies | ||
* | ||
* @param string $username the username of the user who owns the repository | ||
* @param string $repository the name of the repository | ||
* @param string $environment the name of the environment. | ||
* @param array $params query parameters to filter deployments by (see link) | ||
* | ||
* @return array the deployments requested | ||
*/ | ||
public function all(string $username, string $repository, string $environment, array $params = []) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies', $params); | ||
} | ||
|
||
/** | ||
* Get a deployment branch policy | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#get-a-deployment-branch-policy | ||
* | ||
* @param string $username the username of the user who owns the repository | ||
* @param string $repository the name of the repository | ||
* @param string $environment the name of the environment. | ||
* @param int $id The unique identifier of the branch policy. | ||
* | ||
* @return array | ||
*/ | ||
public function show(string $username, string $repository, string $environment, int $id) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id); | ||
} | ||
|
||
/** | ||
* Creates a deployment branch policy for an environment. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#create-a-deployment-branch-policy | ||
* | ||
* @param string $username the username of the user who owns the repository | ||
* @param string $repository the name of the repository | ||
* @param string $environment the name of the environment. | ||
* | ||
* @throws MissingArgumentException | ||
* | ||
* @return array information about the deployment branch policy | ||
*/ | ||
public function create(string $username, string $repository, string $environment, array $params) | ||
{ | ||
if (!isset($params['name'])) { | ||
throw new MissingArgumentException(['name']); | ||
} | ||
SergkeiM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies', $params); | ||
} | ||
|
||
/** | ||
* Updates a deployment branch policy for an environment. | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#update-a-deployment-branch-policy | ||
* | ||
* @param string $username the username of the user who owns the repository | ||
* @param string $repository the name of the repository | ||
* @param string $environment the name of the environment. | ||
* @param int $id The unique identifier of the branch policy. | ||
* | ||
* @return array information about the deployment branch policy | ||
*/ | ||
public function update(string $username, string $repository, string $environment, int $id, array $params) | ||
{ | ||
if (!isset($params['name'])) { | ||
throw new MissingArgumentException(['name']); | ||
} | ||
SergkeiM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id, $params); | ||
} | ||
|
||
/** | ||
* Delete a deployment branch policy | ||
* | ||
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#delete-a-deployment-branch-policy | ||
* | ||
* @param string $username the username of the user who owns the repository | ||
* @param string $repository the name of the repository | ||
* @param string $environment the name of the environment. | ||
* @param int $id The unique identifier of the branch policy. | ||
* | ||
* @return mixed null on success, array on error with 'message' | ||
*/ | ||
public function remove(string $username, string $repository, string $environment, int $id) | ||
{ | ||
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id); | ||
} | ||
} |
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
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,91 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\Deployment; | ||
|
||
use Github\Tests\Api\TestCase; | ||
|
||
class PoliciesTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldCreatePolicy() | ||
{ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('post') | ||
->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies'); | ||
|
||
$api->create('KnpLabs', 'php-github-api', 'production', [ | ||
'name' => 'name' | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldUpdatePolicy() | ||
{ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('put') | ||
->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies/1'); | ||
|
||
$api->update('KnpLabs', 'php-github-api', 'production', 1, [ | ||
'name' => 'name' | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetAllPolicies() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies'); | ||
|
||
$api->all('KnpLabs', 'php-github-api', 'production'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldShowPolicy() | ||
{ | ||
$expectedValue = 'production'; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies/1') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'production', 1)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDeletePolicy() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/repos/KnpLabs/php-github-api/environments/production/deployment-branch-policies/1') | ||
->will($this->returnValue(null)); | ||
|
||
$this->assertNull($api->remove('KnpLabs', 'php-github-api', 'production', 1)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\Deployment\Policies::class; | ||
} | ||
} |
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
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.