From 7de0912505f3e47f920185f802ca260db1ae4fe6 Mon Sep 17 00:00:00 2001 From: Froxz Date: Thu, 9 Mar 2023 13:32:46 +0200 Subject: [PATCH 1/5] Added environment variables & secrets --- doc/environment/secrets.md | 46 +++++++ doc/environment/variables.md | 49 ++++++++ doc/repo/environments.md | 4 + lib/Github/Api/Environment.php | 19 +++ lib/Github/Api/Environment/Secrets.php | 91 ++++++++++++++ lib/Github/Api/Environment/Variables.php | 94 ++++++++++++++ .../Tests/Api/Environment/SecretsTest.php | 116 +++++++++++++++++ .../Tests/Api/Environment/VariablesTest.php | 118 ++++++++++++++++++ 8 files changed, 537 insertions(+) create mode 100644 doc/environment/secrets.md create mode 100644 doc/environment/variables.md create mode 100644 lib/Github/Api/Environment/Secrets.php create mode 100644 lib/Github/Api/Environment/Variables.php create mode 100644 test/Github/Tests/Api/Environment/SecretsTest.php create mode 100644 test/Github/Tests/Api/Environment/VariablesTest.php diff --git a/doc/environment/secrets.md b/doc/environment/secrets.md new file mode 100644 index 00000000000..a956945d61b --- /dev/null +++ b/doc/environment/secrets.md @@ -0,0 +1,46 @@ +## Environment / Secrets API +[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md) + +### List environment secrets + +https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28 + +```php +$secrets = $client->environment()->secrets()->all($repoId, $envName); +``` + +### Get an environment secret + +https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret + +```php +$secret = $client->environment()->secrets()->show($repoId, $envName, $secretName); +``` + +### Create or Update an environment secret + +https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret + +```php +$client->environment()->secrets()->createOrUpdate($repoId, $envName, $secretName, [ + 'encrypted_value' => $encryptedValue, + 'key_id' => $key_id +]); +``` + +### Delete an environment secret + +https://docs.github.com/en/rest/reference/actions#delete-an-organization-secret + +```php +$client->environment()->secrets()->remove($repoId, $envName, $secretName); +``` + +### Get an environment public key + +https://docs.github.com/en/rest/reference/actions#get-an-organization-public-key + +```php +$client->environment()->secrets()->publicKey($repoId, $envName); +``` + diff --git a/doc/environment/variables.md b/doc/environment/variables.md new file mode 100644 index 00000000000..d9de932589e --- /dev/null +++ b/doc/environment/variables.md @@ -0,0 +1,49 @@ +## Environment / Variables API +[Back to the "Environments API"](../repo/environments.md) | [Back to the navigation](../README.md) + +### List environment variables + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables + +```php +$variables = $client->environment()->variables()->all($repoId, $envName); +``` + +### Get an environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable + +```php +$variable = $client->environment()->variables()->show($repoId, $envName, $variableName); +``` + +### Create environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable + +```php +$client->environment()->variables()->create($repoId, $envName, [ + 'name' => $name, + 'value' => $value +]); +``` + +### Update environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable + +```php +$client->environment()->variables()->update($repoId, $envName, $variableName, [ + 'name' => $name, + 'value' => $value +]); +``` + +### Delete an environment variable + +https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable + +```php +$client->environment()->variables()->remove($repoId, $envName, $variableName); +``` + diff --git a/doc/repo/environments.md b/doc/repo/environments.md index 56387ef8bfc..2d3e23a8796 100644 --- a/doc/repo/environments.md +++ b/doc/repo/environments.md @@ -3,6 +3,10 @@ Provides information about environments for a repository. Wraps [GitHub Environments API](https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28). +Additional APIs: +* [Secrets API](environment/secrets.md) +* [Variables API](environment/variables.md) + #### List all environments. ```php diff --git a/lib/Github/Api/Environment.php b/lib/Github/Api/Environment.php index 057d1edf0d8..bab4b9ee4e6 100644 --- a/lib/Github/Api/Environment.php +++ b/lib/Github/Api/Environment.php @@ -2,6 +2,9 @@ namespace Github\Api; +use Github\Api\Environment\Secrets; +use Github\Api\Environment\Variables; + /** * Listing, creating and updating environments. * @@ -67,4 +70,20 @@ public function remove(string $username, string $repository, string $name) { return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/environments/'.$name); } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#about-secrets-in-github-actions + */ + public function secrets(): Secrets + { + return new Secrets($this->getClient()); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#about-variables-in-github-actions + */ + public function variables(): Variables + { + return new Variables($this->getClient()); + } } diff --git a/lib/Github/Api/Environment/Secrets.php b/lib/Github/Api/Environment/Secrets.php new file mode 100644 index 00000000000..a26b2caf0f2 --- /dev/null +++ b/lib/Github/Api/Environment/Secrets.php @@ -0,0 +1,91 @@ +get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets'); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret + * + * @param int $id + * @param string $name + * @param string $secretName + * + * @return array|string + */ + public function show(int $id, string $name, string $secretName) + { + return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret + * + * @param int $id + * @param string $name + * @param string $secretName + * @param array $parameters + * + * @throws MissingArgumentException + * + * @return array|string + */ + public function createOrUpdate(int $id, string $name, string $secretName, array $parameters = []) + { + if (!isset($parameters['encrypted_value'])) { + throw new MissingArgumentException(['encrypted_value']); + } + + if (!isset($parameters['key_id'])) { + throw new MissingArgumentException(['key_id']); + } + + return $this->put('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName), $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#delete-an-environment-secret + * + * @param int $id + * @param string $name + * @param string $secretName + * + * @return array|string + */ + public function remove(int $id, string $name, string $secretName) + { + return $this->delete('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-public-key + * + * @param int $id + * @param string $name + * + * @return array|string + */ + public function publicKey(int $id, string $name) + { + return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/public-key'); + } +} diff --git a/lib/Github/Api/Environment/Variables.php b/lib/Github/Api/Environment/Variables.php new file mode 100644 index 00000000000..b29d1023535 --- /dev/null +++ b/lib/Github/Api/Environment/Variables.php @@ -0,0 +1,94 @@ +get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables'); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable + * + * @param int $id + * @param string $name + * @param string $variableName + * + * @return array|string + */ + public function show(int $id, string $name, string $variableName) + { + return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable + * + * @param int $id + * @param string $name + * @param array $parameters + * + * @throws MissingArgumentException + * + * @return array|string + */ + public function create(int $id, string $name, array $parameters) + { + if (!isset($parameters['name'])) { + throw new MissingArgumentException(['name']); + } + + if (!isset($parameters['value'])) { + throw new MissingArgumentException(['value']); + } + + return $this->post('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable + * + * @param int $id + * @param string $name + * @param string $variableName + * @param array $parameters + * + * @throws MissingArgumentException + * + * @return array|string + */ + public function update(int $id, string $name, string $variableName, array $parameters) + { + return $this->patch('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName), $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable + * + * @param int $id + * @param string $name + * @param string $variableName + * + * @return array|string + */ + public function remove(int $id, string $name, string $variableName) + { + return $this->delete('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); + } +} diff --git a/test/Github/Tests/Api/Environment/SecretsTest.php b/test/Github/Tests/Api/Environment/SecretsTest.php new file mode 100644 index 00000000000..242f710d60f --- /dev/null +++ b/test/Github/Tests/Api/Environment/SecretsTest.php @@ -0,0 +1,116 @@ + 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'] + ]; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/secrets') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all(3948501, 'production')); + } + + /** + * @test + */ + public function shouldGetEnvironmentSecret() + { + $expectedArray = []; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/secrets/secretName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show(3948501, 'production', 'secretName')); + } + + /** + * @test + */ + public function shouldUpdateOrCreateEnvironmentSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('put') + ->with('/repositories/3948501/environments/production/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->createOrUpdate(3948501, 'production', 'secretName', [ + 'encrypted_value' => 'foo', 'key_id' => 'key_id' + ])); + } + + /** + * @test + */ + public function shouldRemoveEnvironmentSecret() + { + $expectedValue = 'response'; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repositories/3948501/environments/production/secrets/secretName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(3948501, 'production', 'secretName')); + } + + /** + * @test + */ + public function shouldGetPublicKey() + { + $expectedArray = ['key_id' => 'key_id', 'key' => 'foo']; + + /** @var Secrets|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/secrets/public-key') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->publicKey(3948501, 'production')); + } + + protected function getApiClass() + { + return Secrets::class; + } +} diff --git a/test/Github/Tests/Api/Environment/VariablesTest.php b/test/Github/Tests/Api/Environment/VariablesTest.php new file mode 100644 index 00000000000..f2b2c87b813 --- /dev/null +++ b/test/Github/Tests/Api/Environment/VariablesTest.php @@ -0,0 +1,118 @@ + 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ['name' => 'name', 'value' => 'value', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], + ]; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/variables') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all(3948501, 'production')); + } + + /** + * @test + */ + public function shouldGetEnvironmentVariable() + { + $expectedArray = []; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/repositories/3948501/environments/production/variables/variableName') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show(3948501, 'production', 'variableName')); + } + + /** + * @test + */ + public function shouldCreateEnvironmentVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('post') + ->with('/repositories/3948501/environments/production/variables') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create(3948501, 'production', [ + 'name' => 'foo', 'value' => 'bar' + ])); + } + + /** + * @test + */ + public function shouldUpdateEnvironmentVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('patch') + ->with('/repositories/3948501/environments/production/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(3948501, 'production', 'variableName', [ + 'name' => 'variableName', 'value' => 'bar' + ])); + } + + /** + * @test + */ + public function shouldRemoveEnvironmentVariable() + { + $expectedValue = 'response'; + + /** @var Variables|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/repositories/3948501/environments/production/variables/variableName') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove(3948501, 'production', 'variableName')); + } + + protected function getApiClass() + { + return Variables::class; + } +} From d08d18df6c7111274831e44f921b36177adcca9a Mon Sep 17 00:00:00 2001 From: Froxz Date: Thu, 9 Mar 2023 13:36:25 +0200 Subject: [PATCH 2/5] fixes for styleCI --- lib/Github/Api/Environment/Secrets.php | 10 +++++----- lib/Github/Api/Environment/Variables.php | 10 +++++----- test/Github/Tests/Api/Environment/SecretsTest.php | 4 ++-- test/Github/Tests/Api/Environment/VariablesTest.php | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Github/Api/Environment/Secrets.php b/lib/Github/Api/Environment/Secrets.php index a26b2caf0f2..ce24d1231b3 100644 --- a/lib/Github/Api/Environment/Secrets.php +++ b/lib/Github/Api/Environment/Secrets.php @@ -13,7 +13,7 @@ class Secrets extends AbstractApi /** * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#list-environment-secrets * - * @param int $id + * @param int $id * @param string $name * * @return array|string @@ -26,7 +26,7 @@ public function all(int $id, string $name) /** * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-secret * - * @param int $id + * @param int $id * @param string $name * @param string $secretName * @@ -40,7 +40,7 @@ public function show(int $id, string $name, string $secretName) /** * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-environment-secret * - * @param int $id + * @param int $id * @param string $name * @param string $secretName * @param array $parameters @@ -65,7 +65,7 @@ public function createOrUpdate(int $id, string $name, string $secretName, array /** * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#delete-an-environment-secret * - * @param int $id + * @param int $id * @param string $name * @param string $secretName * @@ -79,7 +79,7 @@ public function remove(int $id, string $name, string $secretName) /** * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28#get-an-environment-public-key * - * @param int $id + * @param int $id * @param string $name * * @return array|string diff --git a/lib/Github/Api/Environment/Variables.php b/lib/Github/Api/Environment/Variables.php index b29d1023535..f62695a6d69 100644 --- a/lib/Github/Api/Environment/Variables.php +++ b/lib/Github/Api/Environment/Variables.php @@ -13,7 +13,7 @@ class Variables extends AbstractApi /** * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#list-environment-variables * - * @param int $id + * @param int $id * @param string $name * * @return array|string @@ -26,7 +26,7 @@ public function all(int $id, string $name) /** * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#get-an-environment-variable * - * @param int $id + * @param int $id * @param string $name * @param string $variableName * @@ -40,7 +40,7 @@ public function show(int $id, string $name, string $variableName) /** * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#create-an-environment-variable * - * @param int $id + * @param int $id * @param string $name * @param array $parameters * @@ -64,7 +64,7 @@ public function create(int $id, string $name, array $parameters) /** * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#update-an-environment-variable * - * @param int $id + * @param int $id * @param string $name * @param string $variableName * @param array $parameters @@ -81,7 +81,7 @@ public function update(int $id, string $name, string $variableName, array $param /** * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28#delete-an-environment-variable * - * @param int $id + * @param int $id * @param string $name * @param string $variableName * diff --git a/test/Github/Tests/Api/Environment/SecretsTest.php b/test/Github/Tests/Api/Environment/SecretsTest.php index 242f710d60f..0609a64f0f6 100644 --- a/test/Github/Tests/Api/Environment/SecretsTest.php +++ b/test/Github/Tests/Api/Environment/SecretsTest.php @@ -16,7 +16,7 @@ public function shouldGetEnvironmentSecrets() $expectedArray = [ ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], - ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'] + ['name' => 'name', 'created_at' => 'created_at', 'updated_at' => 'updated_at'], ]; /** @var Secrets|MockObject $api */ @@ -67,7 +67,7 @@ public function shouldUpdateOrCreateEnvironmentSecret() ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->createOrUpdate(3948501, 'production', 'secretName', [ - 'encrypted_value' => 'foo', 'key_id' => 'key_id' + 'encrypted_value' => 'foo', 'key_id' => 'key_id', ])); } diff --git a/test/Github/Tests/Api/Environment/VariablesTest.php b/test/Github/Tests/Api/Environment/VariablesTest.php index f2b2c87b813..0fc01193fd1 100644 --- a/test/Github/Tests/Api/Environment/VariablesTest.php +++ b/test/Github/Tests/Api/Environment/VariablesTest.php @@ -67,7 +67,7 @@ public function shouldCreateEnvironmentVariable() ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->create(3948501, 'production', [ - 'name' => 'foo', 'value' => 'bar' + 'name' => 'foo', 'value' => 'bar', ])); } @@ -88,7 +88,7 @@ public function shouldUpdateEnvironmentVariable() ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->update(3948501, 'production', 'variableName', [ - 'name' => 'variableName', 'value' => 'bar' + 'name' => 'variableName', 'value' => 'bar', ])); } From 3f4fff0f2ea254635853e93ccb3a5d4d60108173 Mon Sep 17 00:00:00 2001 From: Froxz Date: Thu, 9 Mar 2023 13:38:48 +0200 Subject: [PATCH 3/5] removed rawurlencode for repo id --- lib/Github/Api/Environment/Secrets.php | 10 +++++----- lib/Github/Api/Environment/Variables.php | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Github/Api/Environment/Secrets.php b/lib/Github/Api/Environment/Secrets.php index ce24d1231b3..e011df0a3d5 100644 --- a/lib/Github/Api/Environment/Secrets.php +++ b/lib/Github/Api/Environment/Secrets.php @@ -20,7 +20,7 @@ class Secrets extends AbstractApi */ public function all(int $id, string $name) { - return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets'); + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets'); } /** @@ -34,7 +34,7 @@ public function all(int $id, string $name) */ public function show(int $id, string $name, string $secretName) { - return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); } /** @@ -59,7 +59,7 @@ public function createOrUpdate(int $id, string $name, string $secretName, array throw new MissingArgumentException(['key_id']); } - return $this->put('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName), $parameters); + return $this->put('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName), $parameters); } /** @@ -73,7 +73,7 @@ public function createOrUpdate(int $id, string $name, string $secretName, array */ public function remove(int $id, string $name, string $secretName) { - return $this->delete('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); + return $this->delete('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName)); } /** @@ -86,6 +86,6 @@ public function remove(int $id, string $name, string $secretName) */ public function publicKey(int $id, string $name) { - return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/secrets/public-key'); + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/public-key'); } } diff --git a/lib/Github/Api/Environment/Variables.php b/lib/Github/Api/Environment/Variables.php index f62695a6d69..09ac690f748 100644 --- a/lib/Github/Api/Environment/Variables.php +++ b/lib/Github/Api/Environment/Variables.php @@ -20,7 +20,7 @@ class Variables extends AbstractApi */ public function all(int $id, string $name) { - return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables'); + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables'); } /** @@ -34,7 +34,7 @@ public function all(int $id, string $name) */ public function show(int $id, string $name, string $variableName) { - return $this->get('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); + return $this->get('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); } /** @@ -58,7 +58,7 @@ public function create(int $id, string $name, array $parameters) throw new MissingArgumentException(['value']); } - return $this->post('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables', $parameters); + return $this->post('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables', $parameters); } /** @@ -75,7 +75,7 @@ public function create(int $id, string $name, array $parameters) */ public function update(int $id, string $name, string $variableName, array $parameters) { - return $this->patch('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName), $parameters); + return $this->patch('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName), $parameters); } /** @@ -89,6 +89,6 @@ public function update(int $id, string $name, string $variableName, array $param */ public function remove(int $id, string $name, string $variableName) { - return $this->delete('/repositories/'.rawurlencode($id).'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); + return $this->delete('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables/'.rawurlencode($variableName)); } } From 289c0ab0cd4b78937120011bd2325ab396d06a30 Mon Sep 17 00:00:00 2001 From: Froxz Date: Thu, 9 Mar 2023 15:13:37 +0200 Subject: [PATCH 4/5] added link to secrets and varaibles --- doc/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/README.md b/doc/README.md index 3c1579f3269..58547e32cda 100644 --- a/doc/README.md +++ b/doc/README.md @@ -59,6 +59,8 @@ v3 APIs: * [Check Suites](repo/check_suites.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) + * [Secrets](environment/secrets.md) + * [Variables](environment/variables.md) * [Environments](repo/environments.md) * [Labels](repo/labels.md) * [Protection](repo/protection.md) From cbf08fc221b7c9b703a3a04baf3432927ea9e9fb Mon Sep 17 00:00:00 2001 From: Froxz Date: Fri, 10 Mar 2023 08:53:04 +0200 Subject: [PATCH 5/5] Removed validation of parameters removed MissingArgumentException --- lib/Github/Api/Environment/Secrets.php | 11 ----------- lib/Github/Api/Environment/Variables.php | 13 ------------- 2 files changed, 24 deletions(-) diff --git a/lib/Github/Api/Environment/Secrets.php b/lib/Github/Api/Environment/Secrets.php index e011df0a3d5..cef84c34958 100644 --- a/lib/Github/Api/Environment/Secrets.php +++ b/lib/Github/Api/Environment/Secrets.php @@ -3,7 +3,6 @@ namespace Github\Api\Environment; use Github\Api\AbstractApi; -use Github\Exception\MissingArgumentException; /** * @link https://docs.github.com/en/rest/actions/secrets?apiVersion=2022-11-28 @@ -45,20 +44,10 @@ public function show(int $id, string $name, string $secretName) * @param string $secretName * @param array $parameters * - * @throws MissingArgumentException - * * @return array|string */ public function createOrUpdate(int $id, string $name, string $secretName, array $parameters = []) { - if (!isset($parameters['encrypted_value'])) { - throw new MissingArgumentException(['encrypted_value']); - } - - if (!isset($parameters['key_id'])) { - throw new MissingArgumentException(['key_id']); - } - return $this->put('/repositories/'.$id.'/environments/'.rawurlencode($name).'/secrets/'.rawurlencode($secretName), $parameters); } diff --git a/lib/Github/Api/Environment/Variables.php b/lib/Github/Api/Environment/Variables.php index 09ac690f748..035a8f605a3 100644 --- a/lib/Github/Api/Environment/Variables.php +++ b/lib/Github/Api/Environment/Variables.php @@ -3,7 +3,6 @@ namespace Github\Api\Environment; use Github\Api\AbstractApi; -use Github\Exception\MissingArgumentException; /** * @link https://docs.github.com/en/rest/actions/variables?apiVersion=2022-11-28 @@ -44,20 +43,10 @@ public function show(int $id, string $name, string $variableName) * @param string $name * @param array $parameters * - * @throws MissingArgumentException - * * @return array|string */ public function create(int $id, string $name, array $parameters) { - if (!isset($parameters['name'])) { - throw new MissingArgumentException(['name']); - } - - if (!isset($parameters['value'])) { - throw new MissingArgumentException(['value']); - } - return $this->post('/repositories/'.$id.'/environments/'.rawurlencode($name).'/variables', $parameters); } @@ -69,8 +58,6 @@ public function create(int $id, string $name, array $parameters) * @param string $variableName * @param array $parameters * - * @throws MissingArgumentException - * * @return array|string */ public function update(int $id, string $name, string $variableName, array $parameters)