Skip to content

Commit ff0fb37

Browse files
committed
Added Org & Repository varaibles
1 parent fcc99dd commit ff0fb37

File tree

7 files changed

+695
-0
lines changed

7 files changed

+695
-0
lines changed

doc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ v3 APIs:
3939
* [Organization](organization.md)
4040
* [Members](organization/members.md)
4141
* [Teams](organization/teams.md)
42+
* [Secrets](organization/actions/secrets.md)
43+
* [Variables](organization/actions/variables.md)
4244
* [Projects](project/projects.md)
4345
* [Columns](project/columns.md)
4446
* [Cards](project/cards.md)
@@ -51,6 +53,7 @@ v3 APIs:
5153
* Actions
5254
* [Artifacts](repo/actions/artifacts.md)
5355
* [Secrets](repo/actions/secrets.md)
56+
* [Variables](repo/actions/variables.md)
5457
* [Self hosted runners](repo/actions/self_hosted_runners.md)
5558
* [Workflow jobs](repo/actions/workflow_jobs.md)
5659
* [Workflow runs](repo/actions/workflow_runs.md)

doc/organization/actions/variables.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
## Organization / Variables API
2+
[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md)
3+
4+
### List organization variables
5+
6+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-organization-variables
7+
8+
```php
9+
$variables = $client->organization()->variables()->all('KnpLabs');
10+
```
11+
12+
### Get an organization variable
13+
14+
https://docs.github.com/en/rest/reference/actions#get-an-organization-secret
15+
16+
```php
17+
$variable = $client->organization()->variables()->show('KnpLabs', $variableName);
18+
```
19+
20+
### Create an organization variable
21+
22+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable
23+
24+
```php
25+
$client->organization()->variables()->create('KnpLabs', [
26+
'name' => $name,
27+
'value' => $value,
28+
'visibility' => $visibility,
29+
'selected_repository_ids' => $selectedRepositoryIds,
30+
]);
31+
```
32+
33+
### Update an organization variable
34+
35+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable
36+
37+
```php
38+
$client->organization()->variables()->update('KnpLabs', $variableName, [
39+
'name' => $name,
40+
'value' => $value,
41+
'visibility' => $visibility,
42+
'selected_repository_ids' => $selectedRepositoryIds
43+
]);
44+
```
45+
46+
### Delete an organization variable
47+
48+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable
49+
50+
```php
51+
$client->organization()->variables()->remove('KnpLabs', $variableName);
52+
```
53+
54+
### List selected repositories for organization variable
55+
56+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable
57+
58+
```php
59+
$client->organization()->variables()->selectedRepositories('KnpLabs', $variableName);
60+
```
61+
62+
### Set selected repositories for an organization variable
63+
64+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable
65+
66+
```php
67+
$client->organization()->variables()->setSelectedRepositories('KnpLabs', 'variableName', [
68+
'selected_repository_ids' => [1, 2, 3],
69+
]);
70+
```
71+
72+
### Add selected repository to an organization variable
73+
74+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable
75+
76+
```php
77+
$client->organization()->variables()->addRepository('KnpLabs', $repositoryId, $variableName);
78+
```
79+
80+
### Remove selected repository from an organization variable
81+
82+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable
83+
84+
```php
85+
$client->organization()->variables()->removeRepository('KnpLabs', $repositoryId, $variableName);
86+
```
87+

doc/repo/actions/variables.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Repo / Actions / Variables API
2+
[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md)
3+
4+
### List repository variables
5+
6+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-repository-variables
7+
8+
```php
9+
$variables = $client->api('repo')->variables()->all('KnpLabs', 'php-github-api');
10+
```
11+
12+
### Get a repository variable
13+
14+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable
15+
16+
```php
17+
$variable = $client->api('repo')->variables()->show('KnpLabs', 'php-github-api', $variableName);
18+
```
19+
20+
### Create a repository variable
21+
22+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable
23+
24+
```php
25+
$client->api('repo')->variables()->create('KnpLabs', 'php-github-api', [
26+
'name' => $name,
27+
'value' => $value,
28+
]);
29+
```
30+
31+
### Update a repository variable
32+
33+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable
34+
35+
```php
36+
$client->api('repo')->variables()->update('KnpLabs', 'php-github-api', $variableName, [
37+
'name' => $name,
38+
'value' => $value,
39+
]);
40+
```
41+
42+
### Delete a repository variable
43+
44+
https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable
45+
46+
```php
47+
$client->api('repo')->variables()->remove('KnpLabs', 'php-github-api', $variableName);
48+
```
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
namespace Github\Api\Organization\Actions;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Exception\MissingArgumentException;
7+
8+
/**
9+
* @link https://docs.github.com/en/rest/reference/actions#variables
10+
*/
11+
class Variables extends AbstractApi
12+
{
13+
/**
14+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-organization-variables
15+
*
16+
* @param string $organization
17+
*
18+
* @return array|string
19+
*/
20+
public function all(string $organization)
21+
{
22+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables');
23+
}
24+
25+
/**
26+
* @link https://docs.github.com/en/rest/reference/actions#get-an-organization-secret
27+
*
28+
* @param string $organization
29+
* @param string $variableName
30+
*
31+
* @return array|string
32+
*/
33+
public function show(string $organization, string $variableName)
34+
{
35+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName));
36+
}
37+
38+
/**
39+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable
40+
*
41+
* @param string $organization
42+
* @param array $parameters
43+
*
44+
* @throws MissingArgumentException
45+
*
46+
* @return array|string
47+
*/
48+
public function create(string $organization, array $parameters)
49+
{
50+
if (!isset($parameters['name'])) {
51+
throw new MissingArgumentException(['name']);
52+
}
53+
54+
if (!isset($parameters['value'])) {
55+
throw new MissingArgumentException(['value']);
56+
}
57+
58+
if (!isset($parameters['visibility'])) {
59+
throw new MissingArgumentException(['visibility']);
60+
}
61+
62+
return $this->post('/orgs/'.rawurlencode($organization).'/actions/variables', $parameters);
63+
}
64+
65+
/**
66+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable
67+
*
68+
* @param string $organization
69+
* @param string $variableName
70+
* @param array $parameters
71+
*
72+
* @return array|string
73+
*/
74+
public function update(string $organization, string $variableName, array $parameters = [])
75+
{
76+
return $this->patch('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName), $parameters);
77+
}
78+
79+
/**
80+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable
81+
*
82+
* @param string $organization
83+
* @param string $variableName
84+
*
85+
* @return array|string
86+
*/
87+
public function remove(string $organization, string $variableName)
88+
{
89+
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName));
90+
}
91+
92+
/**
93+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable
94+
*
95+
* @param string $organization
96+
* @param string $variableName
97+
*
98+
* @return array|string
99+
*/
100+
public function selectedRepositories(string $organization, string $variableName)
101+
{
102+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories');
103+
}
104+
105+
/**
106+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable
107+
*
108+
* @param string $organization
109+
* @param string $variableName
110+
* @param array $parameters
111+
*
112+
* @return array|string
113+
*/
114+
public function setSelectedRepositories(string $organization, string $variableName, array $parameters = [])
115+
{
116+
if (!isset($parameters['selected_repository_ids'])) {
117+
throw new MissingArgumentException(['selected_repository_ids']);
118+
}
119+
120+
return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories', $parameters);
121+
}
122+
123+
/**
124+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable
125+
*
126+
* @param string $organization
127+
* @param string $repositoryId
128+
* @param string $variableName
129+
*
130+
* @return array|string
131+
*/
132+
public function addRepository(string $organization, int $repositoryId, string $variableName)
133+
{
134+
return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId);
135+
}
136+
137+
/**
138+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable
139+
*
140+
* @param string $organization
141+
* @param string $repositoryId
142+
* @param string $variableName
143+
*
144+
* @return array|string
145+
*/
146+
public function removeRepository(string $organization, int $repositoryId, string $variableName)
147+
{
148+
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId);
149+
}
150+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Github\Api\Repository\Actions;
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#about-variables-in-github-actions
10+
*/
11+
class Variables extends AbstractApi
12+
{
13+
/**
14+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-repository-variables
15+
*
16+
* @param string $username
17+
* @param string $repository
18+
*
19+
* @return array|string
20+
*/
21+
public function all(string $username, string $repository)
22+
{
23+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables');
24+
}
25+
26+
/**
27+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable
28+
*
29+
* @param string $username
30+
* @param string $repository
31+
* @param string $variableName
32+
*
33+
* @return array|string
34+
*/
35+
public function show(string $username, string $repository, string $variableName)
36+
{
37+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables/'.rawurlencode($variableName));
38+
}
39+
40+
/**
41+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable
42+
*
43+
* @param string $username
44+
* @param string $repository
45+
* @param array $parameters
46+
*
47+
* @return array|string
48+
*/
49+
public function create(string $username, string $repository, array $parameters = [])
50+
{
51+
if (!isset($parameters['name'])) {
52+
throw new MissingArgumentException(['name']);
53+
}
54+
55+
if (!isset($parameters['value'])) {
56+
throw new MissingArgumentException(['value']);
57+
}
58+
59+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables', $parameters);
60+
}
61+
62+
/**
63+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable
64+
*
65+
* @param string $username
66+
* @param string $repository
67+
* @param string $variableName
68+
* @param array $parameters
69+
*
70+
* @return array|string
71+
*/
72+
public function update(string $username, string $repository, string $variableName, array $parameters = [])
73+
{
74+
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables/'.rawurlencode($variableName), $parameters);
75+
}
76+
77+
/**
78+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable
79+
*
80+
* @param string $username
81+
* @param string $repository
82+
* @param string $variableName
83+
*
84+
* @return array|string
85+
*/
86+
public function remove(string $username, string $repository, string $variableName)
87+
{
88+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/actions/variables/'.rawurlencode($variableName));
89+
}
90+
}

0 commit comments

Comments
 (0)