66 MergeRequestsSummary ,
77 MergeRequestsStatusSummary ,
88} from './GitlabCIApi' ;
9- import { DiscoveryApi } from '@backstage/core-plugin-api' ;
9+ import { DiscoveryApi , IdentityApi } from '@backstage/core-plugin-api' ;
1010import {
1111 ContributorData ,
1212 MergeRequest ,
@@ -16,28 +16,34 @@ import {
1616export class GitlabCIClient implements GitlabCIApi {
1717 discoveryApi : DiscoveryApi ;
1818 baseUrl : string ;
19+ identityApi : IdentityApi ;
1920 constructor ( {
2021 discoveryApi,
2122 baseUrl = 'https://gitlab.com/' ,
23+ identityApi,
2224 } : {
2325 discoveryApi : DiscoveryApi ;
2426 baseUrl ?: string ;
27+ identityApi : IdentityApi ;
2528 } ) {
2629 this . discoveryApi = discoveryApi ;
2730 this . baseUrl = baseUrl . endsWith ( '/' ) ? baseUrl : `${ baseUrl } /` ;
31+ this . identityApi = identityApi ;
2832 }
2933
3034 private async callApi < T > (
3135 path : string ,
32- query : { [ key in string ] : any } ,
36+ query : { [ key in string ] : any }
3337 ) : Promise < T | [ ] > {
3438 const apiUrl = `${ await this . discoveryApi . getBaseUrl ( 'proxy' ) } /gitlabci` ;
39+ const { token } = await this . identityApi . getCredentials ( ) ;
3540 const response = await fetch (
3641 `${ apiUrl } /${ path } ?${ new URLSearchParams ( query ) . toString ( ) } ` ,
42+ { headers : { Authorization : `Bearer ${ token } ` } }
3743 ) ;
3844 if ( response . status === 200 ) {
3945 return ( await response . json ( ) ) as T ;
40- }
46+ }
4147 return [ ] ;
4248 }
4349
@@ -142,7 +148,7 @@ export class GitlabCIClient implements GitlabCIApi {
142148
143149 async getProjectDetails ( projectSlug ?: string ) : Promise < Object | undefined > {
144150 let projectDetails : any ;
145- if ( projectSlug ) {
151+ if ( projectSlug ) {
146152 projectDetails = await this . callApi < Object > (
147153 'projects/' + encodeURIComponent ( projectSlug ) ,
148154 { } ,
0 commit comments