diff --git a/plugins/scaffolder-backend-module-gitlab/api-report.md b/plugins/scaffolder-backend-module-gitlab/api-report.md index ee7f1b3a21..09d061f17b 100644 --- a/plugins/scaffolder-backend-module-gitlab/api-report.md +++ b/plugins/scaffolder-backend-module-gitlab/api-report.md @@ -16,6 +16,9 @@ export const createGitlabGroupEnsureExistsAction: (options: { token?: string | undefined; } & { path: string[]; + }, + { + groupId?: number | undefined; } >; @@ -25,13 +28,16 @@ export const createGitlabProjectAccessTokenAction: (options: { }) => TemplateAction< { repoUrl: string; - projectId: string | number; - name: string; - accessLevel: number; - scopes: string[]; token?: string | undefined; + } & { + projectId: string | number; + name?: string | undefined; + accessLevel?: string | undefined; + scopes?: string[] | undefined; }, - JsonObject + { + access_token: string; + } >; // @public @@ -40,13 +46,17 @@ export const createGitlabProjectDeployTokenAction: (options: { }) => TemplateAction< { repoUrl: string; - projectId: string | number; - name: string; - username: string; - scopes: string[]; token?: string | undefined; + } & { + name: string; + projectId: string | number; + username?: string | undefined; + scopes?: string[] | undefined; }, - JsonObject + { + user: string; + deploy_token: string; + } >; // @public @@ -65,8 +75,7 @@ export const createGitlabProjectVariableAction: (options: { masked?: boolean | undefined; raw?: boolean | undefined; environmentScope?: string | undefined; - } -, + }, JsonObject >; ``` diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts index 8161b4d006..6e883a0fcc 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts @@ -22,20 +22,6 @@ import commonGitlabConfig from '../commonGitlabConfig'; import { getToken } from '../util'; import { z } from 'zod'; -const input = commonGitlabConfig.and( - z.object({ - path: z - .array(z.string(), { - description: 'A path of group names that is ensured to exist', - }) - .min(1), - }), -); - -const output = z.object({ - groupId: z.string({ description: 'The id of the innermost sub-group' }), -}); - /** * Creates an `gitlab:group:ensureExists` Scaffolder action. * @@ -46,10 +32,25 @@ export const createGitlabGroupEnsureExistsAction = (options: { }) => { const { integrations } = options; - return createTemplateAction>({ + return createTemplateAction({ id: 'gitlab:group:ensureExists', description: 'Ensures a Gitlab group exists', - schema: { input, output }, + schema: { + input: commonGitlabConfig.and( + z.object({ + path: z + .array(z.string(), { + description: 'A path of group names that is ensured to exist', + }) + .min(1), + }), + ), + output: z.object({ + groupId: z + .number({ description: 'The id of the innermost sub-group' }) + .optional(), + }), + }, async handler(ctx) { const { path } = ctx.input; const { token, integrationConfig } = getToken(ctx.input, integrations); diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts index d295d7cc07..1e0b8db900 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts @@ -20,21 +20,6 @@ import commonGitlabConfig from '../commonGitlabConfig'; import { getToken } from '../util'; import { z } from 'zod'; -const input = commonGitlabConfig.and( - z.object({ - projectId: z.union([z.number(), z.string()], { description: 'Project ID' }), - name: z.string({ description: 'Deploy Token Name' }).optional(), - accessLevel: z - .string({ description: 'Access Level of the Token' }) - .optional(), - scopes: z.array(z.string(), { description: 'Scopes' }).optional(), - }), -); - -const output = z.object({ - access_token: z.string({ description: 'Access Token' }), -}); - /** * Creates a `gitlab:projectAccessToken:create` Scaffolder action. * @@ -45,9 +30,25 @@ export const createGitlabProjectAccessTokenAction = (options: { integrations: ScmIntegrationRegistry; }) => { const { integrations } = options; - return createTemplateAction>({ + return createTemplateAction({ id: 'gitlab:projectAccessToken:create', - schema: { input, output }, + schema: { + input: commonGitlabConfig.and( + z.object({ + projectId: z.union([z.number(), z.string()], { + description: 'Project ID', + }), + name: z.string({ description: 'Deploy Token Name' }).optional(), + accessLevel: z + .string({ description: 'Access Level of the Token' }) + .optional(), + scopes: z.array(z.string(), { description: 'Scopes' }).optional(), + }), + ), + output: z.object({ + access_token: z.string({ description: 'Access Token' }), + }), + }, async handler(ctx) { ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`); const { projectId, name, accessLevel, scopes } = ctx.input; diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectDeployTokenAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectDeployTokenAction.ts index 46feaad39f..3010bd33d2 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectDeployTokenAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectDeployTokenAction.ts @@ -23,20 +23,6 @@ import { getToken } from '../util'; import { InputError } from '@backstage/errors'; import { z } from 'zod'; -const input = commonGitlabConfig.and( - z.object({ - projectId: z.union([z.number(), z.string()], { description: 'Project ID' }), - name: z.string({ description: 'Deploy Token Name' }), - username: z.string({ description: 'Deploy Token Username' }).optional(), - scopes: z.array(z.string(), { description: 'Scopes' }).optional(), - }), -); - -const output = z.object({ - deploy_token: z.string({ description: 'Deploy Token' }), - user: z.string({ description: 'User' }), -}); - /** * Creates a `gitlab:projectDeployToken:create` Scaffolder action. * @@ -47,9 +33,26 @@ export const createGitlabProjectDeployTokenAction = (options: { integrations: ScmIntegrationRegistry; }) => { const { integrations } = options; - return createTemplateAction>({ + return createTemplateAction({ id: 'gitlab:projectDeployToken:create', - schema: { input, output }, + schema: { + input: commonGitlabConfig.and( + z.object({ + projectId: z.union([z.number(), z.string()], { + description: 'Project ID', + }), + name: z.string({ description: 'Deploy Token Name' }), + username: z + .string({ description: 'Deploy Token Username' }) + .optional(), + scopes: z.array(z.string(), { description: 'Scopes' }).optional(), + }), + ), + output: z.object({ + deploy_token: z.string({ description: 'Deploy Token' }), + user: z.string({ description: 'User' }), + }), + }, async handler(ctx) { ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`); const { projectId, name, username, scopes } = ctx.input; diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectVariableAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectVariableAction.ts index a66d6242ee..a6043bea01 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectVariableAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectVariableAction.ts @@ -21,36 +21,6 @@ import { getToken } from '../util'; import commonGitlabConfig from '../commonGitlabConfig'; import { z } from 'zod'; -const input = commonGitlabConfig.and( - z.object({ - projectId: z.union([z.number(), z.string()], { description: 'Project ID' }), - key: z - .string({ - description: - 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed', - }) - .regex(/^[A-Za-z0-9_]{1,255}$/), - value: z.string({ description: 'The value of a variable' }), - variableType: z.string({ description: 'Variable Type (env_var or file)' }), - variableProtected: z - .boolean({ description: 'Whether the variable is protected' }) - .default(false) - .optional(), - masked: z - .boolean({ description: 'Whether the variable is masked' }) - .default(false) - .optional(), - raw: z - .boolean({ description: 'Whether the variable is expandable' }) - .default(false) - .optional(), - environmentScope: z - .string({ description: 'The environment_scope of the variable' }) - .default('*') - .optional(), - }), -); - /** * Creates a `gitlab:projectVariable:create` Scaffolder action. * @@ -61,9 +31,43 @@ export const createGitlabProjectVariableAction = (options: { integrations: ScmIntegrationRegistry; }) => { const { integrations } = options; - return createTemplateAction>({ + return createTemplateAction({ id: 'gitlab:projectVariable:create', - schema: { input }, + schema: { + input: commonGitlabConfig.and( + z.object({ + projectId: z.union([z.number(), z.string()], { + description: 'Project ID', + }), + key: z + .string({ + description: + 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed', + }) + .regex(/^[A-Za-z0-9_]{1,255}$/), + value: z.string({ description: 'The value of a variable' }), + variableType: z.string({ + description: 'Variable Type (env_var or file)', + }), + variableProtected: z + .boolean({ description: 'Whether the variable is protected' }) + .default(false) + .optional(), + masked: z + .boolean({ description: 'Whether the variable is masked' }) + .default(false) + .optional(), + raw: z + .boolean({ description: 'Whether the variable is expandable' }) + .default(false) + .optional(), + environmentScope: z + .string({ description: 'The environment_scope of the variable' }) + .default('*') + .optional(), + }), + ), + }, async handler(ctx) { const { projectId, diff --git a/yarn.lock b/yarn.lock index 70a7ed3f3c..45879eb030 100644 --- a/yarn.lock +++ b/yarn.lock @@ -40594,13 +40594,6 @@ __metadata: languageName: node linkType: hard -"zod@npm:^3.21.4": - version: 3.21.4 - resolution: "zod@npm:3.21.4" - checksum: f185ba87342ff16f7a06686767c2b2a7af41110c7edf7c1974095d8db7a73792696bcb4a00853de0d2edeb34a5b2ea6a55871bc864227dace682a0a28de33e1f - languageName: node - linkType: hard - "zod@npm:~3.18.0": version: 3.18.0 resolution: "zod@npm:3.18.0"