Skip to content

Commit 7f3277d

Browse files
authored
fixing #149 missing seats paging (#151)
* fixing #149 missing seats paging Signed-off-by: Piotr Karpala <[email protected]> * 2.0.1 Signed-off-by: Piotr Karpala <[email protected]> * vitest 2.1.9 * fix test and dockerfile * logs * error handling --------- Signed-off-by: Piotr Karpala <[email protected]>
1 parent ec4f879 commit 7f3277d

File tree

8 files changed

+128
-76
lines changed

8 files changed

+128
-76
lines changed

DEPLOYMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ or navigate using UI:
150150

151151
1. Set a unique name.
152152
2. Provide a home page URL: your company URL or just `http://localhost`.
153-
3. Add a callback URL for `http://localhost:3000/github/auth`. (We'll add the real redirect URL after the application is deployed.)
153+
3. Add a callback URL for `http://localhost:3000/auth/github`. (We'll add the real redirect URL after the application is deployed.)
154154
4. Uncheck the "Webhook -> Active" checkbox.
155155
5. Set the scopes:
156156
- Select **Organization permissions**.

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,17 @@ RUN echo '#!/bin/sh' > /entrypoint.sh && \
3636
echo 'export NUXT_PUBLIC_GITHUB_ENT=${NUXT_PUBLIC_GITHUB_ENT:-$VUE_APP_GITHUB_ENT}' >> /entrypoint.sh && \
3737
echo 'export NUXT_PUBLIC_GITHUB_TEAM=${NUXT_PUBLIC_GITHUB_TEAM:-$VUE_APP_GITHUB_TEAM}' >> /entrypoint.sh && \
3838
echo 'export NUXT_GITHUB_TOKEN=${NUXT_GITHUB_TOKEN:-$VUE_APP_GITHUB_TOKEN}' >> /entrypoint.sh && \
39-
echo 'export NUXT_SESSION_PASSWORD=${NUXT_SESSION_PASSWORD:-$SESSION_SECRET}' >> /entrypoint.sh && \
39+
echo 'export NUXT_SESSION_PASSWORD=${NUXT_SESSION_PASSWORD:-$SESSION_SECRET$SESSION_SECRET$SESSION_SECRET$SESSION_SECRET}' >> /entrypoint.sh && \
4040
echo 'export NUXT_OAUTH_GITHUB_CLIENT_ID=${NUXT_OAUTH_GITHUB_CLIENT_ID:-$GITHUB_CLIENT_ID}' >> /entrypoint.sh && \
4141
echo 'export NUXT_OAUTH_GITHUB_CLIENT_SECRET=${NUXT_OAUTH_GITHUB_CLIENT_SECRET:-$GITHUB_CLIENT_SECRET}' >> /entrypoint.sh && \
42+
# Conditionally set NUXT_PUBLIC_USING_GITHUB_AUTH if GITHUB_CLIENT_ID is provided
43+
echo 'if [ -n "$GITHUB_CLIENT_ID" ]; then' >> /entrypoint.sh && \
44+
echo 'export NUXT_PUBLIC_USING_GITHUB_AUTH=true' >> /entrypoint.sh && \
45+
echo 'fi' >> /entrypoint.sh && \
4246
echo 'node /app/server/index.mjs' >> /entrypoint.sh && \
4347
chmod +x /entrypoint.sh
4448

49+
4550
USER node
4651
ENTRYPOINT [ "/entrypoint.sh" ]
4752

app/components/MainComponent.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@
6060
<BreakdownComponent v-if="item === 'editors'" :metrics="metrics" :breakdown-key="'editor'" />
6161
<CopilotChatViewer v-if="item === 'copilot chat'" :metrics="metrics" />
6262
<SeatsAnalysisViewer v-if="item === 'seat analysis'" :seats="seats" />
63-
<ApiResponse v-if="item === 'api response'" :metrics="metrics" :original-metrics="originalMetrics"
63+
<ApiResponse
64+
v-if="item === 'api response'" :metrics="metrics" :original-metrics="originalMetrics"
6465
:seats="seats" />
6566
</v-card>
6667
</v-window-item>
67-
<v-alert v-show="metricsReady && metrics.length == 0" density="compact" text="No data available to display"
68+
<v-alert
69+
v-show="metricsReady && metrics.length == 0" density="compact" text="No data available to display"
6870
title="No data" type="warning" />
6971
</v-window>
7072

@@ -148,12 +150,13 @@ export default defineNuxtComponent({
148150
break;
149151
case 404:
150152
apiError.value = `404 Not Found - is the ${config.public.scope || ''} org:'${config.public.githubOrg || ''} ent:'${config.public.githubEnt || ''}' team:'${config.public.githubTeam}' correct? ${error.message}`;
151-
// Update apiError with the error message
152-
apiError.value = error.message;
153153
break;
154154
case 500:
155155
apiError.value = `500 Internal Server Error - most likely a bug in the app. Error: ${error.message}`;
156156
break;
157+
default:
158+
apiError.value = `${error.statusCode} Error: ${error.message}`;
159+
break;
157160
}
158161
}
159162
}

e2e-tests/copilot.ent.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { expect, test } from '@playwright/test'
22
import { DashboardPage } from './pages/DashboardPage';
3-
import { aw } from 'vitest/dist/chunks/reporters.D7Jzd9GS.js';
4-
import { a } from 'vitest/dist/chunks/suite.B2jumIFP.js';
53

64
const tag = { tag: ['@ent'] }
75

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "copilot-metrics-viewer",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"private": true,
55
"type": "module",
66
"scripts": {
@@ -40,7 +40,7 @@
4040
"playwright-core": "^1.49.1",
4141
"sass-embedded": "^1.80.3",
4242
"typescript": "^5.6.3",
43-
"vitest": "^2.1.8",
43+
"vitest": "^2.1.9",
4444
"vue-tsc": "^2.1.6",
4545
"vuetify-nuxt-module": "^0.18.3"
4646
}

server/api/metrics.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { CopilotMetrics } from "@/model/Copilot_Metrics";
22
import { convertToMetrics } from '@/model/MetricsToUsageConverter';
33
import type { MetricsApiResponse } from "@/types/metricsApiResponse";
4+
import type FetchError from 'ofetch';
45

56
// TODO: use for storage https://unstorage.unjs.io/drivers/azure
67

78
import { readFileSync } from 'fs';
89
import { resolve } from 'path';
910

10-
1111
export default defineEventHandler(async (event) => {
1212

13+
const logger = console;
1314
const config = useRuntimeConfig(event);
1415
let apiUrl = '';
1516
let mockedDataPath: string;
@@ -34,31 +35,39 @@ export default defineEventHandler(async (event) => {
3435
}
3536

3637
if (config.public.isDataMocked && mockedDataPath) {
37-
// console.log('getting mocked metrics data from:', mockedDataPath);
3838
const path = mockedDataPath;
3939
const data = readFileSync(path, 'utf8');
4040
const dataJson = JSON.parse(data);
4141
// usage is the new API format
4242
const usageData = ensureCopilotMetrics(dataJson);
4343
// metrics is the old API format
4444
const metricsData = convertToMetrics(usageData);
45+
46+
logger.info('Using mocked data');
4547
return { metrics: metricsData, usage: usageData } as MetricsApiResponse;
4648
}
4749

4850
if (!event.context.headers.has('Authorization')) {
51+
logger.error('No Authentication provided');
4952
return new Response('No Authentication provided', { status: 401 });
5053
}
5154

52-
// console.log('getting metrics data from:', apiUrl);
53-
const response = await $fetch(apiUrl, {
54-
headers: event.context.headers
55-
}) as unknown[];
55+
logger.info(`Fetching metrics data from ${apiUrl}`);
5656

57-
// usage is the new API format
58-
const usageData = ensureCopilotMetrics(response as CopilotMetrics[]);
59-
// metrics is the old API format
60-
const metricsData = convertToMetrics(usageData);
61-
return { metrics: metricsData, usage: usageData } as MetricsApiResponse;
57+
try {
58+
const response = await $fetch(apiUrl, {
59+
headers: event.context.headers
60+
}) as unknown[];
61+
62+
// usage is the new API format
63+
const usageData = ensureCopilotMetrics(response as CopilotMetrics[]);
64+
// metrics is the old API format
65+
const metricsData = convertToMetrics(usageData);
66+
return { metrics: metricsData, usage: usageData } as MetricsApiResponse;
67+
} catch (error: FetchError) {
68+
logger.error('Error fetching metrics data:', error);
69+
return new Response('Error fetching metrics data: ' + error, { status: error.statusCode || 500 });
70+
}
6271
})
6372

6473
function ensureCopilotMetrics(data: CopilotMetrics[]): CopilotMetrics[] {

0 commit comments

Comments
 (0)