-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from DevOps-zhuang/feature/SeatAnalysis
add copilot seat analysis supports
- Loading branch information
Showing
8 changed files
with
513 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// TypeScript | ||
import axios from "axios"; | ||
import { Seat } from "../model/Seat"; | ||
|
||
import organizationMockedResponse_seats from '../assets/organization_response_sample_seats.json'; | ||
import enterpriseMockedResponse_seats from '../assets/enterprise_response_sample_seats.json'; | ||
|
||
export const getSeatsApi = async (): Promise<Seat[]> => { | ||
const perPage = 50; | ||
let page = 1; | ||
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; | ||
seatsData = seatsData.concat(response.seats.map((item: any) => new Seat(item))); | ||
} | ||
else if (process.env.VUE_APP_MOCKED_DATA === "false") { | ||
// 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`, { | ||
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(`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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"total_seats": 2, | ||
"seats": [ | ||
{ | ||
"created_at": "2021-08-03T18:00:00-06:00", | ||
"updated_at": "2021-09-23T15:00:00-06:00", | ||
"pending_cancellation_date": null, | ||
"last_activity_at": "2021-10-14T00:53:32-06:00", | ||
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82", | ||
"assignee": { | ||
"login": "octocat", | ||
"id": 1, | ||
"node_id": "MDQ6VXNlcjE=", | ||
"avatar_url": "https://github.com/images/error/octocat_happy.gif", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/octocat", | ||
"html_url": "https://github.com/octocat", | ||
"followers_url": "https://api.github.com/users/octocat/followers", | ||
"following_url": "https://api.github.com/users/octocat/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions", | ||
"organizations_url": "https://api.github.com/users/octocat/orgs", | ||
"repos_url": "https://api.github.com/users/octocat/repos", | ||
"events_url": "https://api.github.com/users/octocat/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/octocat/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"assigning_team": { | ||
"id": 1, | ||
"node_id": "MDQ6VGVhbTE=", | ||
"url": "https://api.github.com/teams/1", | ||
"html_url": "https://github.com/orgs/github/teams/justice-league", | ||
"name": "Justice League", | ||
"slug": "justice-league", | ||
"description": "A great team.", | ||
"privacy": "closed", | ||
"notification_setting": "notifications_enabled", | ||
"permission": "admin", | ||
"members_url": "https://api.github.com/teams/1/members{/member}", | ||
"repositories_url": "https://api.github.com/teams/1/repos", | ||
"parent": null | ||
} | ||
}, | ||
{ | ||
"created_at": "2021-09-23T18:00:00-06:00", | ||
"updated_at": "2021-09-23T15:00:00-06:00", | ||
"pending_cancellation_date": "2021-11-01", | ||
"last_activity_at": "2021-10-13T00:53:32-06:00", | ||
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82", | ||
"assignee": { | ||
"login": "octokitten", | ||
"id": 1, | ||
"node_id": "MDQ76VNlcjE=", | ||
"avatar_url": "https://github.com/images/error/octokitten_happy.gif", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/octokitten", | ||
"html_url": "https://github.com/octokitten", | ||
"followers_url": "https://api.github.com/users/octokitten/followers", | ||
"following_url": "https://api.github.com/users/octokitten/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/octokitten/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/octokitten/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/octokitten/subscriptions", | ||
"organizations_url": "https://api.github.com/users/octokitten/orgs", | ||
"repos_url": "https://api.github.com/users/octokitten/repos", | ||
"events_url": "https://api.github.com/users/octokitten/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/octokitten/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"total_seats": 2, | ||
"seats": [ | ||
{ | ||
"created_at": "2021-08-03T18:00:00-06:00", | ||
"updated_at": "2021-09-23T15:00:00-06:00", | ||
"pending_cancellation_date": null, | ||
"last_activity_at": "2021-10-14T00:53:32-06:00", | ||
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82", | ||
"assignee": { | ||
"login": "octocat", | ||
"id": 1, | ||
"node_id": "MDQ6VXNlcjE=", | ||
"avatar_url": "https://github.com/images/error/octocat_happy.gif", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/octocat", | ||
"html_url": "https://github.com/octocat", | ||
"followers_url": "https://api.github.com/users/octocat/followers", | ||
"following_url": "https://api.github.com/users/octocat/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions", | ||
"organizations_url": "https://api.github.com/users/octocat/orgs", | ||
"repos_url": "https://api.github.com/users/octocat/repos", | ||
"events_url": "https://api.github.com/users/octocat/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/octocat/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
}, | ||
"assigning_team": { | ||
"id": 1, | ||
"node_id": "MDQ6VGVhbTE=", | ||
"url": "https://api.github.com/teams/1", | ||
"html_url": "https://github.com/orgs/github/teams/justice-league", | ||
"name": "Justice League", | ||
"slug": "justice-league", | ||
"description": "A great team.", | ||
"privacy": "closed", | ||
"notification_setting": "notifications_enabled", | ||
"permission": "admin", | ||
"members_url": "https://api.github.com/teams/1/members{/member}", | ||
"repositories_url": "https://api.github.com/teams/1/repos", | ||
"parent": null | ||
} | ||
}, | ||
{ | ||
"created_at": "2021-09-23T18:00:00-06:00", | ||
"updated_at": "2021-09-23T15:00:00-06:00", | ||
"pending_cancellation_date": "2021-11-01", | ||
"last_activity_at": "2021-10-13T00:53:32-06:00", | ||
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82", | ||
"assignee": { | ||
"login": "octokitten", | ||
"id": 1, | ||
"node_id": "MDQ76VNlcjE=", | ||
"avatar_url": "https://github.com/images/error/octokitten_happy.gif", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/octokitten", | ||
"html_url": "https://github.com/octokitten", | ||
"followers_url": "https://api.github.com/users/octokitten/followers", | ||
"following_url": "https://api.github.com/users/octokitten/following{/other_user}", | ||
"gists_url": "https://api.github.com/users/octokitten/gists{/gist_id}", | ||
"starred_url": "https://api.github.com/users/octokitten/starred{/owner}{/repo}", | ||
"subscriptions_url": "https://api.github.com/users/octokitten/subscriptions", | ||
"organizations_url": "https://api.github.com/users/octokitten/orgs", | ||
"repos_url": "https://api.github.com/users/octokitten/repos", | ||
"events_url": "https://api.github.com/users/octokitten/events{/privacy}", | ||
"received_events_url": "https://api.github.com/users/octokitten/received_events", | ||
"type": "User", | ||
"site_admin": false | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.