diff --git a/.changeset/eighty-rats-smash.md b/.changeset/eighty-rats-smash.md new file mode 100644 index 0000000000..4d49d0f203 --- /dev/null +++ b/.changeset/eighty-rats-smash.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-import': patch +--- + +Improve how URLs are analyzed for add/import diff --git a/app-config.yaml b/app-config.yaml index 48869cc0a0..d2100801ae 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -213,6 +213,7 @@ scaffolder: $env: BITBUCKET_USERNAME token: $env: BITBUCKET_TOKEN + auth: environment: development ### Providing an auth.session.secret will enable session support in the auth-backend diff --git a/plugins/catalog-import/src/components/ComponentConfigDisplay.tsx b/plugins/catalog-import/src/components/ComponentConfigDisplay.tsx index ab5c71c7d3..96b1bf2298 100644 --- a/plugins/catalog-import/src/components/ComponentConfigDisplay.tsx +++ b/plugins/catalog-import/src/components/ComponentConfigDisplay.tsx @@ -33,13 +33,13 @@ import { StructuredMetadataTable, useApi, } from '@backstage/core'; -import parseGitUri from 'git-url-parse'; import { PartialEntity } from '../util/types'; import { generatePath, resolvePath } from 'react-router'; import { entityRoute, entityRouteParams } from '@backstage/plugin-catalog'; import { Entity } from '@backstage/catalog-model'; import { Link as RouterLink } from 'react-router-dom'; import * as YAML from 'yaml'; +import { urlType } from '../util/urls'; const getEntityCatalogPath = ({ entity, @@ -81,7 +81,7 @@ const ComponentConfigDisplay = ({ const onNext = useCallback(async () => { try { setSubmitting(true); - if (!parseGitUri(configFile.location).filepathtype) { + if (urlType(configFile.location) === 'tree') { const result = await submitPrToRepo(configFile); savePRLink(result.link); setSubmitting(false); @@ -100,7 +100,7 @@ const ComponentConfigDisplay = ({ return ( - {!parseGitUri(configFile.location).filepathtype ? ( + {urlType(configFile.location) === 'tree' ? ( Following config object will be submitted in a pull request to the repository{' '} @@ -127,7 +127,7 @@ const ComponentConfigDisplay = ({ )} - {!parseGitUri(configFile.location).filepathtype ? ( + {urlType(configFile.location) === 'tree' ? (
{YAML.stringify(configFile.config)}
) : ( diff --git a/plugins/catalog-import/src/components/ImportComponentForm.tsx b/plugins/catalog-import/src/components/ImportComponentForm.tsx index dab5ccbea2..b6070c4793 100644 --- a/plugins/catalog-import/src/components/ImportComponentForm.tsx +++ b/plugins/catalog-import/src/components/ImportComponentForm.tsx @@ -26,11 +26,11 @@ import { makeStyles } from '@material-ui/core/styles'; import React from 'react'; import { useForm } from 'react-hook-form'; import { useMountedState } from 'react-use'; -import parseGitUri from 'git-url-parse'; import { ComponentIdValidators } from '../util/validate'; import { useGithubRepos } from '../util/useGithubRepos'; import { ConfigSpec } from './ImportComponentPage'; import { catalogApiRef } from '@backstage/plugin-catalog'; +import { urlType } from '../util/urls'; const useStyles = makeStyles(theme => ({ form: { @@ -65,9 +65,9 @@ export const RegisterComponentForm = ({ nextStep, saveConfig }: Props) => { const { componentLocation: target } = formData; try { if (!isMounted()) return; - const type = !parseGitUri(target).filepathtype ? 'repo' : 'file'; + const type = urlType(target); - if (type === 'repo') { + if (type === 'tree') { saveConfig({ type, location: target, diff --git a/plugins/catalog-import/src/components/ImportComponentPage.tsx b/plugins/catalog-import/src/components/ImportComponentPage.tsx index 9fdb465dd1..303c70cc7f 100644 --- a/plugins/catalog-import/src/components/ImportComponentPage.tsx +++ b/plugins/catalog-import/src/components/ImportComponentPage.tsx @@ -32,7 +32,7 @@ import { ImportFinished } from './ImportFinished'; import { PartialEntity } from '../util/types'; export type ConfigSpec = { - type: 'repo' | 'file'; + type: 'tree' | 'file'; location: string; config: PartialEntity[]; }; @@ -44,7 +44,7 @@ export const ImportComponentPage = ({ }) => { const [activeStep, setActiveStep] = useState(0); const [configFile, setConfigFile] = useState({ - type: 'repo', + type: 'tree', location: '', config: [], }); diff --git a/plugins/catalog-import/src/components/ImportFinished.tsx b/plugins/catalog-import/src/components/ImportFinished.tsx index caba678999..9b0f8575a6 100644 --- a/plugins/catalog-import/src/components/ImportFinished.tsx +++ b/plugins/catalog-import/src/components/ImportFinished.tsx @@ -19,7 +19,7 @@ import { Alert } from '@material-ui/lab'; import { Button, Grid, Link } from '@material-ui/core'; type Props = { - type: 'repo' | 'file'; + type: 'tree' | 'file'; nextStep: (options?: { reset: boolean }) => void; PRLink: string; }; @@ -29,13 +29,13 @@ export const ImportFinished = ({ nextStep, PRLink, type }: Props) => { - {type === 'repo' + {type === 'tree' ? 'Pull requests have been successfully opened. You can start again to import more repositories' : 'Entity added to catalog successfully'} - {type === 'repo' ? ( + {type === 'tree' ? (