Skip to content

Commit 96986aa

Browse files
authored
Merge pull request #9 from github-copilot-community/feature/mocked-data
Update environment variables and resolve JSON module in tsconfig.json
2 parents ce51609 + 3dbebc8 commit 96986aa

File tree

5 files changed

+11020
-13
lines changed

5 files changed

+11020
-13
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
VUE_APP_MOCKED_DATA=true
2+
13
VUE_APP_GITHUB_ORG=
4+
25
VUE_APP_GITHUB_TOKEN=

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ Your organization must be enrolled in the GitHub Copilot API private alpha.
5454
## Setup instructions
5555

5656
- Instructions on how to authenticate are provided in the API documentation - available if you have access to the private alpha.
57-
- Edit the .env file in the root directory of the project and add the following variables:
57+
58+
### .env file setup
59+
- To utilize mocked data stored in a JSON file, simply set the following boolean environment variable to true:
60+
```
61+
VUE_APP_MOCKED_DATA=true
62+
```
63+
- To access Copilot metrics through the API, update your configuration by adding the following variables:
5864

5965
```
6066
VUE_APP_GITHUB_ORG=

src/api/GitHubApi.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,31 @@
55
//Return the response from the API
66

77
import axios from "axios";
8+
89
import { Metrics } from "../model/MetricsData";
10+
import data from '../assets/copilot_metrics_response_sample.json';
911

1012
export const getGitHubCopilotMetricsApi = async (): Promise<Metrics[]> => {
11-
const response = await axios.get(
12-
`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/usage`,
13-
{
14-
headers: {
15-
Accept: "application/vnd.github+json",
16-
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
17-
"X-GitHub-Api-Version": "2022-11-28",
18-
},
19-
}
20-
);
13+
14+
let response;
15+
let metricsData;
2116

22-
// Map the response data to an array of Metrics objects
23-
const metricsData = response.data.map((item: any) => new Metrics(item));
17+
if (process.env.VUE_APP_MOCKED_DATA === "true") {
18+
response = data;
19+
metricsData = response.map((item: any) => new Metrics(item));
20+
} 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+
);
2431

32+
metricsData = response.data.map((item: any) => new Metrics(item));
33+
}
2534
return metricsData;
2635
};

0 commit comments

Comments
 (0)