From adc0414cf79ddfa3338d0872db8397e7b466f537 Mon Sep 17 00:00:00 2001 From: npiyush97 Date: Mon, 12 Feb 2024 20:44:58 +0530 Subject: [PATCH] preetier Signed-off-by: npiyush97 --- .changeset/spotty-carrots-refuse.md | 5 +++++ .../StepPrepareCreatePullRequest.tsx | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .changeset/spotty-carrots-refuse.md 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,