Skip to content

Commit 9d1ab1e

Browse files
committed
feat: Support for Organization Runners
Signed-off-by: Hari Darshan Gorana <er.haridarshan@gmail.com>
1 parent 31cd5b1 commit 9d1ab1e

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed

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\Hooks;
78
use Github\Api\Organization\Members;
89
use Github\Api\Organization\OutsideCollaborators;
@@ -131,4 +132,12 @@ public function issues($organization, array $params = [], $page = 1)
131132
{
132133
return $this->get('/orgs/'.rawurlencode($organization).'/issues', array_merge(['page' => $page], $params));
133134
}
135+
136+
/**
137+
* @return SelfHostedRunners
138+
*/
139+
public function runners(): SelfHostedRunners
140+
{
141+
return new SelfHostedRunners($this->getClient());
142+
}
134143
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 string $type
14+
* @param int $page
15+
*
16+
* @return array|string
17+
*/
18+
public function all(string $organization, string $type = 'all', int $page = 1)
19+
{
20+
$parameters = [
21+
'type' => $type,
22+
'page' => $page,
23+
];
24+
25+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners', $parameters);
26+
}
27+
28+
/**
29+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#get-a-self-hosted-runner-for-an-organization
30+
*
31+
* @param string $organization
32+
* @param int $runnerId
33+
*
34+
* @return array|string
35+
*/
36+
public function show(string $organization, int $runnerId)
37+
{
38+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId);
39+
}
40+
41+
/**
42+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#delete-a-self-hosted-runner-from-an-organization
43+
*
44+
* @param string $organization
45+
* @param int $runnerId
46+
*
47+
* @return array|string
48+
*/
49+
public function remove(string $organization, int $runnerId)
50+
{
51+
return $this->delete('/orgs/'.rawurlencode($organization).'/actions/runners/'.$runnerId);
52+
}
53+
54+
/**
55+
* @link https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-runner-applications-for-an-organization
56+
*
57+
* @param string $organization
58+
*
59+
* @return array|string
60+
*/
61+
public function applications(string $organization)
62+
{
63+
return $this->get('/orgs/'.rawurlencode($organization).'/actions/runners/downloads');
64+
}
65+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
}
116+

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
* @return string
93103
*/

0 commit comments

Comments
 (0)