import { useApi } from '@backstage/core-plugin-api' ; import { scmIntegrationsApiRef } from '@backstage/integration-react' ; import { Entity , parseLocationReference , LOCATION_ANNOTATION , SOURCE_LOCATION_ANNOTATION , } from '@backstage/catalog-model' ; const defaultGithubIntegration = { hostname : 'github.com' , baseUrl : 'https://api.github.com' , } ; export const useEntityGithubScmIntegration = ( entity ) => { const integrations = useApi ( scmIntegrationsApiRef ) ; if ( ! entity ) { return defaultGithubIntegration ; } let location = entity . metadata . annotations ?. [ SOURCE_LOCATION_ANNOTATION ] ; if ( ! location ) { location = entity . metadata . annotations ?. [ LOCATION_ANNOTATION ] ; } const { target } = parseLocationReference ( location || '' ) ; const scm = integrations . github . byUrl ( target ) ; if ( scm ) { return { hostname : scm . config . host , baseUrl : scm . config . apiBaseUrl , } ; } return defaultGithubIntegration ; } ;