From 9d1ab1e7c9a5082fbb3e664b36194fa8426d9b57 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Wed, 8 Mar 2023 19:55:34 +0530 Subject: [PATCH 01/10] feat: Support for Organization Runners Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/Organization.php | 9 ++ .../Actions/SelfHostedRunners.php | 65 ++++++++++ .../Actions/SelfHostedRunnersTest.php | 116 ++++++++++++++++++ test/Github/Tests/Api/OrganizationTest.php | 10 ++ 4 files changed, 200 insertions(+) create mode 100644 lib/Github/Api/Organization/Actions/SelfHostedRunners.php create mode 100644 test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php diff --git a/lib/Github/Api/Organization.php b/lib/Github/Api/Organization.php index d3e7646651d..3a051b22575 100644 --- a/lib/Github/Api/Organization.php +++ b/lib/Github/Api/Organization.php @@ -3,6 +3,7 @@ namespace Github\Api; use Github\Api\Organization\Actions\Secrets; +use Github\Api\Organization\Actions\SelfHostedRunners; use Github\Api\Organization\Hooks; use Github\Api\Organization\Members; use Github\Api\Organization\OutsideCollaborators; @@ -131,4 +132,12 @@ public function issues($organization, array $params = [], $page = 1) { return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => $page], $params)); } + + /** + * @return SelfHostedRunners + */ + public function runners(): SelfHostedRunners + { + return new SelfHostedRunners($this->getClient()); + } } diff --git a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php new file mode 100644 index 00000000000..e4d35be619d --- /dev/null +++ b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php @@ -0,0 +1,65 @@ + $type, + 'page' => $page, + ]; + + return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners', $parameters); + } + + /** + * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization + * + * @param string $organization + * @param int $runnerId + * + * @return array|string + */ + public function show(string $organization, int $runnerId) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization + * + * @param string $organization + * @param int $runnerId + * + * @return array|string + */ + public function remove(string $organization, int $runnerId) + { + return $this->delete('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId); + } + + /** + * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization + * + * @param string $organization + * + * @return array|string + */ + public function applications(string $organization) + { + return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/downloads'); + } +} diff --git a/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php b/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php new file mode 100644 index 00000000000..e5ddbdff0ca --- /dev/null +++ b/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php @@ -0,0 +1,116 @@ + 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ], + [ + 'id' => 2, + 'name' => 'iMac', + 'os' => 'macos', + 'status' => 'offline', + ], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/runners') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->all('KnpLabs')); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunner() + { + $expectedArray = [ + 'id' => 1, + 'name' => 'MBP', + 'os' => 'macos', + 'status' => 'online', + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/runners/1') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->show('KnpLabs', 1)); + } + + /** + * @test + */ + public function shouldRemoveSelfHostedRunner() + { + $expectedValue = 'response'; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('delete') + ->with('/orgs/KnpLabs/actions/runners/1') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 1)); + } + + /** + * @test + */ + public function shouldGetSelfHostedRunnerApps() + { + $expectedArray = [ + ['os' => 'osx', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'win', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'], + ['os' => 'linux', 'architecture' => 'arm64', 'download_url' => 'download_url', 'filename' => 'filename'], + ]; + + /** @var SelfHostedRunners|MockObject $api */ + $api = $this->getApiMock(); + + $api + ->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/actions/runners/downloads') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->applications('KnpLabs')); + } + + protected function getApiClass() + { + return SelfHostedRunners::class; + } +} + diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 04f389c0337..cd4e53156e7 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -88,6 +88,16 @@ public function shouldGetTeamsApiObject() $this->assertInstanceOf(\Github\Api\Organization\Teams::class, $api->teams()); } + /** + * @test + */ + public function shouldGetSelfHostedRunnersApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf(\Github\Api\Organization\Actions\SelfHostedRunners::class, $api->runners()); + } + /** * @return string */ From 02bd5bc04e4bafab335af40fe453766816a89d21 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Fri, 10 Mar 2023 13:02:06 +0530 Subject: [PATCH 02/10] fix: StyleCI Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/Organization/Actions/SelfHostedRunners.php | 4 ++-- .../Tests/Api/Organization/Actions/SelfHostedRunnersTest.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php index e4d35be619d..bfcc986be29 100644 --- a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php +++ b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php @@ -11,7 +11,7 @@ class SelfHostedRunners extends AbstractApi * * @param string $organization * @param string $type - * @param int $page + * @param int $page * * @return array|string */ @@ -42,7 +42,7 @@ public function show(string $organization, int $runnerId) * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization * * @param string $organization - * @param int $runnerId + * @param int $runnerId * * @return array|string */ diff --git a/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php b/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php index e5ddbdff0ca..e313a88202a 100644 --- a/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php +++ b/test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php @@ -113,4 +113,3 @@ protected function getApiClass() return SelfHostedRunners::class; } } - From ea2f3ececb90f030c066d687591d8e1c9166242a Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Fri, 10 Mar 2023 14:50:53 +0530 Subject: [PATCH 03/10] docs: Add Organization Self-Hosted runner doc Signed-off-by: Hari Darshan Gorana --- .../actions/self_hosted_runners.md | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 doc/organization/actions/self_hosted_runners.md diff --git a/doc/organization/actions/self_hosted_runners.md b/doc/organization/actions/self_hosted_runners.md new file mode 100644 index 00000000000..f6e915cdce5 --- /dev/null +++ b/doc/organization/actions/self_hosted_runners.md @@ -0,0 +1,51 @@ +## Organization / Actions / Self Hosted Runners API +[Back to the "Organization API"](../../organization.md) | [Back to the navigation](../../README.md) + +# List self-hosted runners for an Organization + +https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization + +```php +$runners = $client->api('organization')->runners()->all('KnpLabs'); +``` + +# Get a self-hosted runner for an Organization + + https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization + +```php +$runner = $client->api('organization')->runners()->show('KnpLabs', $runnerId); +``` + +# Delete a self-hosted runner from an Organization + +https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization + +```php +$client->api('organization')->runners()->remove('KnpLabs', $runnerId); +``` + +# List runner applications for an Organization + +https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization + +```php +$applications = $client->api('organization')->selfHostedRunners()->applications('KnpLabs'); +``` + +# List of all runners with Pagination + +```php +$api = $github->api('organization')->runners(); +$paginator = new Github\ResultPager($github); +$parameters = array('KnpLabs'); +$runners = $paginator->fetchAll($api, 'all', $parameters); + +do { + foreach ($runners['runners'] as $runner) { + // code + } + $runners = $paginator->fetchNext(); +} +while($paginator->hasNext()); +``` From 6df9b8fe3212f4dc60eaea090bc245c5a6afcbec Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Fri, 10 Mar 2023 14:57:44 +0530 Subject: [PATCH 04/10] docs: Add org runner link in README.md Signed-off-by: Hari Darshan Gorana --- doc/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/README.md b/doc/README.md index acae0d3a441..e133527d6ca 100644 --- a/doc/README.md +++ b/doc/README.md @@ -39,6 +39,8 @@ v3 APIs: * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) + * Actions + * [Self hosted runners](organization/actions/self_hosted_runners.md) * [Projects](project/projects.md) * [Columns](project/columns.md) * [Cards](project/cards.md) From 91c80431771f2440cce7d7aebf944fb66457daf9 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Sat, 11 Mar 2023 13:03:55 +0530 Subject: [PATCH 05/10] chore: change argument of `all` method to `$parameters` array Signed-off-by: Hari Darshan Gorana --- .../Api/Organization/Actions/SelfHostedRunners.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php index bfcc986be29..6b94952d18a 100644 --- a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php +++ b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php @@ -10,18 +10,12 @@ class SelfHostedRunners extends AbstractApi * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization * * @param string $organization - * @param string $type - * @param int $page + * @param array $parameters * * @return array|string */ - public function all(string $organization, string $type = 'all', int $page = 1) + public function all(string $organization, array $parameters) { - $parameters = [ - 'type' => $type, - 'page' => $page, - ]; - return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners', $parameters); } From ca9467642c5230a8357d01f5bde840bdb87e9468 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Sat, 11 Mar 2023 13:06:49 +0530 Subject: [PATCH 06/10] chore: fix StyleCi Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/Organization/Actions/SelfHostedRunners.php | 2 +- test/Github/Tests/Api/OrganizationTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php index 6b94952d18a..bb81ffe0eed 100644 --- a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php +++ b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php @@ -10,7 +10,7 @@ class SelfHostedRunners extends AbstractApi * @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization * * @param string $organization - * @param array $parameters + * @param array $parameters * * @return array|string */ diff --git a/test/Github/Tests/Api/OrganizationTest.php b/test/Github/Tests/Api/OrganizationTest.php index 4a123b56959..2b920662691 100644 --- a/test/Github/Tests/Api/OrganizationTest.php +++ b/test/Github/Tests/Api/OrganizationTest.php @@ -97,7 +97,7 @@ public function shouldGetSelfHostedRunnersApiObject() $this->assertInstanceOf(\Github\Api\Organization\Actions\SelfHostedRunners::class, $api->runners()); } - + /** * @test */ From 5ff2a51502bd654d2c013be3abb1cb6c30511521 Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Sat, 11 Mar 2023 13:12:40 +0530 Subject: [PATCH 07/10] chore: minor fix Signed-off-by: Hari Darshan Gorana --- lib/Github/Api/Organization/Actions/SelfHostedRunners.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php index bb81ffe0eed..f0b989f5751 100644 --- a/lib/Github/Api/Organization/Actions/SelfHostedRunners.php +++ b/lib/Github/Api/Organization/Actions/SelfHostedRunners.php @@ -14,7 +14,7 @@ class SelfHostedRunners extends AbstractApi * * @return array|string */ - public function all(string $organization, array $parameters) + public function all(string $organization, array $parameters = []) { return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners', $parameters); } From 987a552a69ba8ba0e0387076e15365a21f04570a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 23 Mar 2023 00:02:52 +0000 Subject: [PATCH 08/10] Add renovate.json --- renovate.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 renovate.json diff --git a/renovate.json b/renovate.json new file mode 100644 index 00000000000..f9c2c327040 --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} From be155523bd5368280c05584aa45879c446ef2a7c Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Sun, 2 Apr 2023 21:17:22 +0530 Subject: [PATCH 09/10] Update renovate.json --- renovate.json | 1 - 1 file changed, 1 deletion(-) diff --git a/renovate.json b/renovate.json index f9c2c327040..ee8c906b910 100644 --- a/renovate.json +++ b/renovate.json @@ -1,5 +1,4 @@ { - "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" ] From 748354251877a9a5487dbf5ef10c2c845a9afe2f Mon Sep 17 00:00:00 2001 From: Hari Darshan Gorana Date: Sun, 2 Apr 2023 21:17:48 +0530 Subject: [PATCH 10/10] Delete renovate.json --- renovate.json | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 renovate.json diff --git a/renovate.json b/renovate.json deleted file mode 100644 index ee8c906b910..00000000000 --- a/renovate.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": [ - "config:base" - ] -}