Skip to content

Commit 0e2399c

Browse files
authored
feature #1101 feat: Support for Organization Runners (haridarshan, 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 #1 from haridarshan/renovate/configure be15552 Update renovate.json 7483542 Delete renovate.json
1 parent 4f7e610 commit 0e2399c

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ v3 APIs:
3939
* [Organization](organization.md)
4040
* [Members](organization/members.md)
4141
* [Teams](organization/teams.md)
42+
* [Self hosted runners](organization/actions/self_hosted_runners.md)
4243
* [Secrets](organization/actions/secrets.md)
4344
* [Variables](organization/actions/variables.md)
4445
* [Projects](project/projects.md)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Organization / Actions / Self Hosted Runners API
2+
[Back to the "Organization API"](../../organization.md) | [Back to the navigation](../../README.md)
3+
4+
# List self-hosted runners for an Organization
5+
6+
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization
7+
8+
```php
9+
$runners = $client->api('organization')->runners()->all('KnpLabs');
10+
```
11+
12+
# Get a self-hosted runner for an Organization
13+
14+
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization
15+
16+
```php
17+
$runner = $client->api('organization')->runners()->show('KnpLabs', $runnerId);
18+
```
19+
20+
# Delete a self-hosted runner from an Organization
21+
22+
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization
23+
24+
```php
25+
$client->api('organization')->runners()->remove('KnpLabs', $runnerId);
26+
```
27+
28+
# List runner applications for an Organization
29+
30+
https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization
31+
32+
```php
33+
$applications = $client->api('organization')->selfHostedRunners()->applications('KnpLabs');
34+
```
35+
36+
# List of all runners with Pagination
37+
38+
```php
39+
$api = $github->api('organization')->runners();
40+
$paginator = new Github\ResultPager($github);
41+
$parameters = array('KnpLabs');
42+
$runners = $paginator->fetchAll($api, 'all', $parameters);
43+
44+
do {
45+
foreach ($runners['runners'] as $runner) {
46+
// code
47+
}
48+
$runners = $paginator->fetchNext();
49+
}
50+
while($paginator->hasNext());
51+
```

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\SelfHostedRunners;
67
use Github\Api\Organization\Actions\Variables;
78
use Github\Api\Organization\Hooks;
89
use Github\Api\Organization\Members;
@@ -140,4 +141,12 @@ public function issues($organization, array $params = [], $page = 1)
140141
{
141142
return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => $page], $params));
142143
}
144+
145+
/**
146+
* @return SelfHostedRunners
147+
*/
148+
public function runners(): SelfHostedRunners
149+
{
150+
return new SelfHostedRunners($this->getClient());
151+
}
143152
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Github\Api\Organization\Actions;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class SelfHostedRunners extends AbstractApi
8+
{
9+
/**
10+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-an-organization
11+
*
12+
* @param string $organization
13+
* @param array $parameters
14+
*
15+
* @return array|string
16+
*/
17+
public function all(string $organization, array $parameters = [])
18+
{
19+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners', $parameters);
20+
}
21+
22+
/**
23+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization
24+
*
25+
* @param string $organization
26+
* @param int $runnerId
27+
*
28+
* @return array|string
29+
*/
30+
public function show(string $organization, int $runnerId)
31+
{
32+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId);
33+
}
34+
35+
/**
36+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization
37+
*
38+
* @param string $organization
39+
* @param int $runnerId
40+
*
41+
* @return array|string
42+
*/
43+
public function remove(string $organization, int $runnerId)
44+
{
45+
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId);
46+
}
47+
48+
/**
49+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization
50+
*
51+
* @param string $organization
52+
*
53+
* @return array|string
54+
*/
55+
public function applications(string $organization)
56+
{
57+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/downloads');
58+
}
59+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Organization\Actions;
4+
5+
use Github\Api\Organization\Actions\SelfHostedRunners;
6+
use Github\Tests\Api\TestCase;
7+
use PHPUnit\Framework\MockObject\MockObject;
8+
9+
class SelfHostedRunnersTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
*/
14+
public function shouldGetSelfHostedRunners()
15+
{
16+
$expectedArray = [
17+
[
18+
'id' => 1,
19+
'name' => 'MBP',
20+
'os' => 'macos',
21+
'status' => 'online',
22+
],
23+
[
24+
'id' => 2,
25+
'name' => 'iMac',
26+
'os' => 'macos',
27+
'status' => 'offline',
28+
],
29+
];
30+
31+
/** @var SelfHostedRunners|MockObject $api */
32+
$api = $this->getApiMock();
33+
34+
$api
35+
->expects($this->once())
36+
->method('get')
37+
->with('/orgs/KnpLabs/actions/runners')
38+
->will($this->returnValue($expectedArray));
39+
40+
$this->assertEquals($expectedArray, $api->all('KnpLabs'));
41+
}
42+
43+
/**
44+
* @test
45+
*/
46+
public function shouldGetSelfHostedRunner()
47+
{
48+
$expectedArray = [
49+
'id' => 1,
50+
'name' => 'MBP',
51+
'os' => 'macos',
52+
'status' => 'online',
53+
];
54+
55+
/** @var SelfHostedRunners|MockObject $api */
56+
$api = $this->getApiMock();
57+
58+
$api
59+
->expects($this->once())
60+
->method('get')
61+
->with('/orgs/KnpLabs/actions/runners/1')
62+
->will($this->returnValue($expectedArray));
63+
64+
$this->assertEquals($expectedArray, $api->show('KnpLabs', 1));
65+
}
66+
67+
/**
68+
* @test
69+
*/
70+
public function shouldRemoveSelfHostedRunner()
71+
{
72+
$expectedValue = 'response';
73+
74+
/** @var SelfHostedRunners|MockObject $api */
75+
$api = $this->getApiMock();
76+
77+
$api
78+
->expects($this->once())
79+
->method('delete')
80+
->with('/orgs/KnpLabs/actions/runners/1')
81+
->will($this->returnValue($expectedValue));
82+
83+
$this->assertEquals($expectedValue, $api->remove('KnpLabs', 1));
84+
}
85+
86+
/**
87+
* @test
88+
*/
89+
public function shouldGetSelfHostedRunnerApps()
90+
{
91+
$expectedArray = [
92+
['os' => 'osx', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'],
93+
['os' => 'linux', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'],
94+
['os' => 'linux', 'architecture' => 'arm', 'download_url' => 'download_url', 'filename' => 'filename'],
95+
['os' => 'win', 'architecture' => 'x64', 'download_url' => 'download_url', 'filename' => 'filename'],
96+
['os' => 'linux', 'architecture' => 'arm64', 'download_url' => 'download_url', 'filename' => 'filename'],
97+
];
98+
99+
/** @var SelfHostedRunners|MockObject $api */
100+
$api = $this->getApiMock();
101+
102+
$api
103+
->expects($this->once())
104+
->method('get')
105+
->with('/orgs/KnpLabs/actions/runners/downloads')
106+
->will($this->returnValue($expectedArray));
107+
108+
$this->assertEquals($expectedArray, $api->applications('KnpLabs'));
109+
}
110+
111+
protected function getApiClass()
112+
{
113+
return SelfHostedRunners::class;
114+
}
115+
}

test/Github/Tests/Api/OrganizationTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ public function shouldGetTeamsApiObject()
8888
$this->assertInstanceOf(\Github\Api\Organization\Teams::class, $api->teams());
8989
}
9090

91+
/**
92+
* @test
93+
*/
94+
public function shouldGetSelfHostedRunnersApiObject()
95+
{
96+
$api = $this->getApiMock();
97+
98+
$this->assertInstanceOf(\Github\Api\Organization\Actions\SelfHostedRunners::class, $api->runners());
99+
}
100+
91101
/**
92102
* @test
93103
*/

0 commit comments

Comments
 (0)