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