Skip to content

Commit

Permalink
feature #1106 Added Org & Repository variables (Froxz)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SergkeiM authored Mar 10, 2023
1 parent acc0453 commit bdb9bfb
Show file tree
Hide file tree
Showing 11 changed files with 705 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ v3 APIs:
* [Organization](organization.md)
* [Members](organization/members.md)
* [Teams](organization/teams.md)
* [Secrets](organization/actions/secrets.md)
* [Variables](organization/actions/variables.md)
* [Projects](project/projects.md)
* [Columns](project/columns.md)
* [Cards](project/cards.md)
Expand All @@ -51,6 +53,7 @@ v3 APIs:
* Actions
* [Artifacts](repo/actions/artifacts.md)
* [Secrets](repo/actions/secrets.md)
* [Variables](repo/actions/variables.md)
* [Self hosted runners](repo/actions/self_hosted_runners.md)
* [Workflow jobs](repo/actions/workflow_jobs.md)
* [Workflow runs](repo/actions/workflow_runs.md)
Expand Down
87 changes: 87 additions & 0 deletions doc/organization/actions/variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
## Organization / Variables API
[Back to the "Organization API"](../organization.md) | [Back to the navigation](../README.md)

### List organization variables

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-organization-variables

```php
$variables = $client->organization()->variables()->all('KnpLabs');
```

### Get an organization variable

https://docs.github.com/en/rest/reference/actions#get-an-organization-secret

```php
$variable = $client->organization()->variables()->show('KnpLabs', $variableName);
```

### Create an organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable

```php
$client->organization()->variables()->create('KnpLabs', [
'name' => $name,
'value' => $value,
'visibility' => $visibility,
'selected_repository_ids' => $selectedRepositoryIds,
]);
```

### Update an organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable

```php
$client->organization()->variables()->update('KnpLabs', $variableName, [
'name' => $name,
'value' => $value,
'visibility' => $visibility,
'selected_repository_ids' => $selectedRepositoryIds
]);
```

### Delete an organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable

```php
$client->organization()->variables()->remove('KnpLabs', $variableName);
```

### List selected repositories for organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable

```php
$client->organization()->variables()->selectedRepositories('KnpLabs', $variableName);
```

### Set selected repositories for an organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable

```php
$client->organization()->variables()->setSelectedRepositories('KnpLabs', 'variableName', [
'selected_repository_ids' => [1, 2, 3],
]);
```

### Add selected repository to an organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable

```php
$client->organization()->variables()->addRepository('KnpLabs', $repositoryId, $variableName);
```

### Remove selected repository from an organization variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable

```php
$client->organization()->variables()->removeRepository('KnpLabs', $repositoryId, $variableName);
```

48 changes: 48 additions & 0 deletions doc/repo/actions/variables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Repo / Actions / Variables API
[Back to the "Repos API"](../../repos.md) | [Back to the navigation](../../README.md)

### List repository variables

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-repository-variables

```php
$variables = $client->api('repo')->variables()->all('KnpLabs', 'php-github-api');
```

### Get a repository variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-a-repository-variable

```php
$variable = $client->api('repo')->variables()->show('KnpLabs', 'php-github-api', $variableName);
```

### Create a repository variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-a-repository-variable

```php
$client->api('repo')->variables()->create('KnpLabs', 'php-github-api', [
'name' => $name,
'value' => $value,
]);
```

### Update a repository variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-a-repository-variable

```php
$client->api('repo')->variables()->update('KnpLabs', 'php-github-api', $variableName, [
'name' => $name,
'value' => $value,
]);
```

### Delete a repository variable

https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-a-repository-variable

```php
$client->api('repo')->variables()->remove('KnpLabs', 'php-github-api', $variableName);
```
9 changes: 9 additions & 0 deletions lib/Github/Api/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\Api;

use Github\Api\Organization\Actions\Secrets;
use Github\Api\Organization\Actions\Variables;
use Github\Api\Organization\Hooks;
use Github\Api\Organization\Members;
use Github\Api\Organization\OutsideCollaborators;
Expand Down Expand Up @@ -110,6 +111,14 @@ public function secrets(): Secrets
return new Secrets($this->getClient());
}

/**
* @return Variables
*/
public function variables(): Variables
{
return new Variables($this->getClient());
}

/**
* @return OutsideCollaborators
*/
Expand Down
131 changes: 131 additions & 0 deletions lib/Github/Api/Organization/Actions/Variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

namespace Github\Api\Organization\Actions;

use Github\Api\AbstractApi;

/**
* @link https://docs.github.com/en/rest/reference/actions#variables
*/
class Variables extends AbstractApi
{
/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-organization-variables
*
* @param string $organization
*
* @return array|string
*/
public function all(string $organization)
{
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables');
}

/**
* @link https://docs.github.com/en/rest/reference/actions#get-an-organization-secret
*
* @param string $organization
* @param string $variableName
*
* @return array|string
*/
public function show(string $organization, string $variableName)
{
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName));
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-organization-variable
*
* @param string $organization
* @param array $parameters
*
* @return array|string
*/
public function create(string $organization, array $parameters)
{
return $this->post('/orgs/'.rawurlencode($organization).'/actions/variables', $parameters);
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-organization-variable
*
* @param string $organization
* @param string $variableName
* @param array $parameters
*
* @return array|string
*/
public function update(string $organization, string $variableName, array $parameters = [])
{
return $this->patch('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName), $parameters);
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-organization-variable
*
* @param string $organization
* @param string $variableName
*
* @return array|string
*/
public function remove(string $organization, string $variableName)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName));
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-selected-repositories-for-an-organization-variable
*
* @param string $organization
* @param string $variableName
*
* @return array|string
*/
public function selectedRepositories(string $organization, string $variableName)
{
return $this->get('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories');
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#set-selected-repositories-for-an-organization-variable
*
* @param string $organization
* @param string $variableName
* @param array $parameters
*
* @return array|string
*/
public function setSelectedRepositories(string $organization, string $variableName, array $parameters = [])
{
return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories', $parameters);
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#add-selected-repository-to-an-organization-variable
*
* @param string $organization
* @param int $repositoryId
* @param string $variableName
*
* @return array|string
*/
public function addRepository(string $organization, int $repositoryId, string $variableName)
{
return $this->put('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId);
}

/**
* @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#remove-selected-repository-from-an-organization-variable
*
* @param string $organization
* @param int $repositoryId
* @param string $variableName
*
* @return array|string
*/
public function removeRepository(string $organization, int $repositoryId, string $variableName)
{
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/variables/'.rawurlencode($variableName).'/repositories/'.$repositoryId);
}
}
9 changes: 9 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Github\Api\Repository\Actions\Artifacts;
use Github\Api\Repository\Actions\Secrets;
use Github\Api\Repository\Actions\SelfHostedRunners;
use Github\Api\Repository\Actions\Variables;
use Github\Api\Repository\Actions\WorkflowJobs;
use Github\Api\Repository\Actions\WorkflowRuns;
use Github\Api\Repository\Actions\Workflows;
Expand Down Expand Up @@ -405,6 +406,14 @@ public function secrets(): Secrets
return new Secrets($this->getClient());
}

/**
* @link https://docs.github.com/en/rest/reference/actions#secrets
*/
public function variables(): Variables
{
return new Variables($this->getClient());
}

/**
* Manage the content of a repository.
*
Expand Down
Loading

0 comments on commit bdb9bfb

Please sign in to comment.