diff --git a/plugins/catalog-import/src/util/useGithubRepos.ts b/plugins/catalog-import/src/util/useGithubRepos.ts index af1ef43c73..7f49bb3363 100644 --- a/plugins/catalog-import/src/util/useGithubRepos.ts +++ b/plugins/catalog-import/src/util/useGithubRepos.ts @@ -18,6 +18,9 @@ import * as YAML from 'yaml'; import { useApi, configApiRef } from '@backstage/core'; import { catalogImportApiRef } from '../api/CatalogImportApi'; import { ConfigSpec } from '../components/ImportComponentPage'; + +//TODO: O5ten, refactor into a core API instead of direct usage like this +//https://github.com/backstage/backstage/pull/3613#issuecomment-7408929430 import { readGitHubIntegrationConfigs } from '@backstage/integration'; export function useGithubRepos() { @@ -25,11 +28,14 @@ export function useGithubRepos() { const config = useApi(configApiRef); const submitPrToRepo = async (selectedRepo: ConfigSpec) => { - const [ownerName, repoName] = selectedRepo.location.split('/').slice(-2); + const [hostname, ownerName, repoName] = selectedRepo.location.split('/').slice(-3); const configs = readGitHubIntegrationConfigs( - config.getOptionalConfigArray('integrations.github') ?? [], - ); - const githubIntegrationConfig = configs[0]; + config.getOptionalConfigArray('integrations.github') ?? [] + ) + const githubIntegrationConfig = configs.find(v => v.host === hostname); + if(!githubIntegrationConfig) { + throw new Error(`Unable to locate github-integration for repo-location: ${selectedRepo.location}`); + } const submitPRResponse = await api .submitPrToRepo({ owner: ownerName, @@ -37,7 +43,7 @@ export function useGithubRepos() { fileContent: selectedRepo.config .map(entity => `---\n${YAML.stringify(entity)}`) .join('\n'), - githubIntegrationConfig, + githubIntegrationConfig }) .catch(e => { throw new Error(`Failed to submit PR to repo:\n${e.message}`);