diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts
index 706943a6aa..4ce25e8fc2 100644
--- a/plugins/catalog-import/src/api/CatalogImportClient.ts
+++ b/plugins/catalog-import/src/api/CatalogImportClient.ts
@@ -128,10 +128,10 @@ export class CatalogImportClient implements CatalogImportApi {
const catalogInfoItem = searchResult.data.items
.map(it => it.path)
.sort((a, b) => a.length - b.length)[0];
- return Promise.resolve({
+ return {
url: `blob/${defaultBranch}/${catalogInfoItem}`,
exists,
- });
+ };
}
return Promise.resolve({
exists,
diff --git a/plugins/catalog-import/src/components/ImportComponentPage.test.tsx b/plugins/catalog-import/src/components/ImportComponentPage.test.tsx
index 5c4b2e8538..932f9aafa0 100644
--- a/plugins/catalog-import/src/components/ImportComponentPage.test.tsx
+++ b/plugins/catalog-import/src/components/ImportComponentPage.test.tsx
@@ -37,12 +37,14 @@ let codeSearchMockResponse: () => Promise<{
};
}>;
+let findGithubConfigMockResponse = () => ({
+ host: 'test.localhost',
+ owner: 'someuser',
+});
+
jest.mock('@backstage/integration', () => ({
readGitHubIntegrationConfigs: () => ({
- find: () => ({
- host: 'test.localhost',
- owner: 'someuser',
- }),
+ find: findGithubConfigMockResponse,
}),
}));
@@ -138,6 +140,7 @@ describe('', () => {
}
it('Should not explode on non-Github URLs', async () => {
+ findGithubConfigMockResponse = () => undefined!!;
await renderSUT();
await waitFor(() => {
fireEvent.input(
@@ -160,6 +163,7 @@ describe('', () => {
});
it('Should offer direct file import from non-Github URLs', async () => {
+ findGithubConfigMockResponse = () => undefined!!;
await renderSUT();
await waitFor(() => {
fireEvent.input(
@@ -188,6 +192,10 @@ describe('', () => {
});
it('Should use found yaml file directly and not create a pull request if GitHub api returns one', async () => {
+ findGithubConfigMockResponse = () => ({
+ host: 'test.localhost',
+ owner: 'someuser',
+ });
codeSearchMockResponse = () =>
Promise.resolve({
data: {
@@ -221,6 +229,10 @@ describe('', () => {
});
it('Should indicate a pull request creation when no yaml file found in the repo', async () => {
+ findGithubConfigMockResponse = () => ({
+ host: 'test.localhost',
+ owner: 'someuser',
+ });
codeSearchMockResponse = () =>
Promise.resolve({
data: {
diff --git a/plugins/catalog-import/src/util/useGithubRepos.ts b/plugins/catalog-import/src/util/useGithubRepos.ts
index 319457dfe8..704ad974a5 100644
--- a/plugins/catalog-import/src/util/useGithubRepos.ts
+++ b/plugins/catalog-import/src/util/useGithubRepos.ts
@@ -22,7 +22,10 @@ import parseGitUri from 'git-url-parse';
// 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';
+import {
+ GitHubIntegrationConfig,
+ readGitHubIntegrationConfigs,
+} from '@backstage/integration';
export function useGithubRepos() {
const api = useApi(catalogImportApiRef);
@@ -84,20 +87,21 @@ export function useGithubRepos() {
const checkForExistingCatalogInfo = async (
location: string,
): Promise<{ exists: boolean; url?: string }> => {
- const { source } = parseGitUri(location);
- if (source !== 'github.com') {
+ let githubConfig: {
+ repoName: string;
+ ownerName: string;
+ githubIntegrationConfig: GitHubIntegrationConfig;
+ };
+ try {
+ githubConfig = getGithubIntegrationConfig(location);
+ } catch (e) {
return Promise.resolve({ exists: false });
}
- const {
- repoName,
- ownerName,
- githubIntegrationConfig,
- } = getGithubIntegrationConfig(location);
return await api
.checkForExistingCatalogInfo({
- owner: ownerName,
- repo: repoName,
- githubIntegrationConfig,
+ owner: githubConfig.ownerName,
+ repo: githubConfig.repoName,
+ githubIntegrationConfig: githubConfig.githubIntegrationConfig,
})
.catch(e => {
throw new Error(