Skip to content

Commit a6f0f4f

Browse files
authoredSep 23, 2024··
feature #1142 Copilot Usage Endpoints (anthony-webart)
This PR was squashed before being merged into the 3.14-dev branch. Discussion ---------- Commits ------- f4e822e Add Copilot usage endpoints e16a14c Reformat code 3698933 Fix incorrect team urls 956fe9e Add Copilot Usage API Documentation detailing endpoints for retrieving usage summaries.
1 parent f8f6a95 commit a6f0f4f

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed
 

‎doc/copilot/usage.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copilot Usage API Documentation
2+
[Back to the navigation](../README.md)
3+
4+
## Overview
5+
6+
The Copilot Usage API provides endpoints to retrieve usage summaries for organizations and enterprises.
7+
8+
**Note**: This endpoint is in beta and is subject to change.
9+
10+
## Endpoints
11+
12+
### Organization Usage Summary
13+
14+
Retrieve the usage summary for a specific organization.
15+
16+
**Method:** `GET`
17+
18+
**Endpoint:** `/orgs/{organization}/copilot/usage`
19+
20+
**Parameters:**
21+
- `organization` (string): The name of the organization.
22+
- `params` (array, optional): Additional query parameters.
23+
24+
**Example:**
25+
```php
26+
$usage = $client->api('copilotUsage')->orgUsageSummary('KnpLabs');
27+
```
28+
29+
### Organization Team Usage Summary
30+
31+
Retrieve the usage summary for a specific team within an organization.
32+
33+
**Method:** `GET`
34+
35+
**Endpoint:** `/orgs/{organization}/team/{team}/copilot/usage`
36+
37+
**Parameters:**
38+
- `organization` (string): The name of the organization.
39+
- `team` (string): The name of the team.
40+
- `params` (array, optional): Additional query parameters.
41+
42+
**Example:**
43+
```php
44+
$usage = $client->api('copilotUsage')->orgTeamUsageSummary('KnpLabs', 'developers');
45+
```
46+
47+
### Enterprise Usage Summary
48+
49+
Retrieve the usage summary for a specific enterprise.
50+
51+
**Method:** `GET`
52+
53+
**Endpoint:** `/enterprises/{enterprise}/copilot/usage`
54+
55+
**Parameters:**
56+
- `enterprise` (string): The name of the enterprise.
57+
- `params` (array, optional): Additional query parameters.
58+
59+
**Example:**
60+
```php
61+
$usage = $client->api('copilotUsage')->enterpriseUsageSummary('KnpLabs');
62+
```
63+
64+
### Enterprise Team Usage Summary
65+
66+
Retrieve the usage summary for a specific team within an enterprise.
67+
68+
**Method:** `GET`
69+
70+
**Endpoint:** `/enterprises/{enterprise}/team/{team}/copilot/usage`
71+
72+
**Parameters:**
73+
- `enterprise` (string): The name of the enterprise.
74+
- `team` (string): The name of the team.
75+
- `params` (array, optional): Additional query parameters.
76+
77+
**Example:**
78+
```php
79+
$usage = $client->api('copilotUsage')->enterpriseTeamUsageSummary('KnpLabs', 'developers');
80+
```

‎lib/Github/Api/Copilot/Usage.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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(
17+
'/orgs/'.rawurlencode($organization).'/team/'.rawurlencode($teamSlug).'/copilot/usage',
18+
$params
19+
);
20+
}
21+
22+
public function enterpriseUsageSummary(string $enterprise, array $params = []): array
23+
{
24+
return $this->get('/enterprises/'.rawurlencode($enterprise).'/copilot/usage', $params);
25+
}
26+
27+
public function enterpriseTeamUsageSummary(string $enterprise, string $teamSlug, array $params = []): array
28+
{
29+
return $this->get(
30+
'/enterprises/'.rawurlencode($enterprise).'/team/'.rawurlencode($teamSlug).'/copilot/usage',
31+
$params
32+
);
33+
}
34+
}

‎lib/Github/Client.php

+5
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
}
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/team/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/team/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)
Please sign in to comment.