Skip to content

Commit bdb9bfb

Browse files
authored
feature KnpLabs#1106 Added Org & Repository variables (Froxz)
This PR was squashed before being merged into the 3.10.x-dev branch. Discussion ---------- Commits ------- ff0fb37 Added Org & Repository varaibles 4a50d98 fixed type hint 7569055 Fixes 37e12a6 added repo variables test 1da518f StyleCI fixes 9f90a4a Removed params validation
1 parent acc0453 commit bdb9bfb

File tree

11 files changed

+705
-0
lines changed

11 files changed

+705
-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+
```

lib/Github/Api/Organization.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\Api;
44

55
use Github\Api\Organization\Actions\Secrets;
6+
use Github\Api\Organization\Actions\Variables;
67
use Github\Api\Organization\Hooks;
78
use Github\Api\Organization\Members;
89
use Github\Api\Organization\OutsideCollaborators;
@@ -110,6 +111,14 @@ public function secrets(): Secrets
110111
return new Secrets($this->getClient());
111112
}
112113

114+
/**
115+
* @return Variables
116+
*/
117+
public function variables(): Variables
118+
{
119+
return new Variables($this->getClient());
120+
}
121+
113122
/**
114123
* @return OutsideCollaborators
115124
*/
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
namespace Github\Api\Organization\Actions;
4+
5+
use Github\Api\AbstractApi;
6+
7+
/**
8+
* @link https://docs.github.com/en/rest/reference/actions#variables
9+
*/
10+
class Variables extends AbstractApi
11+
{
12+
/**
13+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-organization-variables
14+
*
15+
* @param string $organization
16+
*
17+
* @return array|string
18+
*/
19+
public function all(string $organization)
20+
{
21+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables');
22+
}
23+
24+
/**
25+
* @link https://docs.github.com/en/rest/reference/actions#get-an-organization-secret
26+
*
27+
* @param string $organization
28+
* @param string $variableName
29+
*
30+
* @return array|string
31+
*/
32+
public function show(string $organization, string $variableName)
33+
{
34+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName));
35+
}
36+
37+
/**
38+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable
39+
*
40+
* @param string $organization
41+
* @param array $parameters
42+
*
43+
* @return array|string
44+
*/
45+
public function create(string $organization, array $parameters)
46+
{
47+
return $this->post('/orgs/'.rawurlencode($organization).'/actions/variables', $parameters);
48+
}
49+
50+
/**
51+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable
52+
*
53+
* @param string $organization
54+
* @param string $variableName
55+
* @param array $parameters
56+
*
57+
* @return array|string
58+
*/
59+
public function update(string $organization, string $variableName, array $parameters = [])
60+
{
61+
return $this->patch('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName), $parameters);
62+
}
63+
64+
/**
65+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable
66+
*
67+
* @param string $organization
68+
* @param string $variableName
69+
*
70+
* @return array|string
71+
*/
72+
public function remove(string $organization, string $variableName)
73+
{
74+
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName));
75+
}
76+
77+
/**
78+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable
79+
*
80+
* @param string $organization
81+
* @param string $variableName
82+
*
83+
* @return array|string
84+
*/
85+
public function selectedRepositories(string $organization, string $variableName)
86+
{
87+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories');
88+
}
89+
90+
/**
91+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable
92+
*
93+
* @param string $organization
94+
* @param string $variableName
95+
* @param array $parameters
96+
*
97+
* @return array|string
98+
*/
99+
public function setSelectedRepositories(string $organization, string $variableName, array $parameters = [])
100+
{
101+
return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories', $parameters);
102+
}
103+
104+
/**
105+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable
106+
*
107+
* @param string $organization
108+
* @param int $repositoryId
109+
* @param string $variableName
110+
*
111+
* @return array|string
112+
*/
113+
public function addRepository(string $organization, int $repositoryId, string $variableName)
114+
{
115+
return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId);
116+
}
117+
118+
/**
119+
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable
120+
*
121+
* @param string $organization
122+
* @param int $repositoryId
123+
* @param string $variableName
124+
*
125+
* @return array|string
126+
*/
127+
public function removeRepository(string $organization, int $repositoryId, string $variableName)
128+
{
129+
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId);
130+
}
131+
}

lib/Github/Api/Repo.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Github\Api\Repository\Actions\Artifacts;
66
use Github\Api\Repository\Actions\Secrets;
77
use Github\Api\Repository\Actions\SelfHostedRunners;
8+
use Github\Api\Repository\Actions\Variables;
89
use Github\Api\Repository\Actions\WorkflowJobs;
910
use Github\Api\Repository\Actions\WorkflowRuns;
1011
use Github\Api\Repository\Actions\Workflows;
@@ -405,6 +406,14 @@ public function secrets(): Secrets
405406
return new Secrets($this->getClient());
406407
}
407408

409+
/**
410+
* @link https://docs.github.com/en/rest/reference/actions#secrets
411+
*/
412+
public function variables(): Variables
413+
{
414+
return new Variables($this->getClient());
415+
}
416+
408417
/**
409418
* Manage the content of a repository.
410419
*

0 commit comments

Comments
 (0)