Skip to content

Commit b21bfa7

Browse files
committed
Refactor API calls and add support for Enterprise charts via the addition of scopes
1 parent ac9105f commit b21bfa7

File tree

13 files changed

+29708
-400
lines changed

13 files changed

+29708
-400
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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

11+
VUE_APP_GITHUB_ENT=
12+
13+
# Determines the GitHub Personal Access Token to use for API calls.
514
VUE_APP_GITHUB_TOKEN=

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: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,53 @@
77
import axios from "axios";
88

99
import { Metrics } from "../model/MetricsData";
10-
import data from '../assets/copilot_metrics_response_sample.json';
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
}

0 commit comments

Comments
 (0)