diff --git a/.changeset/spotty-carrots-refuse.md b/.changeset/spotty-carrots-refuse.md new file mode 100644 index 0000000000..b615c7a302 --- /dev/null +++ b/.changeset/spotty-carrots-refuse.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-import': patch +--- + +fix related to component name not adhering to kubernetes validobjectname. diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx index 1cbdfce355..1614488922 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx @@ -143,11 +143,25 @@ export const StepPrepareCreatePullRequest = ( .sort(); }); + const isValidObjectName = (value: unknown): boolean => { + return ( + typeof value === 'string' && + value.length >= 1 && + value.length <= 63 && + /^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$/.test(value) + ); + }; + const handleResult = useCallback( async (data: FormData) => { setSubmitted(true); try { + if (!isValidObjectName(data.componentName)) { + throw new Error( + 'Component name: Must start and end with an alphanumeric character, and contain only alphanumeric characters, hyphens, underscores, and periods. Maximum length is 63 characters.', + ); + } const pr = await catalogImportApi.submitPullRequest({ repositoryUrl: analyzeResult.url, title: data.title,