From c6b3d7430ec71b568a249bc09a8299413fd3815d Mon Sep 17 00:00:00 2001 From: Ilya Katlinski Date: Fri, 6 Oct 2023 08:44:47 +0200 Subject: [PATCH] feat: add typing support for gitlab project settings Signed-off-by: Ilya Katlinski --- .../actions/builtin/publish/gitlab.ts | 105 +++++++++++++++--- .../actions/builtin/publish/gitlab.types.ts | 47 ++++++++ 2 files changed, 135 insertions(+), 17 deletions(-) create mode 100644 plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.types.ts diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts index 52c0409870..32d07eec6b 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.ts @@ -22,6 +22,11 @@ import { initRepoAndPush, printGitlabError } from '../helpers'; import { getRepoSourceDirectory, parseRepoUrl } from './util'; import { Config } from '@backstage/config'; import { examples } from './gitlab.examples'; +import { + GitlabBranchSettings, + GitlabProjectSettings, + GitlabProjectVariableSettings, +} from './gitlab.types'; /** * Creates a new action that initializes a git repository of the content in the workspace @@ -48,23 +53,9 @@ export function createPublishGitlabAction(options: { setUserAsOwner?: boolean; /** @deprecated in favour of settings.topics field */ topics?: string[]; - settings?: Record; - branches?: Array<{ - name: string; - protect?: boolean; - create?: boolean; - ref?: string; - }>; - projectVariables?: Array<{ - key: string; - value: string; - description?: string; - variable_type?: string; - protected?: boolean; - masked?: boolean; - raw?: boolean; - environment_scope?: string; - }>; + settings?: GitlabProjectSettings; + branches?: Array; + projectVariables?: Array; }>({ id: 'publish:gitlab', description: @@ -137,6 +128,86 @@ export function createPublishGitlabAction(options: { description: 'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes', type: 'object', + properties: { + name: { + title: 'Project name', + description: + 'The name of the new project. Equals path if not provided.', + type: 'string', + }, + path: { + title: 'Project path', + description: + 'Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).', + type: 'string', + }, + auto_devops_enabled: { + title: 'Auto DevOps enabled', + description: 'Enable Auto DevOps for this project', + type: 'boolean', + }, + ci_config_path: { + title: 'CI config path', + description: 'Custom CI config path for this project', + type: 'string', + }, + description: { + title: 'Project description', + description: 'Short project description', + type: 'string', + }, + namespace_id: { + title: 'Namespace ID', + description: + 'Namespace for the new project (defaults to the current user’s namespace)', + type: 'number', + }, + topics: { + title: 'Topic labels', + description: 'Topic labels to apply on the repository', + type: 'array', + items: { + type: 'string', + }, + }, + visibility: { + title: 'Project visibility', + description: + 'The visibility of the project. Can be private, internal, or public. The default value is private.', + type: 'string', + enum: ['private', 'public', 'internal'], + }, + group_runners_enabled: { + title: 'Group runners enabled', + description: 'Enable group runners for this project', + type: 'boolean', + }, + emails_enabled: { + title: 'Emails enabled', + description: 'Send email notifications', + type: 'boolean', + }, + container_registry_access_level: { + title: 'Container registry access level', + description: + 'Configure the container registry to be enabled or disabled', + type: 'string', + enum: ['disabled', 'private', 'enabled'], + }, + builds_access_level: { + title: 'Builds access level', + description: 'Configure the builds to be enabled or disabled', + type: 'string', + enum: ['disabled', 'private', 'enabled'], + }, + auto_cancel_pending_pipelines: { + title: 'Auto cancel pending pipelines', + description: + 'Enable auto-cancel of pipelines for branches that have newer commits', + type: 'string', + enum: ['disabled', 'enabled'], + }, + }, }, branches: { title: 'Project branches settings', diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.types.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.types.ts new file mode 100644 index 0000000000..8882df8fec --- /dev/null +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/gitlab.types.ts @@ -0,0 +1,47 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export type GitlabProjectSettings = ({ name: string } | { path: string }) & { + auto_devops_enabled?: boolean; + ci_config_path?: string; + description?: string; + namespace_id?: number; + topics?: string[]; + visibility: 'private' | 'internal' | 'public'; + group_runners_enabled?: boolean; + emails_enabled?: boolean; + container_registry_access_level?: 'disabled' | 'private' | 'enabled'; + builds_access_level?: 'disabled' | 'private' | 'enabled'; + auto_cancel_pending_pipelines?: 'disabled' | 'enabled'; +}; + +export type GitlabBranchSettings = { + name: string; + protect?: boolean; + create?: boolean; + ref?: string; +}; + +export type GitlabProjectVariableSettings = { + key: string; + value: string; + description?: string; + variable_type?: string; + protected?: boolean; + masked?: boolean; + raw?: boolean; + environment_scope?: string; +};