@backstage/plugin-scaffolder-backend-module-gitlab 0.9.2-next.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabPipelineTrigger.cjs.js","sources":["../../src/actions/gitlabPipelineTrigger.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport {\n ExpandedPipelineSchema,\n PipelineTriggerTokenSchema,\n} from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabPipelineTrigger.examples';\nimport { getErrorMessage } from './helpers';\n\nconst pipelineInputProperties = z.object({\n projectId: z.number().describe('Project Id'),\n tokenDescription: z.string().describe('Pipeline token description'),\n branch: z.string().describe('Project branch'),\n variables: z\n .record(z.string(), z.string())\n .optional()\n .describe(\n 'A object/record of key-valued strings containing the pipeline variables.',\n ),\n});\n\nconst pipelineOutputProperties = z.object({\n pipelineUrl: z.string({ description: 'Pipeline Url' }),\n});\n\n/**\n * Creates a `gitlab:pipeline:trigger` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createTriggerGitlabPipelineAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:pipeline:trigger',\n description: 'Triggers a GitLab Pipeline.',\n examples,\n schema: {\n input: commonGitlabConfig.merge(pipelineInputProperties),\n output: pipelineOutputProperties,\n },\n async handler(ctx) {\n let pipelineTriggerToken: string | undefined = undefined;\n let pipelineTriggerId: number | undefined = undefined;\n\n const { repoUrl, projectId, tokenDescription, token, branch, variables } =\n commonGitlabConfig.merge(pipelineInputProperties).parse(ctx.input);\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n try {\n ({ pipelineTriggerToken, pipelineTriggerId } = await ctx.checkpoint({\n key: `create.pipeline.token.${projectId}`,\n fn: async () => {\n const res = (await api.PipelineTriggerTokens.create(\n projectId,\n tokenDescription,\n )) as PipelineTriggerTokenSchema;\n return {\n pipelineTriggerToken: res.token,\n pipelineTriggerId: res.id,\n };\n },\n }));\n\n if (!pipelineTriggerToken) {\n ctx.logger.error(\n `Failed to create pipeline token for project ${projectId}.`,\n );\n return;\n }\n ctx.logger.info(\n `Pipeline token id ${pipelineTriggerId} created for project ${projectId}.`,\n );\n\n // Use the pipeline token to trigger the pipeline in the project\n const pipelineTriggerResponse =\n (await api.PipelineTriggerTokens.trigger(\n projectId,\n branch,\n pipelineTriggerToken,\n { variables },\n )) as ExpandedPipelineSchema;\n\n if (!pipelineTriggerResponse.id) {\n ctx.logger.error(\n `Failed to trigger pipeline for project ${projectId}.`,\n );\n return;\n }\n\n ctx.logger.info(\n `Pipeline id ${pipelineTriggerResponse.id} for project ${projectId} triggered.`,\n );\n\n ctx.output('pipelineUrl', pipelineTriggerResponse.web_url);\n } catch (error: any) {\n if (error instanceof z.ZodError) {\n // Handling Zod validation errors\n throw new InputError(`Validation error: ${error.message}`, {\n validationErrors: error.errors,\n });\n }\n // Handling other errors\n throw new InputError(\n `Failed to trigger Pipeline: ${getErrorMessage(error)}`,\n );\n } finally {\n // Delete the pipeline token if it was created\n if (pipelineTriggerId) {\n try {\n await ctx.checkpoint({\n key: `create.delete.token.${projectId}`,\n fn: async () => {\n if (pipelineTriggerId) {\n // to make the current version of TypeScript happy\n await api.PipelineTriggerTokens.remove(\n projectId,\n pipelineTriggerId,\n );\n }\n },\n });\n ctx.logger.info(\n `Deleted pipeline with token id ${pipelineTriggerId}.`,\n );\n } catch (error: any) {\n ctx.logger.error(\n `Failed to delete pipeline with token id ${pipelineTriggerId}.`,\n );\n }\n }\n }\n },\n });\n};\n"],"names":["z","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","InputError","getErrorMessage"],"mappings":";;;;;;;;;;AA6BA,MAAM,uBAAA,GAA0BA,MAAE,MAAO,CAAA;AAAA,EACvC,SAAW,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,YAAY,CAAA;AAAA,EAC3C,gBAAkB,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,4BAA4B,CAAA;AAAA,EAClE,MAAQ,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,gBAAgB,CAAA;AAAA,EAC5C,SAAA,EAAWA,KACR,CAAA,MAAA,CAAOA,KAAE,CAAA,MAAA,EAAU,EAAAA,KAAA,CAAE,MAAO,EAAC,CAC7B,CAAA,QAAA,EACA,CAAA,QAAA;AAAA,IACC;AAAA;AAEN,CAAC,CAAA;AAED,MAAM,wBAAA,GAA2BA,MAAE,MAAO,CAAA;AAAA,EACxC,aAAaA,KAAE,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,gBAAgB;AACvD,CAAC,CAAA;AAQY,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOC,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,yBAAA;AAAA,IACJ,WAAa,EAAA,6BAAA;AAAA,cACbC,uCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAA,EAAOC,0BAAmB,CAAA,KAAA,CAAM,uBAAuB,CAAA;AAAA,MACvD,MAAQ,EAAA;AA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B,YAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,cACT,2CAA2C,iBAAiB,CAAA,CAAA;AAAA,aAC9D;AAAA;AACF;AACF;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabPipelineTrigger.cjs.js","sources":["../../src/actions/gitlabPipelineTrigger.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport {\n ExpandedPipelineSchema,\n PipelineTriggerTokenSchema,\n} from '@gitbeaker/rest';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabPipelineTrigger.examples';\nimport { getErrorMessage } from './helpers';\n\n/**\n * Creates a `gitlab:pipeline:trigger` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createTriggerGitlabPipelineAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:pipeline:trigger',\n description: 'Triggers a GitLab Pipeline.',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n }),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n projectId: z =>\n z.number({\n description: 'Project Id',\n }),\n tokenDescription: z =>\n z.string({\n description: 'Pipeline token description',\n }),\n branch: z =>\n z.string({\n description: 'Project branch',\n }),\n variables: z =>\n z\n .record(z.string(), z.string(), {\n description:\n 'A object/record of key-valued strings containing the pipeline variables.',\n })\n .optional(),\n },\n output: {\n pipelineUrl: z =>\n z.string({\n description: 'Pipeline Url',\n }),\n },\n },\n async handler(ctx) {\n let pipelineTriggerToken: string | undefined = undefined;\n let pipelineTriggerId: number | undefined = undefined;\n\n const { repoUrl, projectId, tokenDescription, token, branch, variables } =\n ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n try {\n ({ pipelineTriggerToken, pipelineTriggerId } = await ctx.checkpoint({\n key: `create.pipeline.token.${projectId}`,\n fn: async () => {\n const res = (await api.PipelineTriggerTokens.create(\n projectId,\n tokenDescription,\n )) as PipelineTriggerTokenSchema;\n return {\n pipelineTriggerToken: res.token,\n pipelineTriggerId: res.id,\n };\n },\n }));\n\n if (!pipelineTriggerToken) {\n ctx.logger.error(\n `Failed to create pipeline token for project ${projectId}.`,\n );\n return;\n }\n ctx.logger.info(\n `Pipeline token id ${pipelineTriggerId} created for project ${projectId}.`,\n );\n\n // Use the pipeline token to trigger the pipeline in the project\n const pipelineTriggerResponse =\n (await api.PipelineTriggerTokens.trigger(\n projectId,\n branch,\n pipelineTriggerToken,\n { variables },\n )) as ExpandedPipelineSchema;\n\n if (!pipelineTriggerResponse.id) {\n ctx.logger.error(\n `Failed to trigger pipeline for project ${projectId}.`,\n );\n return;\n }\n\n ctx.logger.info(\n `Pipeline id ${pipelineTriggerResponse.id} for project ${projectId} triggered.`,\n );\n\n ctx.output('pipelineUrl', pipelineTriggerResponse.web_url);\n } catch (error: any) {\n // Handling other errors\n throw new InputError(\n `Failed to trigger Pipeline: ${getErrorMessage(error)}`,\n );\n } finally {\n // Delete the pipeline token if it was created\n if (pipelineTriggerId) {\n try {\n await ctx.checkpoint({\n key: `create.delete.token.${projectId}`,\n fn: async () => {\n if (pipelineTriggerId) {\n // to make the current version of TypeScript happy\n await api.PipelineTriggerTokens.remove(\n projectId,\n pipelineTriggerId,\n );\n }\n },\n });\n ctx.logger.info(\n `Deleted pipeline with token id ${pipelineTriggerId}.`,\n );\n } catch (error: any) {\n ctx.logger.error(\n `Failed to delete pipeline with token id ${pipelineTriggerId}.`,\n );\n }\n }\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","getClient","InputError","getErrorMessage"],"mappings":";;;;;;;;AAiCa,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,yBAAA;AAAA,IACJ,WAAa,EAAA,6BAAA;AAAA,cACbC,uCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,sJAAA;AAAA,SACd,CAAA;AAAA,QACH,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,gBAAA,EAAkB,CAChB,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,MAAA,EAAQ,CACN,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,SAAA,EAAW,OACT,CACG,CAAA,MAAA,CAAO,EAAE,MAAO,EAAA,EAAG,CAAE,CAAA,MAAA,EAAU,EAAA;AAAA,UAC9B,WACE,EAAA;AAAA,SACH,EACA,QAAS;AAAA,OAChB;AAAA,MACA,MAAQ,E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@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var rest = require('@gitbeaker/rest');
6
6
  var luxon = require('luxon');
7
- var zod = require('zod');
8
7
  var util = require('../util.cjs.js');
9
8
  var gitlabProjectAccessTokenCreate_examples = require('./gitlabProjectAccessTokenCreate.examples.cjs.js');
10
9
 
@@ -14,28 +13,34 @@ const createGitlabProjectAccessTokenAction = (options) => {
14
13
  id: "gitlab:projectAccessToken:create",
15
14
  examples: gitlabProjectAccessTokenCreate_examples.examples,
16
15
  schema: {
17
- input: zod.z.object({
18
- projectId: zod.z.union([zod.z.number(), zod.z.string()], {
16
+ input: {
17
+ projectId: (z) => z.union([z.number(), z.string()], {
19
18
  description: "Project ID/Name(slug) of the Gitlab Project"
20
19
  }),
21
- token: zod.z.string({
20
+ token: (z) => z.string({
22
21
  description: "The token to use for authorization to GitLab"
23
22
  }).optional(),
24
- name: zod.z.string({ description: "Name of Access Key" }).optional(),
25
- repoUrl: zod.z.string({ description: "URL to gitlab instance" }),
26
- accessLevel: zod.z.number({
23
+ name: (z) => z.string({
24
+ description: "Name of Access Key"
25
+ }).optional(),
26
+ repoUrl: (z) => z.string({
27
+ description: "URL to gitlab instance"
28
+ }),
29
+ accessLevel: (z) => z.number({
27
30
  description: "Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)"
28
31
  }).optional(),
29
- scopes: zod.z.string({
32
+ scopes: (z) => z.string({
30
33
  description: "Scopes for a project access token"
31
34
  }).array().optional(),
32
- expiresAt: zod.z.string({
35
+ expiresAt: (z) => z.string({
33
36
  description: "Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days."
34
37
  }).optional()
35
- }),
36
- output: zod.z.object({
37
- access_token: zod.z.string({ description: "Access Token" })
38
- })
38
+ },
39
+ output: {
40
+ access_token: (z) => z.string({
41
+ description: "Access Token"
42
+ })
43
+ }
39
44
  },
40
45
  async handler(ctx) {
41
46
  ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabProjectAccessTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectAccessTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { AccessTokenScopes, Gitlab } from '@gitbeaker/rest';\nimport { DateTime } from 'luxon';\nimport { z } from 'zod';\nimport { getToken } from '../util';\nimport { examples } from './gitlabProjectAccessTokenCreate.examples';\n\n/**\n * Creates a `gitlab:projectAccessToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\n\nexport const createGitlabProjectAccessTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectAccessToken:create',\n examples,\n schema: {\n input: z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID/Name(slug) of the Gitlab Project',\n }),\n token: z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n name: z.string({ description: 'Name of Access Key' }).optional(),\n repoUrl: z.string({ description: 'URL to gitlab instance' }),\n accessLevel: z\n .number({\n description:\n 'Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)',\n })\n .optional(),\n scopes: z\n .string({\n description: 'Scopes for a project access token',\n })\n .array()\n .optional(),\n expiresAt: z\n .string({\n description:\n 'Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days.',\n })\n .optional(),\n }),\n output: z.object({\n access_token: z.string({ description: 'Access Token' }),\n }),\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const {\n projectId,\n name = 'tokenname',\n accessLevel = 40,\n scopes = ['read_repository'],\n expiresAt,\n } = ctx.input;\n\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n if (!integrationConfig.config.token && token) {\n throw new InputError(\n `No token available for host ${integrationConfig.config.baseUrl}`,\n );\n }\n\n let api;\n\n if (!ctx.input.token) {\n api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n } else {\n api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n oauthToken: token,\n });\n }\n\n const projectAccessToken = await ctx.checkpoint({\n key: `project.access.token.${projectId}.${name}`,\n fn: async () => {\n const response = await api.ProjectAccessTokens.create(\n projectId,\n name,\n scopes as AccessTokenScopes[],\n expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!,\n {\n accessLevel,\n },\n );\n return response.token;\n },\n });\n\n if (!projectAccessToken) {\n throw new Error('Could not create project access token');\n }\n\n ctx.output('access_token', projectAccessToken);\n },\n });\n};\n"],"names":["createTemplateAction","examples","z","getToken","InputError","Gitlab","DateTime"],"mappings":";;;;;;;;;;AAgCa,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kCAAA;AAAA,cACJC,gDAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAA,EAAOC,MAAE,MAAO,CAAA;AAAA,QACd,SAAA,EAAWA,KAAE,CAAA,KAAA,CAAM,CAACA,KAAA,CAAE,QAAU,EAAAA,KAAA,CAAE,MAAO,EAAC,CAAG,EAAA;AAAA,UAC3C,WAAa,EAAA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ProjectAccessTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { AccessTokenScopes, Gitlab } from '@gitbeaker/rest';\nimport { DateTime } from 'luxon';\nimport { getToken } from '../util';\nimport { examples } from './gitlabProjectAccessTokenCreate.examples';\n\n/**\n * Creates a `gitlab:projectAccessToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\n\nexport const createGitlabProjectAccessTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectAccessToken:create',\n examples,\n schema: {\n input: {\n projectId: z =>\n z.union([z.number(), z.string()], {\n description: 'Project ID/Name(slug) of the Gitlab Project',\n }),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n name: z =>\n z\n .string({\n description: 'Name of Access Key',\n })\n .optional(),\n repoUrl: z =>\n z.string({\n description: 'URL to gitlab instance',\n }),\n accessLevel: z =>\n z\n .number({\n description:\n 'Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)',\n })\n .optional(),\n scopes: z =>\n z\n .string({\n description: 'Scopes for a project access token',\n })\n .array()\n .optional(),\n expiresAt: z =>\n z\n .string({\n description:\n 'Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days.',\n })\n .optional(),\n },\n output: {\n access_token: z =>\n z.string({\n description: 'Access Token',\n }),\n },\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const {\n projectId,\n name = 'tokenname',\n accessLevel = 40,\n scopes = ['read_repository'],\n expiresAt,\n } = ctx.input;\n\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n if (!integrationConfig.config.token && token) {\n throw new InputError(\n `No token available for host ${integrationConfig.config.baseUrl}`,\n );\n }\n\n let api;\n\n if (!ctx.input.token) {\n api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n } else {\n api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n oauthToken: token,\n });\n }\n\n const projectAccessToken = await ctx.checkpoint({\n key: `project.access.token.${projectId}.${name}`,\n fn: async () => {\n const response = await api.ProjectAccessTokens.create(\n projectId,\n name,\n scopes as AccessTokenScopes[],\n expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!,\n {\n accessLevel,\n },\n );\n return response.token;\n },\n });\n\n if (!projectAccessToken) {\n throw new Error('Could not create project access token');\n }\n\n ctx.output('access_token', projectAccessToken);\n },\n });\n};\n"],"names":["createTemplateAction","examples","getToken","InputError","Gitlab","DateTime"],"mappings":";;;;;;;;;AA+Ba,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kCAAA;AAAA,cACJC,gDAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CAAE,KAAM,CAAA,CAAC,CAAE,CAAA,MAAA,EAAU,EAAA,CAAA,CAAE,MAAO,EAAC,CAAG,EAAA;AAAA,UAChC,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA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,6 @@
3
3
  var errors = require('@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var rest = require('@gitbeaker/rest');
6
- var zod = require('zod');
7
- var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
8
6
  var util = require('../util.cjs.js');
9
7
  var gitlabProjectDeployTokenCreate_examples = require('./gitlabProjectDeployTokenCreate.examples.cjs.js');
10
8
 
@@ -14,20 +12,34 @@ const createGitlabProjectDeployTokenAction = (options) => {
14
12
  id: "gitlab:projectDeployToken:create",
15
13
  examples: gitlabProjectDeployTokenCreate_examples.examples,
16
14
  schema: {
17
- input: commonGitlabConfig.default.merge(
18
- zod.z.object({
19
- projectId: zod.z.union([zod.z.number(), zod.z.string()], {
20
- description: "Project ID"
21
- }),
22
- name: zod.z.string({ description: "Deploy Token Name" }),
23
- username: zod.z.string({ description: "Deploy Token Username" }).optional(),
24
- scopes: zod.z.array(zod.z.string(), { description: "Scopes" })
15
+ input: {
16
+ repoUrl: (z) => z.string({
17
+ description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`
18
+ }),
19
+ token: (z) => z.string({
20
+ description: "The token to use for authorization to GitLab"
21
+ }).optional(),
22
+ projectId: (z) => z.union([z.number(), z.string()], {
23
+ description: "Project ID"
24
+ }),
25
+ name: (z) => z.string({
26
+ description: "Deploy Token Name"
27
+ }),
28
+ username: (z) => z.string({
29
+ description: "Deploy Token Username"
30
+ }).optional(),
31
+ scopes: (z) => z.array(z.string(), {
32
+ description: "Scopes"
25
33
  })
26
- ),
27
- output: zod.z.object({
28
- deploy_token: zod.z.string({ description: "Deploy Token" }),
29
- user: zod.z.string({ description: "User" })
30
- })
34
+ },
35
+ output: {
36
+ deploy_token: (z) => z.string({
37
+ description: "Deploy Token"
38
+ }),
39
+ user: (z) => z.string({
40
+ description: "User"
41
+ })
42
+ }
31
43
  },
32
44
  async handler(ctx) {
33
45
  ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabProjectDeployTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectDeployTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { DeployTokenScope, Gitlab } from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { examples } from './gitlabProjectDeployTokenCreate.examples';\n\n/**\n * Creates a `gitlab:projectDeployToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectDeployTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectDeployToken:create',\n examples,\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }),\n username: z\n .string({ description: 'Deploy Token Username' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }),\n }),\n ),\n output: z.object({\n deploy_token: z.string({ description: 'Deploy Token' }),\n user: z.string({ description: 'User' }),\n }),\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, username, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n if (scopes.length === 0) {\n throw new InputError(\n `Could not create token for project \"${ctx.input.projectId}\": scopes cannot be empty.`,\n );\n }\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n const { deployToken, deployUsername } = await ctx.checkpoint({\n key: `create.deploy.token.${projectId}.${name}`,\n fn: async () => {\n const res = await api.DeployTokens.create(\n name,\n scopes as DeployTokenScope[],\n {\n projectId,\n username,\n },\n );\n\n if (!res.hasOwnProperty('token')) {\n throw new InputError(`No deploy_token given from gitlab instance`);\n }\n\n return {\n deployToken: res.token as string,\n deployUsername: res.username,\n };\n },\n });\n\n ctx.output('deploy_token', deployToken);\n ctx.output('user', deployUsername);\n },\n });\n};\n"],"names":["createTemplateAction","examples","commonGitlabConfig","z","getToken","InputError","Gitlab"],"mappings":";;;;;;;;;;AA+Ba,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kCAAA;AAAA,cACJC,gDAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,OAAOC,0BAAmB,CAAA,KAAA;AAAA,QACxBC,MAAE,MAAO,CAAA;AAAA,UACP,SAAA,EAAWA,KAAE,CAAA,KAAA,CAAM,CAACA,KAAA,CAAE,QAAU,EAAAA,KAAA,CAAE,MAAO,EAAC,CAAG,EAAA;AAAA,YAC3C,WAAa,EAAA;AAAA,WACd,CAAA;AAAA,UACD,MAAMA,KAAE,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,qBAAqB,CAAA;AAAA,UACnD,QAAA,EAAUA,MACP,MAAO,CAAA,EAAE,aAAa,uBAAwB,EAAC,EAC/C,QAAS,EAAA;AAAA,UACZ,MAAA,EAAQA,MAAE,KAAM,CAAAA,KAAA,CAAE,QAAU,EAAA,EAAE,WAAa,EAAA,QAAA,EAAU;AAAA,SACtD;AAAA,OACH;AAAA,MACA,MAAA,EAAQ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,EAAA;AAChC,YAAM,MAAA,IAAID,kBAAW,CAA4C,0CAAA,CAAA,CAAA;AAAA;AAGnE,UAAO,OAAA;AAAA,YACL,aAAa,GAAI,CAAA,KAAA;AAAA,YACjB,gBAAgB,GAAI,CAAA;AAAA,WACtB;AAAA;AACF,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,gBAAgB,WAAW,CAAA;AACtC,MAAI,GAAA,CAAA,MAAA,CAAO,QAAQ,cAAc,CAAA;AAAA;AACnC,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabProjectDeployTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectDeployTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { DeployTokenScope, Gitlab } from '@gitbeaker/rest';\nimport { getToken } from '../util';\nimport { examples } from './gitlabProjectDeployTokenCreate.examples';\n\n/**\n * Creates a `gitlab:projectDeployToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectDeployTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectDeployToken:create',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n }),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n projectId: z =>\n z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z =>\n z.string({\n description: 'Deploy Token Name',\n }),\n username: z =>\n z\n .string({\n description: 'Deploy Token Username',\n })\n .optional(),\n scopes: z =>\n z.array(z.string(), {\n description: 'Scopes',\n }),\n },\n output: {\n deploy_token: z =>\n z.string({\n description: 'Deploy Token',\n }),\n user: z =>\n z.string({\n description: 'User',\n }),\n },\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, username, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n if (scopes.length === 0) {\n throw new InputError(\n `Could not create token for project \"${ctx.input.projectId}\": scopes cannot be empty.`,\n );\n }\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n const { deployToken, deployUsername } = await ctx.checkpoint({\n key: `create.deploy.token.${projectId}.${name}`,\n fn: async () => {\n const res = await api.DeployTokens.create(\n name,\n scopes as DeployTokenScope[],\n {\n projectId,\n username,\n },\n );\n\n if (!res.hasOwnProperty('token')) {\n throw new InputError(`No deploy_token given from gitlab instance`);\n }\n\n return {\n deployToken: res.token as string,\n deployUsername: res.username,\n };\n },\n });\n\n ctx.output('deploy_token', deployToken);\n ctx.output('user', deployUsername);\n },\n });\n};\n"],"names":["createTemplateAction","examples","getToken","InputError","Gitlab"],"mappings":";;;;;;;;AA6Ba,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kCAAA;AAAA,cACJC,gDAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,sJ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CAAA;AAErE,MAAI,IAAA,MAAA,CAAO,WAAW,CAAG,EAAA;AACvB,QAAA,MAAM,IAAIC,iBAAA;AAAA,UACR,CAAA,oCAAA,EAAuC,GAAI,CAAA,KAAA,CAAM,SAAS,CAAA,0BAAA;AAAA,SAC5D;AAAA;AAGF,MAAM,MAAA,GAAA,GAAM,IAAIC,WAAO,CAAA;AAAA,QACrB,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,QAC/B;AAAA,OACD,CAAA;AAED,MAAA,MAAM,EAAE,WAAa,EAAA,cAAA,EAAmB,GAAA,MAAM,IAAI,UAAW,CAAA;AAAA,QAC3D,GAAK,EAAA,CAAA,oBAAA,EAAuB,SAAS,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QAC7C,IAAI,YAAY;AACd,UAAM,MAAA,GAAA,GAAM,MAAM,GAAA,CAAI,YAAa,CAAA,MAAA;AAAA,YACjC,IAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,cACE,SAAA;AAAA,cACA;AAAA;AACF,WACF;AAEA,UAAA,IAAI,CAAC,GAAA,CAAI,cAAe,CAAA,OAAO,CAAG,EAAA;AAChC,YAAM,MAAA,IAAID,kBAAW,CAA4C,0CAAA,CAAA,CAAA;AAAA;AAGnE,UAAO,OAAA;AAAA,YACL,aAAa,GAAI,CAAA,KAAA;AAAA,YACjB,gBAAgB,GAAI,CAAA;AAAA,WACtB;AAAA;AACF,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,gBAAgB,WAAW,CAAA;AACtC,MAAI,GAAA,CAAA,MAAA,CAAO,QAAQ,cAAc,CAAA;AAAA;AACnC,GACD,CAAA;AACH;;;;"}
@@ -12,54 +12,29 @@ const createGitlabProjectMigrateAction = (options) => {
12
12
  examples: gitlabRepoPush_examples.examples,
13
13
  schema: {
14
14
  input: {
15
- required: [
16
- "destinationAccessToken",
17
- "destinationUrl",
18
- "sourceAccessToken",
19
- "sourceFullPath",
20
- "sourceUrl"
21
- ],
22
- type: "object",
23
- properties: {
24
- destinationAccessToken: {
25
- type: "string",
26
- title: "Target Repository Access Token",
27
- description: `The token to use for authorization to the target GitLab'`
28
- },
29
- destinationUrl: {
30
- type: "string",
31
- title: "Target Project Location",
32
- description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`
33
- },
34
- sourceAccessToken: {
35
- type: "string",
36
- title: "Source Group Access Token",
37
- description: `The token to use for authorization to the source GitLab'`
38
- },
39
- sourceFullPath: {
40
- type: "string",
41
- title: "Group Full Path",
42
- description: "Full path to the project in the source Gitlab instance"
43
- },
44
- sourceUrl: {
45
- type: "string",
46
- title: "Source URL Location",
47
- description: `Accepts the format 'https://gitlab.com/'`
48
- }
49
- }
15
+ destinationAccessToken: (z) => z.string({
16
+ description: `The token to use for authorization to the target GitLab'`
17
+ }),
18
+ destinationUrl: (z) => z.string({
19
+ description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`
20
+ }),
21
+ sourceAccessToken: (z) => z.string({
22
+ description: `The token to use for authorization to the source GitLab'`
23
+ }),
24
+ sourceFullPath: (z) => z.string({
25
+ description: "Full path to the project in the source Gitlab instance"
26
+ }),
27
+ sourceUrl: (z) => z.string({
28
+ description: `Accepts the format 'https://gitlab.com/'`
29
+ })
50
30
  },
51
31
  output: {
52
- type: "object",
53
- properties: {
54
- importedRepoUrl: {
55
- title: "URL to the newly imported repo",
56
- type: "string"
57
- },
58
- migrationId: {
59
- title: "Id of the migration that imports the project",
60
- type: "number"
61
- }
62
- }
32
+ importedRepoUrl: (z) => z.string({
33
+ description: "URL to the newly imported repo"
34
+ }),
35
+ migrationId: (z) => z.number({
36
+ description: "Id of the migration that imports the project"
37
+ })
63
38
  }
64
39
  },
65
40
  async handler(ctx) {
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n migrationId: {\n title: 'Id of the migration that imports the project',\n type: 'number',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n const migrationId = await ctx.checkpoint({\n key: `create.migration.${sourceUrl}`,\n fn: async () => {\n const migrationStatus = await api.Migrations.create(\n sourceConfig,\n migrationEntity,\n );\n return migrationStatus.id;\n },\n });\n\n ctx.output(\n 'importedRepoUrl',\n `${destinationHost}/${destinationNamespace}/${destinationSlug}`,\n );\n ctx.output('migrationId', migrationId);\n } catch (e: any) {\n throw new InputError(\n `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.\\nError: ${e}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","createGitlabApi"],"mappings":";;;;;;;AA+Ba,MAAA,gCAAA,GAAmC,CAAC,OAE3C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAMJ,CAAA;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AAW,CAAA;AAAA,eAC9B,CAAQ,EAAA;AACf,QAAA,MAAM,IAAID,iBAAA;AAAA,UACR,CAA2B,wBAAA,EAAA,cAAc,CAAoB,iBAAA,EAAA,cAAc,cAAc,SAAS,CAAA;AAAA,OAAA,EAA0C,CAAC,CAAA;AAAA,SAC/I;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n destinationAccessToken: z =>\n z.string({\n description: `The token to use for authorization to the target GitLab'`,\n }),\n destinationUrl: z =>\n z.string({\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n }),\n sourceAccessToken: z =>\n z.string({\n description: `The token to use for authorization to the source GitLab'`,\n }),\n sourceFullPath: z =>\n z.string({\n description:\n 'Full path to the project in the source Gitlab instance',\n }),\n sourceUrl: z =>\n z.string({\n description: `Accepts the format 'https://gitlab.com/'`,\n }),\n },\n output: {\n importedRepoUrl: z =>\n z.string({\n description: 'URL to the newly imported repo',\n }),\n migrationId: z =>\n z.number({\n description: 'Id of the migration that imports the project',\n }),\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n const migrationId = await ctx.checkpoint({\n key: `create.migration.${sourceUrl}`,\n fn: async () => {\n const migrationStatus = await api.Migrations.create(\n sourceConfig,\n migrationEntity,\n );\n return migrationStatus.id;\n },\n });\n\n ctx.output(\n 'importedRepoUrl',\n `${destinationHost}/${destinationNamespace}/${destinationSlug}`,\n );\n ctx.output('migrationId', migrationId);\n } catch (e: any) {\n throw new InputError(\n `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.\\nError: ${e}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","createGitlabApi"],"mappings":";;;;;;;AA+Ba,MAAA,gCAAA,GAAmC,CAAC,OAE3C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,E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"}
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
- var zod = require('zod');
5
- var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
6
4
  var util = require('../util.cjs.js');
7
5
  var gitlabProjectVariableCreate_examples = require('./gitlabProjectVariableCreate.examples.cjs.js');
8
6
 
@@ -12,24 +10,38 @@ const createGitlabProjectVariableAction = (options) => {
12
10
  id: "gitlab:projectVariable:create",
13
11
  examples: gitlabProjectVariableCreate_examples.examples,
14
12
  schema: {
15
- input: commonGitlabConfig.default.merge(
16
- zod.z.object({
17
- projectId: zod.z.union([zod.z.number(), zod.z.string()], {
18
- description: "Project ID"
19
- }),
20
- key: zod.z.string({
21
- description: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed"
22
- }).regex(/^[A-Za-z0-9_]{1,255}$/),
23
- value: zod.z.string({ description: "The value of a variable" }),
24
- variableType: zod.z.string({
25
- description: "Variable Type (env_var or file)"
26
- }),
27
- variableProtected: zod.z.boolean({ description: "Whether the variable is protected" }).default(false).optional(),
28
- masked: zod.z.boolean({ description: "Whether the variable is masked" }).default(false).optional(),
29
- raw: zod.z.boolean({ description: "Whether the variable is expandable" }).default(false).optional(),
30
- environmentScope: zod.z.string({ description: "The environment_scope of the variable" }).default("*").optional()
31
- })
32
- )
13
+ input: {
14
+ repoUrl: (z) => z.string({
15
+ description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`
16
+ }),
17
+ token: (z) => z.string({
18
+ description: "The token to use for authorization to GitLab"
19
+ }).optional(),
20
+ projectId: (z) => z.union([z.number(), z.string()], {
21
+ description: "Project ID"
22
+ }),
23
+ key: (z) => z.string({
24
+ description: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed"
25
+ }).regex(/^[A-Za-z0-9_]{1,255}$/),
26
+ value: (z) => z.string({
27
+ description: "The value of a variable"
28
+ }),
29
+ variableType: (z) => z.string({
30
+ description: "Variable Type (env_var or file)"
31
+ }),
32
+ variableProtected: (z) => z.boolean({
33
+ description: "Whether the variable is protected"
34
+ }).default(false).optional(),
35
+ masked: (z) => z.boolean({
36
+ description: "Whether the variable is masked"
37
+ }).default(false).optional(),
38
+ raw: (z) => z.boolean({
39
+ description: "Whether the variable is expandable"
40
+ }).default(false).optional(),
41
+ environmentScope: (z) => z.string({
42
+ description: "The environment_scope of the variable"
43
+ }).default("*").optional()
44
+ }
33
45
  },
34
46
  async handler(ctx) {
35
47
  const {
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabProjectVariableCreate.cjs.js","sources":["../../src/actions/gitlabProjectVariableCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { VariableType } from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabProjectVariableCreate.examples';\n\n/**\n * Creates a `gitlab:projectVariable:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectVariableAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectVariable:create',\n examples,\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: z\n .string({\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n })\n .regex(/^[A-Za-z0-9_]{1,255}$/),\n value: z.string({ description: 'The value of a variable' }),\n variableType: z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z\n .boolean({ description: 'Whether the variable is protected' })\n .default(false)\n .optional(),\n masked: z\n .boolean({ description: 'Whether the variable is masked' })\n .default(false)\n .optional(),\n raw: z\n .boolean({ description: 'Whether the variable is expandable' })\n .default(false)\n .optional(),\n environmentScope: z\n .string({ description: 'The environment_scope of the variable' })\n .default('*')\n .optional(),\n }),\n ),\n },\n async handler(ctx) {\n const {\n repoUrl,\n projectId,\n key,\n value,\n variableType,\n variableProtected = false,\n masked = false,\n raw = false,\n environmentScope = '*',\n token,\n } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const api = getClient({ host, integrations, token });\n\n await ctx.checkpoint({\n key: `create.project.variables.${projectId}.${key}.${value}`,\n fn: async () => {\n await api.ProjectVariables.create(projectId, key, value, {\n variableType: variableType as VariableType,\n protected: variableProtected,\n masked,\n raw,\n environmentScope,\n });\n },\n });\n },\n });\n};\n"],"names":["createTemplateAction","examples","commonGitlabConfig","z","parseRepoUrl","getClient"],"mappings":";;;;;;;;AA8Ba,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,+BAAA;AAAA,cACJC,6CAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,OAAOC,0BAAmB,CAAA,KAAA;AAAA,QACxBC,MAAE,MAAO,CAAA;AAAA,UACP,SAAA,EAAWA,KAAE,CAAA,KAAA,CAAM,CAACA,KAAA,CAAE,QAAU,EAAAA,KAAA,CAAE,MAAO,EAAC,CAAG,EAAA;AAAA,YAC3C,WAAa,EAAA;AAAA,WACd,CAAA;AAAA,UACD,G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,cAAU,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,OAAO,CAAA;AAEnD,MAAA,MAAM,IAAI,UAAW,CAAA;AAAA,QACnB,KAAK,CAA4B,yBAAA,EAAA,SAAS,CAAI,CAAA,EAAA,GAAG,IAAI,KAAK,CAAA,CAAA;AAAA,QAC1D,IAAI,YAAY;AACd,UAAA,MAAM,GAAI,CAAA,gBAAA,CAAiB,MAAO,CAAA,SAAA,EAAW,KAAK,KAAO,EAAA;AAAA,YACvD,YAAA;AAAA,YACA,SAAW,EAAA,iBAAA;AAAA,YACX,MAAA;AAAA,YACA,GAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA;AACH,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabProjectVariableCreate.cjs.js","sources":["../../src/actions/gitlabProjectVariableCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { VariableType } from '@gitbeaker/rest';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabProjectVariableCreate.examples';\n\n/**\n * Creates a `gitlab:projectVariable:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectVariableAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectVariable:create',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n }),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n projectId: z =>\n z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: z =>\n z\n .string({\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n })\n .regex(/^[A-Za-z0-9_]{1,255}$/),\n value: z =>\n z.string({\n description: 'The value of a variable',\n }),\n variableType: z =>\n z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z =>\n z\n .boolean({\n description: 'Whether the variable is protected',\n })\n .default(false)\n .optional(),\n masked: z =>\n z\n .boolean({\n description: 'Whether the variable is masked',\n })\n .default(false)\n .optional(),\n raw: z =>\n z\n .boolean({\n description: 'Whether the variable is expandable',\n })\n .default(false)\n .optional(),\n environmentScope: z =>\n z\n .string({\n description: 'The environment_scope of the variable',\n })\n .default('*')\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n projectId,\n key,\n value,\n variableType,\n variableProtected = false,\n masked = false,\n raw = false,\n environmentScope = '*',\n token,\n } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const api = getClient({ host, integrations, token });\n\n await ctx.checkpoint({\n key: `create.project.variables.${projectId}.${key}.${value}`,\n fn: async () => {\n await api.ProjectVariables.create(projectId, key, value, {\n variableType: variableType as VariableType,\n protected: variableProtected,\n masked,\n raw,\n environmentScope,\n });\n },\n });\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","getClient"],"mappings":";;;;;;AA4Ba,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,+BAAA;AAAA,cACJC,6CAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA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ACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,CAAA,CACA,OAAQ,CAAA,GAAG,EACX,QAAS;AAAA;AAChB,KACF;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAM,MAAA;AAAA,QACJ,OAAA;AAAA,QACA,SAAA;AAAA,QACA,GAAA;AAAA,QACA,KAAA;AAAA,QACA,YAAA;AAAA,QACA,iBAAoB,GAAA,KAAA;AAAA,QACpB,MAAS,GAAA,KAAA;AAAA,QACT,GAAM,GAAA,KAAA;AAAA,QACN,gBAAmB,GAAA,GAAA;AAAA,QACnB;AAAA,UACE,GAAI,CAAA,KAAA;AAER,MAAA,MAAM,EAAE,IAAA,EAAS,GAAAC,iBAAA,CAAa,SAAS,YAAY,CAAA;AAEnD,MAAA,MAAM,MAAMC,cAAU,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,OAAO,CAAA;AAEnD,MAAA,MAAM,IAAI,UAAW,CAAA;AAAA,QACnB,KAAK,CAA4B,yBAAA,EAAA,SAAS,CAAI,CAAA,EAAA,GAAG,IAAI,KAAK,CAAA,CAAA;AAAA,QAC1D,IAAI,YAAY;AACd,UAAA,MAAM,GAAI,CAAA,gBAAA,CAAiB,MAAO,CAAA,SAAA,EAAW,KAAK,KAAO,EAAA;AAAA,YACvD,YAAA;AAAA,YACA,SAAW,EAAA,iBAAA;AAAA,YACX,MAAA;AAAA,YACA,GAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA;AACH,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
4
3
  var path = require('path');
5
4
  var errors = require('@backstage/errors');
6
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
7
7
  var helpers = require('./helpers.cjs.js');
8
8
  var gitlabRepoPush_examples = require('./gitlabRepoPush.examples.cjs.js');
9
9
 
@@ -18,63 +18,38 @@ const createGitlabRepoPushAction = (options) => {
18
18
  examples: gitlabRepoPush_examples.examples,
19
19
  schema: {
20
20
  input: {
21
- required: ["repoUrl", "branchName", "commitMessage"],
22
- type: "object",
23
- properties: {
24
- repoUrl: {
25
- type: "string",
26
- title: "Repository Location",
27
- description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`
28
- },
29
- branchName: {
30
- type: "string",
31
- title: "Source Branch Name",
32
- description: "The branch name for the commit"
33
- },
34
- commitMessage: {
35
- type: "string",
36
- title: "Commit Message",
37
- description: `The commit message`
38
- },
39
- sourcePath: {
40
- type: "string",
41
- title: "Working Subdirectory",
42
- description: "Subdirectory of working directory to copy changes from"
43
- },
44
- targetPath: {
45
- type: "string",
46
- title: "Repository Subdirectory",
47
- description: "Subdirectory of repository to apply changes to"
48
- },
49
- token: {
50
- title: "Authentication Token",
51
- type: "string",
52
- description: "The token to use for authorization to GitLab"
53
- },
54
- commitAction: {
55
- title: "Commit action",
56
- type: "string",
57
- enum: ["create", "update", "delete"],
58
- description: "The action to be used for git commit. Defaults to create, but can be set to update or delete"
59
- }
60
- }
21
+ repoUrl: (z) => z.string({
22
+ description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`
23
+ }),
24
+ branchName: (z) => z.string({
25
+ description: "The branch name for the commit"
26
+ }),
27
+ commitMessage: (z) => z.string({
28
+ description: `The commit message`
29
+ }),
30
+ sourcePath: (z) => z.string({
31
+ description: "Subdirectory of working directory to copy changes from"
32
+ }).optional(),
33
+ targetPath: (z) => z.string({
34
+ description: "Subdirectory of repository to apply changes to"
35
+ }).optional(),
36
+ token: (z) => z.string({
37
+ description: "The token to use for authorization to GitLab"
38
+ }).optional(),
39
+ commitAction: (z) => z.enum(["create", "update", "delete"], {
40
+ description: "The action to be used for git commit. Defaults to create, but can be set to update or delete"
41
+ }).optional()
61
42
  },
62
43
  output: {
63
- type: "object",
64
- properties: {
65
- projectid: {
66
- title: "Gitlab Project id/Name(slug)",
67
- type: "string"
68
- },
69
- projectPath: {
70
- title: "Gitlab Project path",
71
- type: "string"
72
- },
73
- commitHash: {
74
- title: "The git commit hash of the commit",
75
- type: "string"
76
- }
77
- }
44
+ projectid: (z) => z.string({
45
+ description: "Gitlab Project id/Name(slug)"
46
+ }),
47
+ projectPath: (z) => z.string({
48
+ description: "Gitlab Project path"
49
+ }),
50
+ commitHash: (z) => z.string({
51
+ description: "The git commit hash of the commit"
52
+ })
78
53
  }
79
54
  },
80
55
  async handler(ctx) {