@roadiehq/backstage-plugin-github-insights
Version:
31 lines (28 loc) • 1.02 kB
JavaScript
import { useApi } from '@backstage/core-plugin-api';
import { scmIntegrationsApiRef } from '@backstage/integration-react';
import { ANNOTATION_SOURCE_LOCATION, ANNOTATION_LOCATION, parseLocationRef } from '@backstage/catalog-model';
const defaultGithubIntegration = {
hostname: "github.com",
baseUrl: "https://api.github.com"
};
const useEntityGithubScmIntegration = (entity) => {
const integrations = useApi(scmIntegrationsApiRef);
if (!entity) {
return defaultGithubIntegration;
}
let location = entity.metadata.annotations?.[ANNOTATION_SOURCE_LOCATION];
if (!location) {
location = entity.metadata.annotations?.[ANNOTATION_LOCATION];
}
const { target } = parseLocationRef(location || "");
const scm = integrations.github.byUrl(target);
if (scm) {
return {
hostname: scm.config.host,
baseUrl: scm.config.apiBaseUrl
};
}
return defaultGithubIntegration;
};
export { useEntityGithubScmIntegration };
//# sourceMappingURL=useEntityGithubScmIntegration.esm.js.map