From 1af175b0bc4735b06b76e867a1846253fd0b9c8b Mon Sep 17 00:00:00 2001 From: Lucile Desfour Date: Tue, 23 Nov 2021 11:13:24 +0100 Subject: [PATCH 1/3] add allowed owner to scaffolder plugin (fix #8205) Signed-off-by: Lucile Desfour --- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 80 ++++++++++++++----- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index f862fa66fe..12931c297f 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -27,7 +27,7 @@ import FormHelperText from '@material-ui/core/FormHelperText'; import { useApi } from '@backstage/core-plugin-api'; import { Progress } from '@backstage/core-components'; -function splitFormData(url: string | undefined) { +function splitFormData(url: string | undefined, allowedOwners: string[]) { let host = undefined; let owner = undefined; let repo = undefined; @@ -39,7 +39,10 @@ function splitFormData(url: string | undefined) { if (url) { const parsed = new URL(`https://${url}`); host = parsed.host; - owner = parsed.searchParams.get('owner') || undefined; + owner = + parsed.searchParams.get('owner') || allowedOwners + ? allowedOwners[0] + : undefined; repo = parsed.searchParams.get('repo') || undefined; // This is azure dev ops specific. not used for any other provider. organization = parsed.searchParams.get('organization') || undefined; @@ -95,13 +98,16 @@ export const RepoUrlPicker = ({ const scaffolderApi = useApi(scaffolderApiRef); const integrationApi = useApi(scmIntegrationsApiRef); const allowedHosts = uiSchema['ui:options']?.allowedHosts as string[]; + const allowedOwners = uiSchema['ui:options']?.allowedOwners as string[]; const { value: integrations, loading } = useAsync(async () => { return await scaffolderApi.getIntegrationsList({ allowedHosts }); }); - const { host, owner, repo, organization, workspace, project } = - splitFormData(formData); + const { host, owner, repo, organization, workspace, project } = splitFormData( + formData, + allowedOwners, + ); const updateHost = useCallback( (evt: React.ChangeEvent<{ name?: string; value: unknown }>) => { onChange( @@ -300,21 +306,57 @@ export const RepoUrlPicker = ({ )} {/* Show this for all hosts except bitbucket */} - {host && integrationApi.byHost(host)?.type !== 'bitbucket' && ( - <> - 0 && !owner} - > - Owner - - - The organization, user or project that this repo will belong to - - - - )} + {host && + integrationApi.byHost(host)?.type !== 'bitbucket' && + !allowedOwners && ( + <> + 0 && !owner} + > + Owner + + + The organization, user or project that this repo will belong to + + + + )} + {/* Show this for all hosts except bitbucket where allowed owner is set */} + {host && + integrationApi.byHost(host)?.type !== 'bitbucket' && + allowedOwners && ( + <> + 0 && !owner} + > + Owner Available + + + The organization, user or project that this repo will belong to + + + + )} {/* Show this for all hosts */} Date: Fri, 26 Nov 2021 12:06:10 +0100 Subject: [PATCH 2/3] add changeset Signed-off-by: Lucile Desfour --- .changeset/five-lies-care.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/five-lies-care.md diff --git a/.changeset/five-lies-care.md b/.changeset/five-lies-care.md new file mode 100644 index 0000000000..e939942b70 --- /dev/null +++ b/.changeset/five-lies-care.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': minor +--- + +Can specify allowedOwners to the RepoUrlPicker picker in a template definition From ab4664e582468710bc8e0cf5e3246d2ad470a680 Mon Sep 17 00:00:00 2001 From: Lucile Desfour Date: Thu, 2 Dec 2021 14:56:00 +0100 Subject: [PATCH 3/3] set change to patch Signed-off-by: Lucile Desfour --- .changeset/five-lies-care.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/five-lies-care.md b/.changeset/five-lies-care.md index e939942b70..dab3f55d52 100644 --- a/.changeset/five-lies-care.md +++ b/.changeset/five-lies-care.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder': minor +'@backstage/plugin-scaffolder': patch --- Can specify allowedOwners to the RepoUrlPicker picker in a template definition