Add todo and find config by hostname

This commit is contained in:
Mikael Östberg
2020-12-09 11:05:29 +01:00
parent a3cb631ca5
commit d0c62e7dc7
@@ -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}`);