Skip to content

Commit e313383

Browse files
committed
fixed call for seats
1 parent 32c009e commit e313383

File tree

5 files changed

+15
-45
lines changed

5 files changed

+15
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ docker build -t copilot-metrics-viewer-with-api -f api.Dockerfile .
164164
To run:
165165

166166
```
167-
docker run -p 8080:3000 --env-file ./.env copilot-metrics-viewer-api
167+
docker run -it --rm -p 8080:3000 --env-file ./.env copilot-metrics-viewer-with-api
168168
```
169169

170170
## Azure Deployment

api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "gh-api",
33
"version": "1.0.0",
4-
"main": "index.js",
4+
"main": "server.js",
55
"scripts": {
6-
"start": "node index.mjs",
6+
"start": "node server.mjs",
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"author": "",

api/server.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { createProxyMiddleware } from 'http-proxy-middleware';
88

99
// Construct __dirname equivalent in ES module scope
1010
const __dirname = path.dirname(fileURLToPath(import.meta.url));
11-
//dotenv.config({ path: path.join(__dirname, '.env') });
12-
dotenv.config({ path: path.join(__dirname, '.env.local') });
11+
dotenv.config({ path: path.join(__dirname, '.env') });
12+
//dotenv.config();
1313

1414
const app = express();
1515

src/api/ExtractSeats.ts

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,23 @@ const headers = {
1515
export const getSeatsApi = async (): Promise<Seat[]> => {
1616
const perPage = 50;
1717
let page = 1;
18-
let seatUrl = config.github.apiUrl;
18+
const seatUrl = `${config.github.apiUrl}/copilot/billing/seats`;
1919
let seatsData: Seat[] = [];
2020

2121
let response;
22-
2322

24-
if (process.env.VUE_APP_MOCKED_DATA === "true") {
23+
24+
if (config.mockedData) {
2525
console.log("Using mock data. Check VUE_APP_MOCKED_DATA variable.");
26-
if (process.env.VUE_APP_SCOPE === "organization") {
27-
response = organizationMockedResponse_seats;
28-
}
29-
else if (process.env.VUE_APP_SCOPE === "enterprise") {
30-
response = enterpriseMockedResponse_seats;
31-
}
32-
else {
33-
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
34-
}
35-
seatsData = seatsData.concat(response.seats.map((item: any) => new Seat(item)));
36-
return seatsData;
26+
response = config.scope.type === "organization" ? organizationMockedResponse_seats : enterpriseMockedResponse_seats;
27+
seatsData = seatsData.concat(response.seats.map((item: any) => new Seat(item)));
28+
return seatsData;
3729
}
3830
else {
39-
// if VUE_APP_GITHUB_TOKEN is not set, throw an error
40-
if (!process.env.VUE_APP_GITHUB_TOKEN) {
41-
throw new Error("VUE_APP_GITHUB_TOKEN environment variable is not set.");
42-
return seatsData;
43-
}
44-
else if (process.env.VUE_APP_SCOPE === "organization") {
45-
seatUrl=seatUrl+`orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/billing/seats`;
46-
}
47-
else if (process.env.VUE_APP_SCOPE === "enterprise") {
48-
seatUrl=seatUrl+`enterprises/${process.env.VUE_APP_GITHUB_ENT}/copilot/billing/seats`;
49-
}
50-
else {
51-
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
52-
return seatsData;
53-
}
5431

5532
// Fetch the first page to get the total number of seats
5633
response = await axios.get(seatUrl, {
57-
headers: {
58-
Accept: "application/vnd.github+json",
59-
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
60-
"X-GitHub-Api-Version": "2022-11-28",
61-
},
34+
headers,
6235
params: {
6336
per_page: perPage,
6437
page: page
@@ -73,11 +46,7 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
7346
// Fetch the remaining pages
7447
for (page = 2; page <= totalPages; page++) {
7548
response = await axios.get(seatUrl, {
76-
headers: {
77-
Accept: "application/vnd.github+json",
78-
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
79-
"X-GitHub-Api-Version": "2022-11-28",
80-
},
49+
headers,
8150
params: {
8251
per_page: perPage,
8352
page: page
@@ -86,5 +55,5 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
8655
seatsData = seatsData.concat(response.data.seats.map((item: any) => new Seat(item)));
8756
}
8857
return seatsData;
89-
}
9058
}
59+
}

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ if (!config.mockedData && !config.github.token && !config.github.baseApi) {
5858
export default config;
5959

6060
interface Config {
61+
/** Flag to use mocked data only */
6162
mockedData: boolean;
6263
scope: {
6364
type: 'organization' | 'enterprise';

0 commit comments

Comments
 (0)