@@ -15,50 +15,23 @@ const headers = {
15
15
export const getSeatsApi = async ( ) : Promise < Seat [ ] > => {
16
16
const perPage = 50 ;
17
17
let page = 1 ;
18
- let seatUrl = config . github . apiUrl ;
18
+ const seatUrl = ` ${ config . github . apiUrl } /copilot/billing/seats` ;
19
19
let seatsData : Seat [ ] = [ ] ;
20
20
21
21
let response ;
22
-
23
22
24
- if ( process . env . VUE_APP_MOCKED_DATA === "true" ) {
23
+
24
+ if ( config . mockedData ) {
25
25
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 ;
37
29
}
38
30
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
- }
54
31
55
32
// Fetch the first page to get the total number of seats
56
33
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,
62
35
params : {
63
36
per_page : perPage ,
64
37
page : page
@@ -73,11 +46,7 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
73
46
// Fetch the remaining pages
74
47
for ( page = 2 ; page <= totalPages ; page ++ ) {
75
48
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,
81
50
params : {
82
51
per_page : perPage ,
83
52
page : page
@@ -86,5 +55,5 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
86
55
seatsData = seatsData . concat ( response . data . seats . map ( ( item : any ) => new Seat ( item ) ) ) ;
87
56
}
88
57
return seatsData ;
89
- }
90
58
}
59
+ }
0 commit comments