Skip to content

Commit f227a05

Browse files
authored
Merge pull request #23 from github-copilot-resources/feature/enterprise-team-slice-calls
Add support to Enterprise level metrics
2 parents ac9105f + b10cbee commit f227a05

21 files changed

+29844
-444
lines changed

.env

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
# Determines if mocked data should be used instead of making API calls.
12
VUE_APP_MOCKED_DATA=true
23

4+
# Determines the scope of the API calls.
5+
# Can be 'enterprise' or 'organization' to target API calls to an enterprise or an organization respectively.
6+
VUE_APP_SCOPE=organization
7+
8+
# Determines the enterprise or organization name to target API calls.
39
VUE_APP_GITHUB_ORG=octodemo
410

5-
VUE_APP_GITHUB_TOKEN=
11+
VUE_APP_GITHUB_ENT=
12+
13+
# Determines the GitHub Personal Access Token to use for API calls.
14+
# Create with scopes copilot, manage_billing:copilot, admin:enterprise, or manage_billing:enterprise, read:enterprise AND read:org
15+
VUE_APP_GITHUB_TOKEN=

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,40 @@ The language breakdown analysis tab also displays a table showing the Accepted P
7272

7373
## Setup instructions
7474

75-
- Instructions on how to authenticate are provided in the [API documentation](https://docs.github.com/en/enterprise-cloud@latest/rest/copilot/copilot-usage?apiVersion=2022-11-28)
75+
Instructions on how to authenticate are provided in the [API documentation](https://docs.github.com/en/enterprise-cloud@latest/rest/copilot/copilot-usage?apiVersion=2022-11-28)
76+
77+
In the `.env` file, you can configure several environment variables that control the behavior of the application.
78+
79+
#### VUE_APP_SCOPE
80+
81+
The `VUE_APP_SCOPE` environment variable in the `.env` file determines the scope of the API calls made by the application. It can be set to either 'enterprise' or 'organization'.
82+
83+
- If set to 'enterprise', the application will target API calls to the GitHub Enterprise account defined in the `VUE_APP_GITHUB_ENT` variable.
84+
- If set to 'organization', the application will target API calls to the GitHub Organization account defined in the `VUE_APP_GITHUB_ORG` variable.
85+
86+
For example, if you want to target the API calls to an organization, you would set `VUE_APP_SCOPE=organization` in the `.env` file.
87+
88+
````
89+
VUE_APP_SCOPE=organization
90+
91+
VUE_APP_GITHUB_ORG= <YOUR-ORGANIZATION>
92+
93+
VUE_APP_GITHUB_ENT=
94+
````
95+
96+
97+
#### VUE_APP_MOCKED_DATA
98+
99+
To access Copilot metrics from the last 28 days via the API and display actual data, set the following boolean environment variable to `false`:
76100

77-
### .env file setup
78-
- To retrieve Copilot metrics via the API and display your organization's data, configure the following boolean environment variable to false:
79101
```
80102
VUE_APP_MOCKED_DATA=false
81103
```
82-
- Additionally, update the following environment variables:
104+
105+
#### VUE_APP_GITHUB_TOKEN
106+
Specifies the GitHub Personal Access Token utilized for API requests. Generate this token with the following scopes: _copilot_, _manage_billing:copilot_, _manage_billing:enterprise_, _read:enterprise_, _admin:org_.
83107

84108
```
85-
VUE_APP_GITHUB_ORG=
86109
VUE_APP_GITHUB_TOKEN=
87110
```
88111

@@ -120,4 +143,5 @@ This project is licensed under the terms of the MIT open source license. Please
120143
I aim to provide support through GitHub Issues. While I strive to stay responsive, I can't guarantee immediate responses. For critical issues, please include "CRITICAL" in the title for quicker attention.
121144

122145
### Coming next 🔮
123-
- Enterprise level charts
146+
- Team slicing
147+
- Persistence layer

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copilot-metrics-viewer",
3-
"version": "1.2.0",
3+
"version": "1.4.0",
44
"private": true,
55
"scripts": {
66
"serve": "vue-cli-service serve",

public/assets/copilotLogo.png

-2.91 KB
Binary file not shown.

public/assets/[email protected]

26.9 KB
Loading

public/favicon.ico

-4.19 KB
Binary file not shown.

public/favicon.svg

Lines changed: 3 additions & 0 deletions
Loading

public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7-
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
7+
<link rel="icon" href="<%= BASE_URL %>favicon.svg">
88
<title><%= htmlWebpackPlugin.options.title %></title>
99
</head>
1010
<body>

src/api/GitHubApi.ts

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,69 @@
66

77
import axios from "axios";
88

9-
import { Metrics } from "../model/MetricsData";
10-
import data from '../assets/copilot_metrics_response_sample.json';
9+
import { Metrics } from "../model/Metrics";
10+
import organizationMockedResponse from '../assets/organization_response_sample.json';
11+
import enterpriseMockedResponse from '../assets/enterprise_response_sample.json';
1112

12-
export const getGitHubCopilotMetricsApi = async (): Promise<Metrics[]> => {
13+
14+
export const getMetricsApi = async (): Promise<Metrics[]> => {
1315

1416
let response;
1517
let metricsData;
1618

1719
if (process.env.VUE_APP_MOCKED_DATA === "true") {
18-
response = data;
20+
21+
if (process.env.VUE_APP_SCOPE === "organization") {
22+
response = organizationMockedResponse;
23+
} else if (process.env.VUE_APP_SCOPE === "enterprise") {
24+
response = enterpriseMockedResponse;
25+
} else {
26+
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
27+
}
28+
1929
metricsData = response.map((item: any) => new Metrics(item));
2030
} else {
21-
response = await axios.get(
22-
`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`,
23-
{
24-
headers: {
25-
Accept: "application/vnd.github+json",
26-
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
27-
"X-GitHub-Api-Version": "2022-11-28",
28-
},
29-
}
30-
);
31+
if (process.env.VUE_APP_SCOPE === "organization") {
32+
response = await axios.get(
33+
`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`,
34+
{
35+
headers: {
36+
Accept: "application/vnd.github+json",
37+
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
38+
"X-GitHub-Api-Version": "2022-11-28",
39+
},
40+
}
41+
);
42+
} else if (process.env.VUE_APP_SCOPE === "enterprise") {
43+
44+
response = await axios.get(
45+
`https://api.github.com/enterprises/${process.env.VUE_APP_GITHUB_ENT}/copilot/usage`,
46+
{
47+
headers: {
48+
Accept: "application/vnd.github+json",
49+
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
50+
"X-GitHub-Api-Version": "2022-11-28",
51+
},
52+
}
53+
);
54+
} else {
55+
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
56+
}
3157

3258
metricsData = response.data.map((item: any) => new Metrics(item));
3359
}
3460
return metricsData;
35-
};
61+
};
62+
63+
export const getTeams = async (): Promise<string[]> =>{
64+
const response = await axios.get(`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/teams`, {
65+
headers: {
66+
Accept: 'application/vnd.github+json',
67+
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
68+
'X-GitHub-Api-Version': '2022-11-28',
69+
},
70+
});
71+
72+
return response.data;
73+
}
74+

0 commit comments

Comments
 (0)