forked from KnpLabs/php-github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature KnpLabs#1101 feat: Support for Organization Runners (haridars…
…han, renovate[bot]) This PR was squashed before being merged into the 3.11.x-dev branch. Discussion ---------- Commits ------- 9d1ab1e feat: Support for Organization Runners 02bd5bc fix: StyleCI ea2f3ec docs: Add Organization Self-Hosted runner doc 6df9b8f docs: Add org runner link in README.md 70e7bbe Merge branch 'KnpLabs:master' into master 50a0ee1 Merge branch 'master' into master 370927e Merge branch 'KnpLabs:master' into master 91c8043 chore: change argument of `all` method to `$parameters` array ca94676 chore: fix StyleCi 5ff2a51 chore: minor fix 987a552 Add renovate.json 234a7a2 Merge pull request KnpLabs#1 from haridarshan/renovate/configure be15552 Update renovate.json 7483542 Delete renovate.json
- Loading branch information
1 parent
4f7e610
commit 0e2399c
Showing
6 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Github\Api\Organization\Actions; | ||
|
||
use Github\Api\AbstractApi; | ||
|
||
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 | ||
* | ||
* @return array|string | ||
*/ | ||
public function all(string $organization, array $parameters = []) | ||
{ | ||
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'); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
test/Github/Tests/Api/Organization/Actions/SelfHostedRunnersTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\Organization\Actions; | ||
|
||
use Github\Api\Organization\Actions\SelfHostedRunners; | ||
use Github\Tests\Api\TestCase; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
class SelfHostedRunnersTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldGetSelfHostedRunners() | ||
{ | ||
$expectedArray = [ | ||
[ | ||
'id' => 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters