Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ The language breakdown analysis tab also displays a table showing the Accepted P

## Seat Analysis

![image](https://github.com/DevOps-zhuang/copilot-metrics-viewer/assets/54096296/d1fa9d1d-4fab-4e87-84ba-7be189dd4dd0)
![image](https://private-user-images.githubusercontent.com/54096296/334353713-d1fa9d1d-4fab-4e87-84ba-7be189dd4dd0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg5ODc0MTYsIm5iZiI6MTcxODk4NzExNiwicGF0aCI6Ii81NDA5NjI5Ni8zMzQzNTM3MTMtZDFmYTlkMWQtNGZhYi00ZTg3LTg0YmEtN2JlMTg5ZGQ0ZGQwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIxVDE2MjUxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE1MWE2YmEwYThkODU5MGVmZDc1MDZjNWY5M2MzNzQzNzFjNTZjNjA1Njk0ZDdhZjc1ZjQ5YWJhYjcxMmRiYmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rjuRIhggtvKfIXZxCnQQSsDqrhOt1_jK3jdbbDvn2_A)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I don't have access to https://private-user-images.githubusercontent.com/54096296/334353713-d1fa9d1d-4fab-4e87-84ba-7be189dd4dd0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg5ODc0MTYsIm5iZiI6MTcxODk4NzExNiwicGF0aCI6Ii81NDA5NjI5Ni8zMzQzNTM3MTMtZDFmYTlkMWQtNGZhYi00ZTg3LTg0YmEtN2JlMTg5ZGQ0ZGQwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIxVDE2MjUxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE1MWE2YmEwYThkODU5MGVmZDc1MDZjNWY5M2MzNzQzNzFjNTZjNjA1Njk0ZDdhZjc1ZjQ5YWJhYjcxMmRiYmEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rjuRIhggtvKfIXZxCnQQSsDqrhOt1_jK3jdbbDvn2_A I assume this might apply to other users as well.
Please consider either including the image file in the repo or embedding the image as a base64 encoded string.

Copy link
Contributor Author

@DevOps-zhuang DevOps-zhuang Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, and I want to follow the format like 'https://github.com/github-copilot-resources/copilot-metrics-viewer/assets/3329307/79867d5f-8933-4509-a58a-8c6deeb47536', however, didn't find the assets folder in the repo. I guess it is from the other way to update the image files, then used in readme? thanks.

I tried to post the files here, and then get the url, will try use it in readme. though not sure whether it is a popular way :-)

image


1. **Total Assigned:** This metric represents the total number of Copilot seats assigned within current organization.
1. **Total Assigned:** This metric represents the total number of Copilot seats assigned within current organization/enterprise.

2. **Assigned But Never Used:** This metric shows seats that were assigned but never within the current organization. The assigned timestamp is also displayed in the below chart.
2. **Assigned But Never Used:** This metric shows seats that were assigned but never within the current organization/enterprise. The assigned timestamp is also displayed in the below chart.

3. **No Activity in the Last 7 days:** never used seats or seats used, but with no activity in the past 7 days.

Expand Down
92 changes: 57 additions & 35 deletions src/api/ExtractSeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,64 @@ import enterpriseMockedResponse_seats from '../assets/enterprise_response_sample
export const getSeatsApi = async (): Promise<Seat[]> => {
const perPage = 50;
let page = 1;
let seatUrl = `https://api.github.com/`;
let seatsData: Seat[] = [];

let response;
if (process.env.VUE_APP_SCOPE !== "organization") {
// when the scope is not organization, return seatsData,by default it will return empty array
return seatsData;
}
else{
if (process.env.VUE_APP_MOCKED_DATA === "true") {
response = organizationMockedResponse_seats;


if (process.env.VUE_APP_MOCKED_DATA === "true") {
console.log("Using mock data. Check VUE_APP_MOCKED_DATA variable.");
if (process.env.VUE_APP_SCOPE === "organization") {
response = organizationMockedResponse_seats;
}
else if (process.env.VUE_APP_SCOPE === "enterprise") {
response = enterpriseMockedResponse_seats;
}
else {
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
}
seatsData = seatsData.concat(response.seats.map((item: any) => new Seat(item)));
}
else if (process.env.VUE_APP_MOCKED_DATA === "false") {
return seatsData;
}
else {
// if VUE_APP_GITHUB_TOKEN is not set, throw an error
if (!process.env.VUE_APP_GITHUB_TOKEN) {
throw new Error("VUE_APP_GITHUB_TOKEN environment variable is not set.");
return seatsData;
}
else if (process.env.VUE_APP_SCOPE === "organization") {
seatUrl=seatUrl+`orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/billing/seats`;
}
else if (process.env.VUE_APP_SCOPE === "enterprise") {
seatUrl=seatUrl+`enterprises/${process.env.VUE_APP_GITHUB_ENT}/copilot/billing/seats`;
}
else {
throw new Error(`Invalid VUE_APP_SCOPE value: ${process.env.VUE_APP_SCOPE}. Expected "organization" or "enterprise".`);
return seatsData;
}

// Fetch the first page to get the total number of seats
response = await axios.get(`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/billing/seats`, {
response = await axios.get(seatUrl, {
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
params: {
per_page: perPage,
page: page
}
});

seatsData = seatsData.concat(response.data.seats.map((item: any) => new Seat(item)));
// Calculate the total pages
const totalSeats = response.data.total_seats;
const totalPages = Math.ceil(totalSeats / perPage);

// Fetch the remaining pages
for (page = 2; page <= totalPages; page++) {
response = await axios.get(seatUrl, {
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
Expand All @@ -33,29 +76,8 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
page: page
}
});

seatsData = seatsData.concat(response.data.seats.map((item: any) => new Seat(item)));
// Calculate the total pages
const totalSeats = response.data.total_seats;
const totalPages = Math.ceil(totalSeats / perPage);

// Fetch the remaining pages
for (page = 2; page <= totalPages; page++) {
response = await axios.get(`https://api.github.com/orgs/${process.env.VUE_APP_GITHUB_ORG}/copilot/billing/seats`, {
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${process.env.VUE_APP_GITHUB_TOKEN}`,
"X-GitHub-Api-Version": "2022-11-28",
},
params: {
per_page: perPage,
page: page
}
});

seatsData = seatsData.concat(response.data.seats.map((item: any) => new Seat(item)));
} //end of else if (process.env.VUE_APP_MOCKED_DATA === "false")
} //end of else if (process.env.VUE_APP_SCOPE !== "organization")
return seatsData;
}
}
}
return seatsData;
}
}
2 changes: 1 addition & 1 deletion src/assets/enterprise_response_sample_seats.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"last_activity_at": "2021-10-14T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octocat",
"login": "octocat_byEnterprise",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
Expand Down
4 changes: 2 additions & 2 deletions src/assets/organization_response_sample_seats.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"last_activity_at": "2021-10-14T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octocat",
"login": "octocat_org",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
Expand Down Expand Up @@ -50,7 +50,7 @@
"last_activity_at": "2021-10-13T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octokitten",
"login": "octokitten_org",
"id": 1,
"node_id": "MDQ76VNlcjE=",
"avatar_url": "https://github.com/images/error/octokitten_happy.gif",
Expand Down
4 changes: 2 additions & 2 deletions src/components/ApiResponse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</div>

<br><br>
<div v-if="vueAppScope === 'organization'">
<!--<div v-if="vueAppScope === 'organization'">-->

<v-card max-height="575px" class="overflow-y-auto">
<pre ref="jsonText">{{ JSON.stringify(seats, null, 2) }}</pre>
</v-card>
Expand All @@ -24,7 +25,6 @@
<div v-if="showSeatMessage" :class="{'copy-message': true, 'error': isError}">{{ message }}</div>
</transition>
</div>
</div>
</v-container>
</template>

Expand Down
10 changes: 5 additions & 5 deletions src/components/MainComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
<BreakdownComponent v-if="item === 'languages'" :metrics="metrics" :breakdownKey="'language'"/>
<BreakdownComponent v-if="item === 'editors'" :metrics="metrics" :breakdownKey="'editor'"/>
<CopilotChatViewer v-if="item === 'copilot chat'" :metrics="metrics" />
<div v-if="isScopeOrganization">
<!--<div v-if="isScopeOrganization">-->
<SeatsAnalysisViewer v-if="item === 'seat analysis'" :seats="seats" />
</div>
<!--</div>-->
<ApiResponse v-if="item === 'api response'" :metrics="metrics" :seats="seats" />
</v-card>
</v-window-item>
Expand Down Expand Up @@ -94,23 +94,23 @@ export default defineComponent({
},
data () {
return {
tabItems: ['languages', 'editors', 'copilot chat', 'api response'],
tabItems: ['languages', 'editors', 'copilot chat','seat analysis' , 'api response'],
tab: null
}
},
created() {
if(this.itemName !== 'invalid'){
this.tabItems.unshift(this.itemName);
}
if (process.env.VUE_APP_SCOPE === 'organization') {
/* if (process.env.VUE_APP_SCOPE === 'organization') {
// get the last item in the array,which is 'api response'
//and add 'seat analysis' before it
let lastItem = this.tabItems.pop();
this.tabItems.push('seat analysis');
if (lastItem) {
this.tabItems.push(lastItem);
}
}
} */
},
setup() {
const metricsReady = ref(false);
Expand Down