|
7 | 7 | import axios from "axios";
|
8 | 8 |
|
9 | 9 | 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'; |
11 | 12 |
|
12 |
| -export const getGitHubCopilotMetricsApi = async (): Promise<Metrics[]> => { |
| 13 | + |
| 14 | +export const getMetricsApi = async (): Promise<Metrics[]> => { |
13 | 15 |
|
14 | 16 | let response;
|
15 | 17 | let metricsData;
|
16 | 18 |
|
17 | 19 | 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 | + |
19 | 29 | metricsData = response.map((item: any) => new Metrics(item));
|
20 | 30 | } 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 | + } |
31 | 57 |
|
32 | 58 | metricsData = response.data.map((item: any) => new Metrics(item));
|
33 | 59 | }
|
|
0 commit comments