11import { GithubApi } from './GithubApi' ;
2- import { OAuthApi , FetchApi } from '@backstage/core-plugin-api' ;
2+ import { OAuthApi , FetchApi , ConfigApi } from '@backstage/core-plugin-api' ;
33import { ResponseError } from '@backstage/errors' ;
44import {
55 SearchApiFetchRequest ,
@@ -17,20 +17,30 @@ import {
1717export class GithubClient implements GithubApi {
1818 private readonly authApi : OAuthApi ;
1919 private readonly fetchApi : FetchApi ;
20+ private readonly configApi : ConfigApi ;
2021
21- constructor ( options : { authApi : OAuthApi ; fetchApi : FetchApi } ) {
22+ constructor ( options : {
23+ authApi : OAuthApi ;
24+ fetchApi : FetchApi ;
25+ configApi : ConfigApi ;
26+ } ) {
2227 this . authApi = options . authApi ;
2328 this . fetchApi = options . fetchApi ;
29+ this . configApi = options . configApi ;
2430 }
2531
2632 private async get < T > (
2733 path : string ,
2834 params : { [ key in string ] : any } = { } ,
2935 ) : Promise < T > {
3036 const query = new URLSearchParams ( params ) ;
37+
38+ const baseUrl : string =
39+ this . configApi . get ( 'gh-plugin.url' ) || 'https://api.github.com/' ;
40+
3141 const url = new URL (
3242 `${ path } ?${ query . toString ( ) . replaceAll ( '%2B' , '+' ) } ` ,
33- 'https://api.github.com/' ,
43+ baseUrl ,
3444 ) ;
3545
3646 const token = await this . authApi . getAccessToken ( ) ;
@@ -82,11 +92,9 @@ export class GithubClient implements GithubApi {
8292 ) ;
8393 }
8494
85- public getAuthenticatedUserReposByType ( params : UserRepositoryApiRequest ) : Promise < UserRepositoryApiResponse > {
86- return this . get < UserRepositoryApiResponse > (
87- `/user/repos` ,
88- params ,
89- ) ;
95+ public getAuthenticatedUserReposByType (
96+ params : UserRepositoryApiRequest ,
97+ ) : Promise < UserRepositoryApiResponse > {
98+ return this . get < UserRepositoryApiResponse > ( `/user/repos` , params ) ;
9099 }
91-
92100}
0 commit comments