Skip to content

Commit 00570ac

Browse files
authored
feature KnpLabs#1108 Deployment branch policies (Froxz)
This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- * added Deployment branch policies * Moved environments under deployment Commits ------- 9734d23 Deployment branch policies c72fdae removed params validation a61fe84 StyleCI fixes c30050c styleCI fixes 5d7048f Merge branch 'master' into feature/deployment-branch-policies f657c3f StyleCi fixes d9f0195 Changes to docs
1 parent bdb9bfb commit 00570ac

File tree

13 files changed

+309
-46
lines changed

13 files changed

+309
-46
lines changed

doc/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ v3 APIs:
6262
* [Check Suites](repo/check_suites.md)
6363
* [Contents](repo/contents.md)
6464
* [Deployments](repo/deployments.md)
65-
* [Secrets](environment/secrets.md)
66-
* [Variables](environment/variables.md)
67-
* [Environments](repo/environments.md)
65+
* [Policies](repo/deployments/policies.md)
66+
* [Environments](repo/deployments/environments.md)
67+
* [Secrets](repo/deployments/environment/secrets.md)
68+
* [Variables](repo/deployments/environment/variables.md)
6869
* [Labels](repo/labels.md)
6970
* [Protection](repo/protection.md)
7071
* [Releases](repo/releases.md)

doc/environment/secrets.md renamed to doc/repo/deployments/environment/secrets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Environment / Secrets API
2-
[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md)
2+
[Back to the "Environments API"](../environments.md) | [Back to the navigation](../README.md)
33

44
### List environment secrets
55

doc/environment/variables.md renamed to doc/repo/deployments/environment/variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Environment / Variables API
2-
[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md)
2+
[Back to the "Environments API"](../environments.md) | [Back to the navigation](../README.md)
33

44
### List environment variables
55

doc/repo/deployments/environments.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
## Deployment / Environments API
2+
[Back to the "Deployment API"](../deployments.md) | [Back to the navigation](../index.md)
3+
4+
Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28).
5+
6+
Additional APIs:
7+
* [Secrets API](environment/secrets.md)
8+
* [Variables API](environment/variables.md)
9+
10+
#### List all environments.
11+
12+
```php
13+
$environments = $client->deployment()->environment()->all('KnpLabs', 'php-github-api');
14+
```
15+
16+
### Get one environment.
17+
18+
```php
19+
$environment = $client->deployment()->environment()->show('KnpLabs', 'php-github-api', $name);
20+
```
21+
22+
#### Create or update environment.
23+
24+
```php
25+
$data = $client->deployment()->environment()->createOrUpdate('KnpLabs', 'php-github-api', $name);
26+
```
27+
28+
#### Delete a existing environment.
29+
30+
```php
31+
$environment = $client->deployment()->environment()->remove('KnpLabs', 'php-github-api', $name);
32+
```

doc/repo/deployments/policies.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Deployment / Branch policies API
2+
[Back to the "Deployment API"](../deployments.md) | [Back to the navigation](../index.md)
3+
4+
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).
5+
6+
#### List deployment branch policies.
7+
8+
```php
9+
$policies = $client->deployment()->policies()->all('KnpLabs', 'php-github-api', 'production');
10+
```
11+
12+
### Get one environment.
13+
14+
```php
15+
$policy = $client->deployment()->policies()->show('KnpLabs', 'php-github-api', 'production', $branchPolicyId);
16+
```
17+
18+
#### Create policy.
19+
20+
```php
21+
$data = $client->deployment()->policies()->create('KnpLabs', 'php-github-api', 'production', [
22+
'name' => 'name'
23+
]);
24+
```
25+
26+
#### Update policy.
27+
28+
```php
29+
$data = $client->deployment()->policies()->update('KnpLabs', 'php-github-api', 'production', $branchPolicyId, [
30+
'name' => 'name'
31+
]);
32+
```
33+
34+
#### Delete a existing policy.
35+
36+
```php
37+
$policy = $client->deployment()->policies()->remove('KnpLabs', 'php-github-api', 'production', $branchPolicyId);
38+
```

doc/repo/environments.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/Github/Api/Deployment.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Github\Api;
44

5+
use Github\Api\Deployment\Environments;
6+
use Github\Api\Deployment\Policies;
57
use Github\Exception\MissingArgumentException;
68

79
/**
@@ -130,4 +132,20 @@ public function getStatuses($username, $repository, $id)
130132
{
131133
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/deployments/'.$id.'/statuses');
132134
}
135+
136+
/**
137+
* @return Environments
138+
*/
139+
public function environments()
140+
{
141+
return new Environments($this->getClient());
142+
}
143+
144+
/**
145+
* @return Policies
146+
*/
147+
public function policies()
148+
{
149+
return new Policies($this->getClient());
150+
}
133151
}

lib/Github/Api/Environment.php renamed to lib/Github/Api/Deployment/Environments.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
22

3-
namespace Github\Api;
3+
namespace Github\Api\Deployment;
44

5+
use Github\Api\AbstractApi;
56
use Github\Api\Environment\Secrets;
67
use Github\Api\Environment\Variables;
78

@@ -10,7 +11,7 @@
1011
*
1112
* @link https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#
1213
*/
13-
class Environment extends AbstractApi
14+
class Environments extends AbstractApi
1415
{
1516
/**
1617
* List environments for a particular repository.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Github\Api\Deployment;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* Listing, creating and updating deployments.
9+
*
10+
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#list-deployment-branch-policies
11+
*/
12+
class Policies extends AbstractApi
13+
{
14+
/**
15+
* List deployment branch policies.
16+
*
17+
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#list-deployment-branch-policies
18+
*
19+
* @param string $username the username of the user who owns the repository
20+
* @param string $repository the name of the repository
21+
* @param string $environment the name of the environment.
22+
* @param array $params query parameters to filter deployments by (see link)
23+
*
24+
* @return array the branch policies requested
25+
*/
26+
public function all(string $username, string $repository, string $environment, array $params = [])
27+
{
28+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies', $params);
29+
}
30+
31+
/**
32+
* Get a deployment branch policy.
33+
*
34+
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#get-a-deployment-branch-policy
35+
*
36+
* @param string $username the username of the user who owns the repository
37+
* @param string $repository the name of the repository
38+
* @param string $environment the name of the environment.
39+
* @param int $id the unique identifier of the branch policy.
40+
*
41+
* @return array
42+
*/
43+
public function show(string $username, string $repository, string $environment, int $id)
44+
{
45+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id);
46+
}
47+
48+
/**
49+
* Creates a deployment branch policy for an environment.
50+
*
51+
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#create-a-deployment-branch-policy
52+
*
53+
* @param string $username the username of the user who owns the repository
54+
* @param string $repository the name of the repository
55+
* @param string $environment the name of the environment.
56+
*
57+
* @return array information about the deployment branch policy
58+
*/
59+
public function create(string $username, string $repository, string $environment, array $params)
60+
{
61+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies', $params);
62+
}
63+
64+
/**
65+
* Updates a deployment branch policy for an environment.
66+
*
67+
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#update-a-deployment-branch-policy
68+
*
69+
* @param string $username the username of the user who owns the repository
70+
* @param string $repository the name of the repository
71+
* @param string $environment the name of the environment.
72+
* @param int $id the unique identifier of the branch policy.
73+
*
74+
* @return array information about the deployment branch policy
75+
*/
76+
public function update(string $username, string $repository, string $environment, int $id, array $params)
77+
{
78+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id, $params);
79+
}
80+
81+
/**
82+
* Delete a deployment branch policy.
83+
*
84+
* @link https://docs.github.com/en/rest/deployments/branch-policies?apiVersion=2022-11-28#delete-a-deployment-branch-policy
85+
*
86+
* @param string $username the username of the user who owns the repository
87+
* @param string $repository the name of the repository
88+
* @param string $environment the name of the environment.
89+
* @param int $id the unique identifier of the branch policy.
90+
*
91+
* @return mixed null on success, array on error with 'message'
92+
*/
93+
public function remove(string $username, string $repository, string $environment, int $id)
94+
{
95+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($environment).'/deployment-branch-policies/'.$id);
96+
}
97+
}

lib/Github/Client.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ public function api($name): AbstractApi
181181
$api = new Api\Deployment($this);
182182
break;
183183

184-
case 'environment':
185-
case 'environments':
186-
$api = new Api\Environment($this);
187-
break;
188-
189184
case 'ent':
190185
case 'enterprise':
191186
$api = new Api\Enterprise($this);

test/Github/Tests/Api/EnvironmentTest.php renamed to test/Github/Tests/Api/Deployment/EnvironmentsTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
namespace Github\Tests\Api;
3+
namespace Github\Tests\Api\Deployment;
4+
5+
use Github\Tests\Api\TestCase;
46

57
class EnvironmentTest extends TestCase
68
{
@@ -66,6 +68,6 @@ public function shouldDeleteEnvironment()
6668
*/
6769
protected function getApiClass()
6870
{
69-
return \Github\Api\Environment::class;
71+
return \Github\Api\Deployment\Environments::class;
7072
}
7173
}

0 commit comments

Comments
 (0)