Skip to content

Commit bf73f6a

Browse files
committed
Add GitHub API integration and MetricsViewer component
1 parent 3f59a6f commit bf73f6a

File tree

7 files changed

+496
-8
lines changed

7 files changed

+496
-8
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"lint": "vue-cli-service lint"
99
},
1010
"dependencies": {
11+
"axios": "^1.6.2",
1112
"core-js": "^3.8.3",
1213
"vue": "^3.2.13"
1314
},

src/App.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template>
22
<img alt="Vue logo" src="./assets/logo.png">
3-
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
3+
<MetricsViewer />
44
</template>
55

66
<script lang="ts">
77
import { defineComponent } from 'vue';
8-
import HelloWorld from './components/HelloWorld.vue';
8+
import MetricsViewer from './components/MetricsViewer.vue';
99
1010
export default defineComponent({
1111
name: 'App',
1212
components: {
13-
HelloWorld
14-
}
13+
MetricsViewer
14+
}
1515
});
1616
</script>
1717

src/api/GitHubApi.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Make a call to the GitHub API to get Copilot Metrics, the API is https://api.github.com/orgs/toussaintt/copilot/usage
2+
//Add the header Accept: application/vnd.github+json to the request
3+
//Add also the Authorization: Bearer <token> header where <token> is hardcoded for now
4+
//Also add X-GitHub-Api-Version: 2022-11-28 header
5+
//Return the response from the API
6+
7+
import axios from "axios";
8+
import { Metrics } from "../model/MetricsData";
9+
10+
export const getGitHubCopilotMetricsApi = async (): Promise<Metrics[]> => {
11+
const response = await axios.get(
12+
"https://api.github.com/orgs/toussaintt/copilot/usage",
13+
{
14+
headers: {
15+
Accept: "application/vnd.github+json",
16+
Authorization: "Bearer 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",
17+
"X-GitHub-Api-Version": "2022-11-28",
18+
},
19+
}
20+
);
21+
22+
// Map the response data to an array of Metrics objects
23+
const metricsData = response.data.map((item: any) => new Metrics(item));
24+
25+
// Print the metrics data to the console
26+
console.log(metricsData);
27+
28+
return metricsData;
29+
};

src/components/MetricsViewer.vue

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<template>
2+
<div>
3+
<h1>GitHub Copilot Metrics</h1>
4+
</div>
5+
<div>
6+
<div v-if="loading">Loading...</div>
7+
<div v-else-if="error">{{ error }}</div>
8+
<div v-else>
9+
<div v-for="metric in metrics" :key="metric.day">
10+
<h2>{{ metric.day }}</h2>
11+
<p>Total Suggestions: {{ metric.total_suggestions_count }}</p>
12+
<p>Total Acceptances: {{ metric.total_acceptances_count }}</p>
13+
<p>Total Lines Suggested: {{ metric.total_lines_suggested }}</p>
14+
<p>Total Lines Accepted: {{ metric.total_lines_accepted }}</p>
15+
<p>Total Active Users: {{ metric.total_active_users }}</p>
16+
<h3>Breakdown</h3>
17+
<div v-for="breakdown in metric.breakdown" :key="breakdown.language">
18+
<h4>{{ breakdown.language }}</h4>
19+
<p>Editor: {{ breakdown.editor }}</p>
20+
<p>Suggestions Count: {{ breakdown.suggestions_count }}</p>
21+
<p>Acceptances Count: {{ breakdown.acceptances_count }}</p>
22+
<p>Lines Suggested: {{ breakdown.lines_suggested }}</p>
23+
<p>Lines Accepted: {{ breakdown.lines_accepted }}</p>
24+
<p>Active Users: {{ breakdown.active_users }}</p>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
</template>
30+
31+
<script lang="ts">
32+
import { defineComponent } from 'vue';
33+
import { getGitHubCopilotMetricsApi } from '../api/GitHubApi';
34+
import { Metrics } from '../model/MetricsData';
35+
36+
export default defineComponent({
37+
name: 'MetricsViewer',
38+
data() {
39+
return {
40+
loading: false,
41+
error: null,
42+
metrics: [] as Metrics[]
43+
};
44+
},
45+
methods: {
46+
async fetchMetrics(): Promise<void> {
47+
console.log('fetchMetrics');
48+
this.loading = true;
49+
this.error = null;
50+
try {
51+
this.metrics = await getGitHubCopilotMetricsApi();
52+
} catch (error) {
53+
this.error = error as any;
54+
} finally {
55+
this.loading = false;
56+
}
57+
}
58+
},
59+
created() {
60+
this.fetchMetrics();
61+
},
62+
});
63+
64+
</script>
65+
66+
<style scoped>
67+
/* Your CSS goes here */
68+
</style>

src/model/MetricsData.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Breakdown {
2+
language: string;
3+
editor: string;
4+
suggestions_count: number;
5+
acceptances_count: number;
6+
lines_suggested: number;
7+
lines_accepted: number;
8+
active_users: number;
9+
10+
constructor(data: any) {
11+
this.language = data.language;
12+
this.editor = data.editor;
13+
this.suggestions_count = data.suggestions_count;
14+
this.acceptances_count = data.acceptances_count;
15+
this.lines_suggested = data.lines_suggested;
16+
this.lines_accepted = data.lines_accepted;
17+
this.active_users = data.active_users;
18+
}
19+
}
20+
21+
export class Metrics {
22+
total_suggestions_count: number;
23+
total_acceptances_count: number;
24+
total_lines_suggested: number;
25+
total_lines_accepted: number;
26+
total_active_users: number;
27+
day: string;
28+
breakdown: Breakdown[];
29+
30+
constructor(data: any) {
31+
this.total_suggestions_count = data.total_suggestions_count;
32+
this.total_acceptances_count = data.total_acceptances_count;
33+
this.total_lines_suggested = data.total_lines_suggested;
34+
this.total_lines_accepted = data.total_lines_accepted;
35+
this.total_active_users = data.total_active_users;
36+
this.day = data.day;
37+
this.breakdown = data.breakdown.map((item: any) => new Breakdown(item));
38+
}
39+
}

0 commit comments

Comments
 (0)