Skip to content

Commit f4e822e

Browse files
Add Copilot usage endpoints
1 parent 71fec50 commit f4e822e

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

lib/Github/Api/Copilot/Usage.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Github\Api\Copilot;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class Usage extends AbstractApi
8+
{
9+
public function orgUsageSummary(string $organization, array $params = []): array
10+
{
11+
return $this->get('/orgs/' . rawurlencode($organization) . '/copilot/usage', $params);
12+
}
13+
14+
public function orgTeamUsageSummary(string $organization, string $teamSlug, array $params = []): array
15+
{
16+
return $this->get('/orgs/' . rawurlencode($organization) . '/teams/' . rawurlencode($teamSlug) . '/copilot/usage', $params);
17+
}
18+
19+
public function enterpriseUsageSummary(string $enterprise, array $params = []): array
20+
{
21+
return $this->get('/enterprises/' . rawurlencode($enterprise) . '/copilot/usage', $params);
22+
}
23+
24+
public function enterpriseTeamUsageSummary(string $enterprise, string $teamSlug, array $params = []): array
25+
{
26+
return $this->get('/enterprises/' . rawurlencode($enterprise) . '/teams/' . rawurlencode($teamSlug) . '/copilot/usage', $params);
27+
}
28+
}

lib/Github/Client.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ public function api($name): AbstractApi
301301
$api = new Api\Organization\OutsideCollaborators($this);
302302
break;
303303

304+
case 'copilotUsage':
305+
case 'copilot_usage':
306+
$api = new Api\Copilot\Usage($this);
307+
break;
308+
304309
default:
305310
throw new InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name));
306311
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Copilot;
4+
5+
use Github\Api\Copilot\Usage;
6+
use Github\Tests\Api\TestCase;
7+
8+
class UsageTest extends TestCase
9+
{
10+
/**
11+
* @test
12+
*/
13+
public function shouldGetOrgUsageSummary(): void
14+
{
15+
$expectedValue = ['usage1', 'usage2'];
16+
17+
$api = $this->getApiMock();
18+
$api->expects($this->once())
19+
->method('get')
20+
->with('/orgs/KnpLabs/copilot/usage', [])
21+
->will($this->returnValue($expectedValue));
22+
23+
$this->assertEquals($expectedValue, $api->orgUsageSummary('KnpLabs'));
24+
}
25+
26+
/**
27+
* @test
28+
*/
29+
public function shouldGetOrgTeamUsageSummary(): void
30+
{
31+
$expectedValue = ['usage1', 'usage2'];
32+
33+
$api = $this->getApiMock();
34+
$api->expects($this->once())
35+
->method('get')
36+
->with('/orgs/KnpLabs/teams/php-github-api/copilot/usage', [])
37+
->will($this->returnValue($expectedValue));
38+
39+
$this->assertEquals($expectedValue, $api->orgTeamUsageSummary('KnpLabs', 'php-github-api'));
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function shouldGetEnterpriseUsageSummary(): void
46+
{
47+
$expectedValue = ['usage1', 'usage2'];
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('get')
52+
->with('/enterprises/KnpLabs/copilot/usage', [])
53+
->will($this->returnValue($expectedValue));
54+
55+
$this->assertEquals($expectedValue, $api->enterpriseUsageSummary('KnpLabs'));
56+
}
57+
58+
/**
59+
* @test
60+
*/
61+
public function shouldGetEnterpriseTeamUsageSummary(): void
62+
{
63+
$expectedValue = ['usage1', 'usage2'];
64+
65+
$api = $this->getApiMock();
66+
$api->expects($this->once())
67+
->method('get')
68+
->with('/enterprises/KnpLabs/teams/php-github-api/copilot/usage', [])
69+
->will($this->returnValue($expectedValue));
70+
71+
$this->assertEquals($expectedValue, $api->enterpriseTeamUsageSummary('KnpLabs', 'php-github-api'));
72+
}
73+
74+
protected function getApiClass(): string
75+
{
76+
return Usage::class;
77+
}
78+
}

0 commit comments

Comments
 (0)