Address issues from code review
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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('<ImportComponentPage />', () => {
|
||||
}
|
||||
|
||||
it('Should not explode on non-Github URLs', async () => {
|
||||
findGithubConfigMockResponse = () => undefined!!;
|
||||
await renderSUT();
|
||||
await waitFor(() => {
|
||||
fireEvent.input(
|
||||
@@ -160,6 +163,7 @@ describe('<ImportComponentPage />', () => {
|
||||
});
|
||||
|
||||
it('Should offer direct file import from non-Github URLs', async () => {
|
||||
findGithubConfigMockResponse = () => undefined!!;
|
||||
await renderSUT();
|
||||
await waitFor(() => {
|
||||
fireEvent.input(
|
||||
@@ -188,6 +192,10 @@ describe('<ImportComponentPage />', () => {
|
||||
});
|
||||
|
||||
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('<ImportComponentPage />', () => {
|
||||
});
|
||||
|
||||
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: {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user