import { configApiRef , useApi } from '@backstage/core-plugin-api' ; import { Entity , getEntitySourceLocation } from "@backstage/catalog-model" ; export const useGitHubConfig = ( entity ) => { const config = useApi ( configApiRef ) ; const providerConfigs = config . getOptionalConfigArray ( 'integrations.github' ) ?? [ ] ; const location = getEntitySourceLocation ( entity ) ; if ( location . type === 'url' && location . target . length > 0 ) { const locationHost = new URL ( location . target ) . host ; return providerConfigs . find ( providerConfig => providerConfig ?. getOptionalString ( "host" ) === locationHost ) ; } return providerConfigs [ 0 ] ; } ;