Skip to content

Commit acc0453

Browse files
authored
feature KnpLabs#1104 Added environment variables & secrets (Froxz)
This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- Added environment: [Secrets](https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#list-environment-secrets) [Variables](https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables) Commits ------- 7de0912 Added environment variables & secrets d08d18d fixes for styleCI 3f4fff0 removed rawurlencode for repo id 289c0ab added link to secrets and varaibles cbf08fc Removed validation of parameters
1 parent 8168261 commit acc0453

File tree

9 files changed

+515
-0
lines changed

9 files changed

+515
-0
lines changed

doc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ v3 APIs:
5959
* [Check Suites](repo/check_suites.md)
6060
* [Contents](repo/contents.md)
6161
* [Deployments](repo/deployments.md)
62+
* [Secrets](environment/secrets.md)
63+
* [Variables](environment/variables.md)
6264
* [Environments](repo/environments.md)
6365
* [Labels](repo/labels.md)
6466
* [Protection](repo/protection.md)

doc/environment/secrets.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Environment / Secrets API
2+
[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md)
3+
4+
### List environment secrets
5+
6+
https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28
7+
8+
```php
9+
$secrets = $client->environment()->secrets()->all($repoId, $envName);
10+
```
11+
12+
### Get an environment secret
13+
14+
https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret
15+
16+
```php
17+
$secret = $client->environment()->secrets()->show($repoId, $envName, $secretName);
18+
```
19+
20+
### Create or Update an environment secret
21+
22+
https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret
23+
24+
```php
25+
$client->environment()->secrets()->createOrUpdate($repoId, $envName, $secretName, [
26+
'encrypted_value' => $encryptedValue,
27+
'key_id' => $key_id
28+
]);
29+
```
30+
31+
### Delete an environment secret
32+
33+
https://docs.github.com/en/rest/reference/actions#delete-an-organization-secret
34+
35+
```php
36+
$client->environment()->secrets()->remove($repoId, $envName, $secretName);
37+
```
38+
39+
### Get an environment public key
40+
41+
https://docs.github.com/en/rest/reference/actions#get-an-organization-public-key
42+
43+
```php
44+
$client->environment()->secrets()->publicKey($repoId, $envName);
45+
```
46+

doc/environment/variables.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Environment / Variables API
2+
[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md)
3+
4+
### List environment variables
5+
6+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables
7+
8+
```php
9+
$variables = $client->environment()->variables()->all($repoId, $envName);
10+
```
11+
12+
### Get an environment variable
13+
14+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable
15+
16+
```php
17+
$variable = $client->environment()->variables()->show($repoId, $envName, $variableName);
18+
```
19+
20+
### Create environment variable
21+
22+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable
23+
24+
```php
25+
$client->environment()->variables()->create($repoId, $envName, [
26+
'name' => $name,
27+
'value' => $value
28+
]);
29+
```
30+
31+
### Update environment variable
32+
33+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable
34+
35+
```php
36+
$client->environment()->variables()->update($repoId, $envName, $variableName, [
37+
'name' => $name,
38+
'value' => $value
39+
]);
40+
```
41+
42+
### Delete an environment variable
43+
44+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable
45+
46+
```php
47+
$client->environment()->variables()->remove($repoId, $envName, $variableName);
48+
```
49+

doc/repo/environments.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28).
55

6+
Additional APIs:
7+
* [Secrets API](environment/secrets.md)
8+
* [Variables API](environment/variables.md)
9+
610
#### List all environments.
711

812
```php

lib/Github/Api/Environment.php

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

33
namespace Github\Api;
44

5+
use Github\Api\Environment\Secrets;
6+
use Github\Api\Environment\Variables;
7+
58
/**
69
* Listing, creating and updating environments.
710
*
@@ -67,4 +70,20 @@ public function remove(string $username, string $repository, string $name)
6770
{
6871
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.rawurlencode($name));
6972
}
73+
74+
/**
75+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#about-secrets-in-github-actions
76+
*/
77+
public function secrets(): Secrets
78+
{
79+
return new Secrets($this->getClient());
80+
}
81+
82+
/**
83+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#about-variables-in-github-actions
84+
*/
85+
public function variables(): Variables
86+
{
87+
return new Variables($this->getClient());
88+
}
7089
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace Github\Api\Environment;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28
9+
*/
10+
class Secrets extends AbstractApi
11+
{
12+
/**
13+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#list-environment-secrets
14+
*
15+
* @param int $id
16+
* @param string $name
17+
*
18+
* @return array|string
19+
*/
20+
public function all(int $id, string $name)
21+
{
22+
return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets');
23+
}
24+
25+
/**
26+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret
27+
*
28+
* @param int $id
29+
* @param string $name
30+
* @param string $secretName
31+
*
32+
* @return array|string
33+
*/
34+
public function show(int $id, string $name, string $secretName)
35+
{
36+
return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName));
37+
}
38+
39+
/**
40+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret
41+
*
42+
* @param int $id
43+
* @param string $name
44+
* @param string $secretName
45+
* @param array $parameters
46+
*
47+
* @return array|string
48+
*/
49+
public function createOrUpdate(int $id, string $name, string $secretName, array $parameters = [])
50+
{
51+
return $this->put('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName), $parameters);
52+
}
53+
54+
/**
55+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#delete-an-environment-secret
56+
*
57+
* @param int $id
58+
* @param string $name
59+
* @param string $secretName
60+
*
61+
* @return array|string
62+
*/
63+
public function remove(int $id, string $name, string $secretName)
64+
{
65+
return $this->delete('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName));
66+
}
67+
68+
/**
69+
* @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-public-key
70+
*
71+
* @param int $id
72+
* @param string $name
73+
*
74+
* @return array|string
75+
*/
76+
public function publicKey(int $id, string $name)
77+
{
78+
return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/public-key');
79+
}
80+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
namespace Github\Api\Environment;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28
9+
*/
10+
class Variables extends AbstractApi
11+
{
12+
/**
13+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables
14+
*
15+
* @param int $id
16+
* @param string $name
17+
*
18+
* @return array|string
19+
*/
20+
public function all(int $id, string $name)
21+
{
22+
return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables');
23+
}
24+
25+
/**
26+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable
27+
*
28+
* @param int $id
29+
* @param string $name
30+
* @param string $variableName
31+
*
32+
* @return array|string
33+
*/
34+
public function show(int $id, string $name, string $variableName)
35+
{
36+
return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName));
37+
}
38+
39+
/**
40+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable
41+
*
42+
* @param int $id
43+
* @param string $name
44+
* @param array $parameters
45+
*
46+
* @return array|string
47+
*/
48+
public function create(int $id, string $name, array $parameters)
49+
{
50+
return $this->post('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables', $parameters);
51+
}
52+
53+
/**
54+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable
55+
*
56+
* @param int $id
57+
* @param string $name
58+
* @param string $variableName
59+
* @param array $parameters
60+
*
61+
* @return array|string
62+
*/
63+
public function update(int $id, string $name, string $variableName, array $parameters)
64+
{
65+
return $this->patch('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName), $parameters);
66+
}
67+
68+
/**
69+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable
70+
*
71+
* @param int $id
72+
* @param string $name
73+
* @param string $variableName
74+
*
75+
* @return array|string
76+
*/
77+
public function remove(int $id, string $name, string $variableName)
78+
{
79+
return $this->delete('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName));
80+
}
81+
}

0 commit comments

Comments
 (0)