Skip to content

Commit 7de0912

Browse files
committed
Added environment variables & secrets
1 parent fcc99dd commit 7de0912

File tree

8 files changed

+537
-0
lines changed

8 files changed

+537
-0
lines changed

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

0 commit comments

Comments
 (0)