@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":"gitlabGroupEnsureExists.cjs.js","sources":["../../src/actions/gitlabGroupEnsureExists.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 { GroupSchema } from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabGroupEnsureExists.examples';\n\n/**\n * Creates an `gitlab:group:ensureExists` Scaffolder action.\n *\n * @public\n */\nexport const createGitlabGroupEnsureExistsAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction({\n id: 'gitlab:group:ensureExists',\n description: 'Ensures a Gitlab group exists',\n supportsDryRun: true,\n examples,\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n path: z\n .array(\n z.string().or(\n z.object({\n name: z.string(),\n slug: z.string(),\n }),\n ),\n {\n description:\n 'A path of group names or objects (name and slug) that is ensured to exist',\n },\n )\n .min(1),\n }),\n ),\n output: z.object({\n groupId: z\n .number({ description: 'The id of the innermost sub-group' })\n .optional(),\n }),\n },\n async handler(ctx) {\n if (ctx.isDryRun) {\n ctx.output('groupId', 42);\n return;\n }\n\n const { token, repoUrl, path } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const api = getClient({ host, integrations, token });\n\n let currentPath: string | null = null;\n let parentId: number | null = null;\n for (const { name, slug } of pathIterator(path)) {\n const fullPath: string = currentPath ? `${currentPath}/${slug}` : slug;\n const result = (await api.Groups.search(\n fullPath,\n )) as unknown as Array<GroupSchema>; // recast since the return type for search is wrong in the gitbeaker typings\n const subGroup = result.find(\n searchPathElem => searchPathElem.full_path === fullPath,\n );\n if (!subGroup) {\n ctx.logger.info(`creating missing group ${fullPath}`);\n\n parentId = await ctx.checkpoint({\n key: `ensure.${name}.${slug}.${parentId}`,\n // eslint-disable-next-line no-loop-func\n fn: async () => {\n return (\n await api.Groups.create(\n name,\n slug,\n parentId\n ? {\n parentId: parentId,\n }\n : {},\n )\n )?.id;\n },\n });\n } else {\n parentId = subGroup.id;\n }\n currentPath = fullPath;\n }\n if (parentId !== null) {\n ctx.output('groupId', parentId);\n }\n },\n });\n};\n\ntype PathPart = { name: string; slug: string };\ntype PathItem = string | PathPart;\n\nfunction* pathIterator(items: PathItem[]): Generator<PathPart> {\n for (const item of items) {\n if (typeof item === 'string') {\n const parts = item.split('/');\n for (const part of parts) {\n yield { name: part, slug: part };\n }\n } else {\n yield item;\n }\n }\n}\n"],"names":["createTemplateAction","examples","commonGitlabConfig","z","parseRepoUrl","getClient"],"mappings":";;;;;;;;AA6Ba,MAAA,mCAAA,GAAsC,CAAC,OAE9C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,2BAAA;AAAA,IACJ,WAAa,EAAA,+BAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,cAChBC,yCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,OAAOC,0BAAmB,CAAA,KAAA;AAAA,QACxBC,MAAE,MAAO,CAAA;AAAA,UACP,MAAMA,KACH,CAAA,K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Ac,KAAA;AAAA,SACjD;AACA,QAAA,IAAI,CAAC,QAAU,EAAA;AACb,UAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAA0B,uBAAA,EAAA,QAAQ,CAAE,CAAA,CAAA;AAEpD,UAAW,QAAA,GAAA,MAAM,IAAI,UAAW,CAAA;AAAA,YAC9B,KAAK,CAAU,OAAA,EAAA,IAAI,CAAI,CAAA,EAAA,IAAI,IAAI,QAAQ,CAAA,CAAA;AAAA;AAAA,YAEvC,IAAI,YAAY;AACd,cACE,OAAA,CAAA,MAAM,IAAI,MAAO,CAAA,MAAA;AAAA,gBACf,IAAA;AAAA,gBACA,IAAA;AAAA,gBACA,QACI,GAAA;AAAA,kBACE;AAAA,oBAEF;AAAC,eAEN,GAAA,EAAA;AAAA;AACL,WACD,CAAA;AAAA,SACI,MAAA;AACL,UAAA,QAAA,GAAW,QAAS,CAAA,EAAA;AAAA;AAEtB,QAAc,WAAA,GAAA,QAAA;AAAA;AAEhB,MAAA,IAAI,aAAa,IAAM,EAAA;AACrB,QAAI,GAAA,CAAA,MAAA,CAAO,WAAW,QAAQ,CAAA;AAAA;AAChC;AACF,GACD,CAAA;AACH;AAKA,UAAU,aAAa,KAAwC,EAAA;AAC7D,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAI,IAAA,OAAO,SAAS,QAAU,EAAA;AAC5B,MAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,KAAA,CAAM,GAAG,CAAA;AAC5B,MAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,QAAA,MAAM,EAAE,IAAA,EAAM,IAAM,EAAA,IAAA,EAAM,IAAK,EAAA;AAAA;AACjC,KACK,MAAA;AACL,MAAM,MAAA,IAAA;AAAA;AACR;AAEJ;;;;"}
1
+ {"version":3,"file":"gitlabGroupEnsureExists.cjs.js","sources":["../../src/actions/gitlabGroupEnsureExists.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 { GroupSchema } from '@gitbeaker/rest';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabGroupEnsureExists.examples';\n\n/**\n * Creates an `gitlab:group:ensureExists` Scaffolder action.\n *\n * @public\n */\nexport const createGitlabGroupEnsureExistsAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction({\n id: 'gitlab:group:ensureExists',\n description: 'Ensures a Gitlab group exists',\n supportsDryRun: true,\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 path: z =>\n z\n .array(\n z.string().or(\n z.object({\n name: z.string(),\n slug: z.string(),\n }),\n ),\n {\n description:\n 'A path of group names or objects (name and slug) that is ensured to exist',\n },\n )\n .min(1),\n },\n output: {\n groupId: z =>\n z\n .number({\n description: 'The id of the innermost sub-group',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n if (ctx.isDryRun) {\n ctx.output('groupId', 42);\n return;\n }\n\n const { token, repoUrl, path } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const api = getClient({ host, integrations, token });\n\n let currentPath: string | null = null;\n let parentId: number | null = null;\n for (const { name, slug } of pathIterator(path)) {\n const fullPath: string = currentPath ? `${currentPath}/${slug}` : slug;\n const result = (await api.Groups.search(\n fullPath,\n )) as unknown as Array<GroupSchema>; // recast since the return type for search is wrong in the gitbeaker typings\n const subGroup = result.find(\n searchPathElem => searchPathElem.full_path === fullPath,\n );\n if (!subGroup) {\n ctx.logger.info(`creating missing group ${fullPath}`);\n\n parentId = await ctx.checkpoint({\n key: `ensure.${name}.${slug}.${parentId}`,\n // eslint-disable-next-line no-loop-func\n fn: async () => {\n return (\n await api.Groups.create(\n name,\n slug,\n parentId\n ? {\n parentId: parentId,\n }\n : {},\n )\n )?.id;\n },\n });\n } else {\n parentId = subGroup.id;\n }\n currentPath = fullPath;\n }\n if (parentId !== null) {\n ctx.output('groupId', parentId);\n }\n },\n });\n};\n\ntype PathPart = { name: string; slug: string };\ntype PathItem = string | PathPart;\n\nfunction* pathIterator(items: PathItem[]): Generator<PathPart> {\n for (const item of items) {\n if (typeof item === 'string') {\n const parts = item.split('/');\n for (const part of parts) {\n yield { name: part, slug: part };\n }\n } else {\n yield item;\n }\n }\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","getClient"],"mappings":";;;;;;AA2Ba,MAAA,mCAAA,GAAsC,CAAC,OAE9C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,2BAAA;AAAA,IACJ,WAAa,EAAA,+BAAA;AAAA,IACb,cAAgB,EAAA,IAAA;AAAA,cAChBC,yCAAA;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,IAAA,EAAM,OACJ,CACG,CAAA,KAAA;AAAA,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ACA,QAAA,IAAI,CAAC,QAAU,EAAA;AACb,UAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAA0B,uBAAA,EAAA,QAAQ,CAAE,CAAA,CAAA;AAEpD,UAAW,QAAA,GAAA,MAAM,IAAI,UAAW,CAAA;AAAA,YAC9B,KAAK,CAAU,OAAA,EAAA,IAAI,CAAI,CAAA,EAAA,IAAI,IAAI,QAAQ,CAAA,CAAA;AAAA;AAAA,YAEvC,IAAI,YAAY;AACd,cACE,OAAA,CAAA,MAAM,IAAI,MAAO,CAAA,MAAA;AAAA,gBACf,IAAA;AAAA,gBACA,IAAA;AAAA,gBACA,QACI,GAAA;AAAA,kBACE;AAAA,oBAEF;AAAC,eAEN,GAAA,EAAA;AAAA;AACL,WACD,CAAA;AAAA,SACI,MAAA;AACL,UAAA,QAAA,GAAW,QAAS,CAAA,EAAA;AAAA;AAEtB,QAAc,WAAA,GAAA,QAAA;AAAA;AAEhB,MAAA,IAAI,aAAa,IAAM,EAAA;AACrB,QAAI,GAAA,CAAA,MAAA,CAAO,WAAW,QAAQ,CAAA;AAAA;AAChC;AACF,GACD,CAAA;AACH;AAKA,UAAU,aAAa,KAAwC,EAAA;AAC7D,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAI,IAAA,OAAO,SAAS,QAAU,EAAA;AAC5B,MAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,KAAA,CAAM,GAAG,CAAA;AAC5B,MAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,QAAA,MAAM,EAAE,IAAA,EAAM,IAAM,EAAA,IAAA,EAAM,IAAK,EAAA;AAAA;AACjC,KACK,MAAA;AACL,MAAM,MAAA,IAAA;AAAA;AACR;AAEJ;;;;"}
@@ -4,53 +4,9 @@ var errors = require('@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
6
6
  var gitlabIssueCreate_examples = require('./gitlabIssueCreate.examples.cjs.js');
7
- var zod = require('zod');
8
7
  var util = require('../util.cjs.js');
9
8
  var helpers = require('./helpers.cjs.js');
10
9
 
11
- const issueInputProperties = zod.z.object({
12
- projectId: zod.z.number().describe("Project Id"),
13
- title: zod.z.string({ description: "Title of the issue" }),
14
- assignees: zod.z.array(zod.z.number(), {
15
- description: "IDs of the users to assign the issue to."
16
- }).optional(),
17
- confidential: zod.z.boolean({ description: "Issue Confidentiality" }).optional(),
18
- description: zod.z.string().describe("Issue description").max(1048576).optional(),
19
- createdAt: zod.z.string().describe("Creation date/time").regex(
20
- /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
21
- "Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
22
- ).optional(),
23
- dueDate: zod.z.string().describe("Due date/time").regex(
24
- /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
25
- "Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
26
- ).optional(),
27
- discussionToResolve: zod.z.string({
28
- description: 'Id of a discussion to resolve. Use in combination with "merge_request_to_resolve_discussions_of"'
29
- }).optional(),
30
- epicId: zod.z.number({ description: "Id of the linked Epic" }).min(0, "Valid values should be equal or greater than zero").optional(),
31
- labels: zod.z.string({ description: "Labels to apply" }).optional(),
32
- issueType: zod.z.nativeEnum(commonGitlabConfig.IssueType, {
33
- description: "Type of the issue"
34
- }).optional(),
35
- mergeRequestToResolveDiscussionsOf: zod.z.number({
36
- description: "IID of a merge request in which to resolve all issues"
37
- }).optional(),
38
- milestoneId: zod.z.number({ description: "Global ID of a milestone to assign the issue" }).optional(),
39
- weight: zod.z.number({ description: "The issue weight" }).min(0).refine((value) => {
40
- const isValid = value >= 0;
41
- if (!isValid) {
42
- return {
43
- message: "Valid values should be equal or greater than zero"
44
- };
45
- }
46
- return isValid;
47
- }).optional()
48
- });
49
- const issueOutputProperties = zod.z.object({
50
- issueUrl: zod.z.string({ description: "Issue Url" }),
51
- issueId: zod.z.number({ description: "Issue Id" }),
52
- issueIid: zod.z.number({ description: "Issue Iid" })
53
- });
54
10
  const createGitlabIssueAction = (options) => {
55
11
  const { integrations } = options;
56
12
  return pluginScaffolderNode.createTemplateAction({
@@ -58,8 +14,80 @@ const createGitlabIssueAction = (options) => {
58
14
  description: "Creates a Gitlab issue.",
59
15
  examples: gitlabIssueCreate_examples.examples,
60
16
  schema: {
61
- input: commonGitlabConfig.default.merge(issueInputProperties),
62
- output: issueOutputProperties
17
+ input: {
18
+ repoUrl: (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
+ token: (z) => z.string({
22
+ description: "The token to use for authorization to GitLab"
23
+ }).optional(),
24
+ projectId: (z) => z.number({
25
+ description: "Project Id"
26
+ }),
27
+ title: (z) => z.string({
28
+ description: "Title of the issue"
29
+ }),
30
+ assignees: (z) => z.array(z.number(), {
31
+ description: "IDs of the users to assign the issue to."
32
+ }).optional(),
33
+ confidential: (z) => z.boolean({
34
+ description: "Issue Confidentiality"
35
+ }).optional(),
36
+ description: (z) => z.string({
37
+ description: "Issue description"
38
+ }).max(1048576).optional(),
39
+ createdAt: (z) => z.string({
40
+ description: "Creation date/time"
41
+ }).regex(
42
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
43
+ "Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
44
+ ).optional(),
45
+ dueDate: (z) => z.string({
46
+ description: "Due date/time"
47
+ }).regex(
48
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
49
+ "Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
50
+ ).optional(),
51
+ discussionToResolve: (z) => z.string({
52
+ description: 'Id of a discussion to resolve. Use in combination with "merge_request_to_resolve_discussions_of"'
53
+ }).optional(),
54
+ epicId: (z) => z.number({
55
+ description: "Id of the linked Epic"
56
+ }).min(0, "Valid values should be equal or greater than zero").optional(),
57
+ labels: (z) => z.string({
58
+ description: "Labels to apply"
59
+ }).optional(),
60
+ issueType: (z) => z.nativeEnum(commonGitlabConfig.IssueType, {
61
+ description: "Type of the issue"
62
+ }).optional(),
63
+ mergeRequestToResolveDiscussionsOf: (z) => z.number({
64
+ description: "IID of a merge request in which to resolve all issues"
65
+ }).optional(),
66
+ milestoneId: (z) => z.number({
67
+ description: "Global ID of a milestone to assign the issue"
68
+ }).optional(),
69
+ weight: (z) => z.number({
70
+ description: "The issue weight"
71
+ }).min(0).refine(
72
+ (value) => {
73
+ return value >= 0;
74
+ },
75
+ {
76
+ message: "Valid values should be equal or greater than zero"
77
+ }
78
+ ).optional()
79
+ },
80
+ output: {
81
+ issueUrl: (z) => z.string({
82
+ description: "Issue Url"
83
+ }),
84
+ issueId: (z) => z.number({
85
+ description: "Issue Id"
86
+ }),
87
+ issueIid: (z) => z.number({
88
+ description: "Issue Iid"
89
+ })
90
+ }
63
91
  },
64
92
  async handler(ctx) {
65
93
  try {
@@ -80,7 +108,7 @@ const createGitlabIssueAction = (options) => {
80
108
  milestoneId,
81
109
  weight,
82
110
  token
83
- } = commonGitlabConfig.default.merge(issueInputProperties).parse(ctx.input);
111
+ } = ctx.input;
84
112
  const { host } = util.parseRepoUrl(repoUrl, integrations);
85
113
  const api = util.getClient({ host, integrations, token });
86
114
  let isEpicScoped = false;
@@ -138,11 +166,6 @@ const createGitlabIssueAction = (options) => {
138
166
  ctx.output("issueUrl", response.web_url);
139
167
  ctx.output("issueIid", response.iid);
140
168
  } catch (error) {
141
- if (error instanceof zod.z.ZodError) {
142
- throw new errors.InputError(`Validation error: ${error.message}`, {
143
- validationErrors: error.errors
144
- });
145
- }
146
169
  throw new errors.InputError(
147
170
  `Failed to create GitLab issue: ${helpers.getErrorMessage(error)}`
148
171
  );
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabIssueCreate.cjs.js","sources":["../../src/actions/gitlabIssueCreate.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 commonGitlabConfig, { IssueType } from '../commonGitlabConfig';\nimport { examples } from './gitlabIssueCreate.examples';\nimport { z } from 'zod';\nimport { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';\nimport { CreateIssueOptions, IssueSchema } from '@gitbeaker/rest';\nimport { getErrorMessage } from './helpers';\n\nconst issueInputProperties = z.object({\n projectId: z.number().describe('Project Id'),\n title: z.string({ description: 'Title of the issue' }),\n assignees: z\n .array(z.number(), {\n description: 'IDs of the users to assign the issue to.',\n })\n .optional(),\n confidential: z.boolean({ description: 'Issue Confidentiality' }).optional(),\n description: z.string().describe('Issue description').max(1048576).optional(),\n createdAt: z\n .string()\n .describe('Creation date/time')\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/,\n 'Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ',\n )\n .optional(),\n dueDate: z\n .string()\n .describe('Due date/time')\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/,\n 'Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ',\n )\n .optional(),\n discussionToResolve: z\n .string({\n description:\n 'Id of a discussion to resolve. Use in combination with \"merge_request_to_resolve_discussions_of\"',\n })\n .optional(),\n epicId: z\n .number({ description: 'Id of the linked Epic' })\n .min(0, 'Valid values should be equal or greater than zero')\n .optional(),\n labels: z.string({ description: 'Labels to apply' }).optional(),\n issueType: z\n .nativeEnum(IssueType, {\n description: 'Type of the issue',\n })\n .optional(),\n mergeRequestToResolveDiscussionsOf: z\n .number({\n description: 'IID of a merge request in which to resolve all issues',\n })\n .optional(),\n milestoneId: z\n .number({ description: 'Global ID of a milestone to assign the issue' })\n .optional(),\n weight: z\n .number({ description: 'The issue weight' })\n .min(0)\n .refine(value => {\n const isValid = value >= 0;\n if (!isValid) {\n return {\n message: 'Valid values should be equal or greater than zero',\n };\n }\n return isValid;\n })\n .optional(),\n});\n\nconst issueOutputProperties = z.object({\n issueUrl: z.string({ description: 'Issue Url' }),\n issueId: z.number({ description: 'Issue Id' }),\n issueIid: z.number({ description: 'Issue Iid' }),\n});\n\n/**\n * Creates a `gitlab:issues:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabIssueAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:issues:create',\n description: 'Creates a Gitlab issue.',\n examples,\n schema: {\n input: commonGitlabConfig.merge(issueInputProperties),\n output: issueOutputProperties,\n },\n async handler(ctx) {\n try {\n const {\n repoUrl,\n projectId,\n title,\n description = '',\n confidential = false,\n assignees = [],\n createdAt = '',\n dueDate,\n discussionToResolve = '',\n epicId,\n labels = '',\n issueType,\n mergeRequestToResolveDiscussionsOf,\n milestoneId,\n weight,\n token,\n } = commonGitlabConfig.merge(issueInputProperties).parse(ctx.input);\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n let isEpicScoped = false;\n\n isEpicScoped = await ctx.checkpoint({\n key: `is.epic.scoped.${projectId}.${title}`,\n fn: async () => {\n if (epicId) {\n isEpicScoped = await checkEpicScope(api, projectId, epicId);\n\n if (isEpicScoped) {\n ctx.logger.info('Epic is within Project Scope');\n } else {\n ctx.logger.warn(\n 'Chosen epic is not within the Project Scope. The issue will be created without an associated epic.',\n );\n }\n }\n return isEpicScoped;\n },\n });\n\n const mappedCreatedAt = convertDate(\n String(createdAt),\n new Date().toISOString(),\n );\n const mappedDueDate = dueDate\n ? convertDate(String(dueDate), new Date().toISOString())\n : undefined;\n\n const issueOptions: CreateIssueOptions = {\n description,\n assigneeIds: assignees,\n confidential,\n epicId: isEpicScoped ? epicId : undefined,\n labels,\n createdAt: mappedCreatedAt,\n dueDate: mappedDueDate,\n discussionToResolve,\n issueType,\n mergeRequestToResolveDiscussionsOf,\n milestoneId,\n weight,\n };\n\n const response = await ctx.checkpoint({\n key: `issue.${projectId}.${title}`,\n fn: async () => {\n const issue = (await api.Issues.create(\n projectId,\n title,\n issueOptions,\n )) as IssueSchema;\n\n return {\n id: issue.id,\n web_url: issue.web_url,\n iid: issue.iid,\n };\n },\n });\n\n ctx.output('issueId', response.id);\n ctx.output('issueUrl', response.web_url);\n ctx.output('issueIid', response.iid);\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 create GitLab issue: ${getErrorMessage(error)}`,\n );\n }\n },\n });\n};\n"],"names":["z","IssueType","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","checkEpicScope","convertDate","InputError","getErrorMessage"],"mappings":";;;;;;;;;;AA0BA,MAAM,oBAAA,GAAuBA,MAAE,MAAO,CAAA;AAAA,EACpC,SAAW,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,YAAY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kB,KAAM,CAAA;AAAA,WACzB,CAAA;AAAA;AAGH,QAAA,MAAM,IAAIA,iBAAA;AAAA,UACR,CAAA,+BAAA,EAAkCC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SAC1D;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabIssueCreate.cjs.js","sources":["../../src/actions/gitlabIssueCreate.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 { IssueType } from '../commonGitlabConfig';\nimport { examples } from './gitlabIssueCreate.examples';\nimport { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';\nimport { CreateIssueOptions, IssueSchema } from '@gitbeaker/rest';\nimport { getErrorMessage } from './helpers';\n\n/**\n * Creates a `gitlab:issues:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabIssueAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:issues:create',\n description: 'Creates a Gitlab issue.',\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 title: z =>\n z.string({\n description: 'Title of the issue',\n }),\n assignees: z =>\n z\n .array(z.number(), {\n description: 'IDs of the users to assign the issue to.',\n })\n .optional(),\n confidential: z =>\n z\n .boolean({\n description: 'Issue Confidentiality',\n })\n .optional(),\n description: z =>\n z\n .string({\n description: 'Issue description',\n })\n .max(1048576)\n .optional(),\n createdAt: z =>\n z\n .string({\n description: 'Creation date/time',\n })\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/,\n 'Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ',\n )\n .optional(),\n dueDate: z =>\n z\n .string({\n description: 'Due date/time',\n })\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/,\n 'Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ',\n )\n .optional(),\n discussionToResolve: z =>\n z\n .string({\n description:\n 'Id of a discussion to resolve. Use in combination with \"merge_request_to_resolve_discussions_of\"',\n })\n .optional(),\n epicId: z =>\n z\n .number({\n description: 'Id of the linked Epic',\n })\n .min(0, 'Valid values should be equal or greater than zero')\n .optional(),\n labels: z =>\n z\n .string({\n description: 'Labels to apply',\n })\n .optional(),\n issueType: z =>\n z\n .nativeEnum(IssueType, {\n description: 'Type of the issue',\n })\n .optional(),\n mergeRequestToResolveDiscussionsOf: z =>\n z\n .number({\n description:\n 'IID of a merge request in which to resolve all issues',\n })\n .optional(),\n milestoneId: z =>\n z\n .number({\n description: 'Global ID of a milestone to assign the issue',\n })\n .optional(),\n weight: z =>\n z\n .number({\n description: 'The issue weight',\n })\n .min(0)\n .refine(\n value => {\n return value >= 0;\n },\n {\n message: 'Valid values should be equal or greater than zero',\n },\n )\n .optional(),\n },\n output: {\n issueUrl: z =>\n z.string({\n description: 'Issue Url',\n }),\n issueId: z =>\n z.number({\n description: 'Issue Id',\n }),\n issueIid: z =>\n z.number({\n description: 'Issue Iid',\n }),\n },\n },\n async handler(ctx) {\n try {\n const {\n repoUrl,\n projectId,\n title,\n description = '',\n confidential = false,\n assignees = [],\n createdAt = '',\n dueDate,\n discussionToResolve = '',\n epicId,\n labels = '',\n issueType,\n mergeRequestToResolveDiscussionsOf,\n milestoneId,\n weight,\n token,\n } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n let isEpicScoped = false;\n\n isEpicScoped = await ctx.checkpoint({\n key: `is.epic.scoped.${projectId}.${title}`,\n fn: async () => {\n if (epicId) {\n isEpicScoped = await checkEpicScope(api, projectId, epicId);\n\n if (isEpicScoped) {\n ctx.logger.info('Epic is within Project Scope');\n } else {\n ctx.logger.warn(\n 'Chosen epic is not within the Project Scope. The issue will be created without an associated epic.',\n );\n }\n }\n return isEpicScoped;\n },\n });\n\n const mappedCreatedAt = convertDate(\n String(createdAt),\n new Date().toISOString(),\n );\n const mappedDueDate = dueDate\n ? convertDate(String(dueDate), new Date().toISOString())\n : undefined;\n\n const issueOptions: CreateIssueOptions = {\n description,\n assigneeIds: assignees,\n confidential,\n epicId: isEpicScoped ? epicId : undefined,\n labels,\n createdAt: mappedCreatedAt,\n dueDate: mappedDueDate,\n discussionToResolve,\n issueType,\n mergeRequestToResolveDiscussionsOf,\n milestoneId,\n weight,\n };\n\n const response = await ctx.checkpoint({\n key: `issue.${projectId}.${title}`,\n fn: async () => {\n const issue = (await api.Issues.create(\n projectId,\n title,\n issueOptions,\n )) as IssueSchema;\n\n return {\n id: issue.id,\n web_url: issue.web_url,\n iid: issue.iid,\n };\n },\n });\n\n ctx.output('issueId', response.id);\n ctx.output('issueUrl', response.web_url);\n ctx.output('issueIid', response.iid);\n } catch (error: any) {\n // Handling other errors\n throw new InputError(\n `Failed to create GitLab issue: ${getErrorMessage(error)}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","IssueType","parseRepoUrl","getClient","chec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CAAA,OAAA;AAAA,cACf,KAAK,KAAM,CAAA;AAAA,aACb;AAAA;AACF,SACD,CAAA;AAED,QAAI,GAAA,CAAA,MAAA,CAAO,SAAW,EAAA,QAAA,CAAS,EAAE,CAAA;AACjC,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,QAAA,CAAS,OAAO,CAAA;AACvC,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,QAAA,CAAS,GAAG,CAAA;AAAA,eAC5B,KAAY,EAAA;AAEnB,QAAA,MAAM,IAAIC,iBAAA;AAAA,UACR,CAAA,+BAAA,EAAkCC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SAC1D;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -4,69 +4,9 @@ var errors = require('@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
5
  var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
6
6
  var gitlabIssueEdit_examples = require('./gitlabIssueEdit.examples.cjs.js');
7
- var zod = require('zod');
8
7
  var util = require('../util.cjs.js');
9
8
  var helpers = require('./helpers.cjs.js');
10
9
 
11
- const editIssueInputProperties = zod.z.object({
12
- projectId: zod.z.number().describe(
13
- "The global ID or URL-encoded path of the project owned by the authenticated user."
14
- ),
15
- issueIid: zod.z.number().describe("The internal ID of a project's issue"),
16
- addLabels: zod.z.string({
17
- description: "Comma-separated label names to add to an issue. If a label does not already exist, this creates a new project label and assigns it to the issue."
18
- }).optional(),
19
- assignees: zod.z.array(zod.z.number(), {
20
- description: "IDs of the users to assign the issue to."
21
- }).optional(),
22
- confidential: zod.z.boolean({ description: "Updates an issue to be confidential." }).optional(),
23
- description: zod.z.string().describe("The description of an issue. Limited to 1,048,576 characters.").max(1048576).optional(),
24
- discussionLocked: zod.z.boolean({
25
- description: "Flag indicating if the issue\u2019s discussion is locked. If the discussion is locked only project members can add or edit comments."
26
- }).optional(),
27
- dueDate: zod.z.string().describe(
28
- "The due date. Date time string in the format YYYY-MM-DD, for example 2016-03-11."
29
- ).regex(/^\d{4}-\d{2}-\d{2}$/, "Invalid date format. Use YYYY-MM-DD").optional(),
30
- epicId: zod.z.number({
31
- description: "ID of the epic to add the issue to. Valid values are greater than or equal to 0."
32
- }).min(0, "Valid values should be equal or greater than zero").optional(),
33
- issueType: zod.z.nativeEnum(commonGitlabConfig.IssueType, {
34
- description: "Updates the type of issue. One of issue, incident, test_case or task."
35
- }).optional(),
36
- labels: zod.z.string({
37
- description: "Comma-separated label names for an issue. Set to an empty string to unassign all labels. If a label does not already exist, this creates a new project label and assigns it to the issue."
38
- }).optional(),
39
- milestoneId: zod.z.number({
40
- description: "The global ID of a milestone to assign the issue to. Set to 0 or provide an empty value to unassign a milestone"
41
- }).optional(),
42
- removeLabels: zod.z.string({
43
- description: "Comma-separated label names to remove from an issue."
44
- }).optional(),
45
- stateEvent: zod.z.nativeEnum(commonGitlabConfig.IssueStateEvent, {
46
- description: "The state event of an issue. To close the issue, use close, and to reopen it, use reopen."
47
- }).optional(),
48
- title: zod.z.string().describe("The title of an issue.").optional(),
49
- updatedAt: zod.z.string().describe(
50
- "When the issue was updated. Date time string, ISO 8601 formatted"
51
- ).regex(
52
- /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
53
- "Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
54
- ).optional(),
55
- weight: zod.z.number({ description: "The issue weight" }).min(0, "Valid values should be equal or greater than zero").max(10, "Valid values should be equal or less than 10").optional()
56
- });
57
- const editIssueOutputProperties = zod.z.object({
58
- issueUrl: zod.z.string({ description: "Issue WebUrl" }),
59
- projectId: zod.z.number({
60
- description: "The project id the issue belongs to WebUrl"
61
- }),
62
- issueId: zod.z.number({ description: "The issues Id" }),
63
- issueIid: zod.z.number({
64
- description: "The issues internal ID of a project's issue"
65
- }),
66
- state: zod.z.string({ description: "The state event of an issue" }),
67
- title: zod.z.string({ description: "The title of an issue." }),
68
- updatedAt: zod.z.string({ description: "The last updated time of the issue." })
69
- });
70
10
  const editGitlabIssueAction = (options) => {
71
11
  const { integrations } = options;
72
12
  return pluginScaffolderNode.createTemplateAction({
@@ -74,8 +14,91 @@ const editGitlabIssueAction = (options) => {
74
14
  description: "Edit a Gitlab issue.",
75
15
  examples: gitlabIssueEdit_examples.examples,
76
16
  schema: {
77
- input: commonGitlabConfig.default.merge(editIssueInputProperties),
78
- output: editIssueOutputProperties
17
+ input: {
18
+ repoUrl: (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
+ token: (z) => z.string({
22
+ description: "The token to use for authorization to GitLab"
23
+ }).optional(),
24
+ projectId: (z) => z.number({
25
+ description: "The global ID or URL-encoded path of the project owned by the authenticated user."
26
+ }),
27
+ issueIid: (z) => z.number({
28
+ description: "The internal ID of a project's issue"
29
+ }),
30
+ addLabels: (z) => z.string({
31
+ description: "Comma-separated label names to add to an issue. If a label does not already exist, this creates a new project label and assigns it to the issue."
32
+ }).optional(),
33
+ assignees: (z) => z.array(z.number(), {
34
+ description: "IDs of the users to assign the issue to."
35
+ }).optional(),
36
+ confidential: (z) => z.boolean({
37
+ description: "Updates an issue to be confidential."
38
+ }).optional(),
39
+ description: (z) => z.string({
40
+ description: "The description of an issue. Limited to 1,048,576 characters."
41
+ }).max(1048576).optional(),
42
+ discussionLocked: (z) => z.boolean({
43
+ description: "Flag indicating if the issue discussion is locked. If the discussion is locked only project members can add or edit comments."
44
+ }).optional(),
45
+ dueDate: (z) => z.string({
46
+ description: "The due date. Date time string in the format YYYY-MM-DD, for example 2016-03-11."
47
+ }).regex(/^\d{4}-\d{2}-\d{2}$/, "Invalid date format. Use YYYY-MM-DD").optional(),
48
+ epicId: (z) => z.number({
49
+ description: "ID of the epic to add the issue to. Valid values are greater than or equal to 0."
50
+ }).min(0, "Valid values should be equal or greater than zero").optional(),
51
+ issueType: (z) => z.nativeEnum(commonGitlabConfig.IssueType, {
52
+ description: "Updates the type of issue. One of issue, incident, test_case or task."
53
+ }).optional(),
54
+ labels: (z) => z.string({
55
+ description: "Comma-separated label names for an issue. Set to an empty string to unassign all labels. If a label does not already exist, this creates a new project label and assigns it to the issue."
56
+ }).optional(),
57
+ milestoneId: (z) => z.number({
58
+ description: "The global ID of a milestone to assign the issue to. Set to 0 or provide an empty value to unassign a milestone"
59
+ }).optional(),
60
+ removeLabels: (z) => z.string({
61
+ description: "Comma-separated label names to remove from an issue."
62
+ }).optional(),
63
+ stateEvent: (z) => z.nativeEnum(commonGitlabConfig.IssueStateEvent, {
64
+ description: "The state event of an issue. To close the issue, use close, and to reopen it, use reopen."
65
+ }).optional(),
66
+ title: (z) => z.string({
67
+ description: "The title of an issue."
68
+ }).optional(),
69
+ updatedAt: (z) => z.string({
70
+ description: "When the issue was updated. Date time string, ISO 8601 formatted"
71
+ }).regex(
72
+ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
73
+ "Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
74
+ ).optional(),
75
+ weight: (z) => z.number({
76
+ description: "The issue weight"
77
+ }).min(0, "Valid values should be equal or greater than zero").max(10, "Valid values should be equal or less than 10").optional()
78
+ },
79
+ output: {
80
+ issueUrl: (z) => z.string({
81
+ description: "Issue WebUrl"
82
+ }),
83
+ projectId: (z) => z.number({
84
+ description: "The project id the issue belongs to WebUrl"
85
+ }),
86
+ issueId: (z) => z.number({
87
+ description: "The issues Id"
88
+ }),
89
+ issueIid: (z) => z.number({
90
+ description: "The issues internal ID of a project's issue"
91
+ }),
92
+ state: (z) => z.string({
93
+ description: "The state event of an issue"
94
+ }),
95
+ title: (z) => z.string({
96
+ description: "The title of an issue."
97
+ }),
98
+ updatedAt: (z) => z.string({
99
+ description: "The last updated time of the issue."
100
+ })
101
+ }
79
102
  },
80
103
  async handler(ctx) {
81
104
  try {
@@ -99,7 +122,7 @@ const editGitlabIssueAction = (options) => {
99
122
  stateEvent,
100
123
  weight,
101
124
  token
102
- } = commonGitlabConfig.default.merge(editIssueInputProperties).parse(ctx.input);
125
+ } = ctx.input;
103
126
  const { host } = util.parseRepoUrl(repoUrl, integrations);
104
127
  const api = util.getClient({ host, integrations, token });
105
128
  let isEpicScoped = false;
@@ -168,11 +191,6 @@ const editGitlabIssueAction = (options) => {
168
191
  ctx.output("state", editedIssue.state);
169
192
  ctx.output("updatedAt", editedIssue.updatedAt);
170
193
  } catch (error) {
171
- if (error instanceof zod.z.ZodError) {
172
- throw new errors.InputError(`Validation error: ${error.message}`, {
173
- validationErrors: error.errors
174
- });
175
- }
176
194
  throw new errors.InputError(
177
195
  `Failed to edit/modify GitLab issue: ${helpers.getErrorMessage(error)}`
178
196
  );
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabIssueEdit.cjs.js","sources":["../../src/actions/gitlabIssueEdit.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 commonGitlabConfig, {\n IssueStateEvent,\n IssueType,\n} from '../commonGitlabConfig';\nimport { examples } from './gitlabIssueEdit.examples';\nimport { z } from 'zod';\nimport { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';\nimport { EditIssueOptions, IssueSchema } from '@gitbeaker/rest';\nimport { getErrorMessage } from './helpers';\n\nconst editIssueInputProperties = z.object({\n projectId: z\n .number()\n .describe(\n 'The global ID or URL-encoded path of the project owned by the authenticated user.',\n ),\n issueIid: z.number().describe(\"The internal ID of a project's issue\"),\n addLabels: z\n .string({\n description:\n 'Comma-separated label names to add to an issue. If a label does not already exist, this creates a new project label and assigns it to the issue.',\n })\n .optional(),\n assignees: z\n .array(z.number(), {\n description: 'IDs of the users to assign the issue to.',\n })\n .optional(),\n confidential: z\n .boolean({ description: 'Updates an issue to be confidential.' })\n .optional(),\n description: z\n .string()\n .describe('The description of an issue. Limited to 1,048,576 characters.')\n .max(1048576)\n .optional(),\n discussionLocked: z\n .boolean({\n description:\n 'Flag indicating if the issue’s discussion is locked. If the discussion is locked only project members can add or edit comments.',\n })\n .optional(),\n dueDate: z\n .string()\n .describe(\n 'The due date. Date time string in the format YYYY-MM-DD, for example 2016-03-11.',\n )\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, 'Invalid date format. Use YYYY-MM-DD')\n .optional(),\n epicId: z\n .number({\n description:\n 'ID of the epic to add the issue to. Valid values are greater than or equal to 0.',\n })\n .min(0, 'Valid values should be equal or greater than zero')\n .optional(),\n issueType: z\n .nativeEnum(IssueType, {\n description:\n 'Updates the type of issue. One of issue, incident, test_case or task.',\n })\n .optional(),\n labels: z\n .string({\n description:\n 'Comma-separated label names for an issue. Set to an empty string to unassign all labels. If a label does not already exist, this creates a new project label and assigns it to the issue.',\n })\n .optional(),\n milestoneId: z\n .number({\n description:\n 'The global ID of a milestone to assign the issue to. Set to 0 or provide an empty value to unassign a milestone',\n })\n .optional(),\n removeLabels: z\n .string({\n description: 'Comma-separated label names to remove from an issue.',\n })\n .optional(),\n stateEvent: z\n .nativeEnum(IssueStateEvent, {\n description:\n 'The state event of an issue. To close the issue, use close, and to reopen it, use reopen.',\n })\n .optional(),\n title: z.string().describe('The title of an issue.').optional(),\n updatedAt: z\n .string()\n .describe(\n 'When the issue was updated. Date time string, ISO 8601 formatted',\n )\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/,\n 'Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ',\n )\n .optional(),\n weight: z\n .number({ description: 'The issue weight' })\n .min(0, 'Valid values should be equal or greater than zero')\n .max(10, 'Valid values should be equal or less than 10')\n .optional(),\n});\n\nconst editIssueOutputProperties = z.object({\n issueUrl: z.string({ description: 'Issue WebUrl' }),\n projectId: z.number({\n description: 'The project id the issue belongs to WebUrl',\n }),\n issueId: z.number({ description: 'The issues Id' }),\n issueIid: z.number({\n description: \"The issues internal ID of a project's issue\",\n }),\n state: z.string({ description: 'The state event of an issue' }),\n title: z.string({ description: 'The title of an issue.' }),\n updatedAt: z.string({ description: 'The last updated time of the issue.' }),\n});\n\n/**\n * Creates a `gitlab:issue:edit` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const editGitlabIssueAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:issue:edit',\n description: 'Edit a Gitlab issue.',\n examples,\n schema: {\n input: commonGitlabConfig.merge(editIssueInputProperties),\n output: editIssueOutputProperties,\n },\n async handler(ctx) {\n try {\n const {\n repoUrl,\n projectId,\n title,\n addLabels,\n removeLabels,\n issueIid,\n description,\n confidential = false,\n assignees = [],\n updatedAt = '',\n dueDate,\n discussionLocked = false,\n epicId,\n labels,\n issueType,\n milestoneId,\n stateEvent,\n weight,\n token,\n } = commonGitlabConfig.merge(editIssueInputProperties).parse(ctx.input);\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n let isEpicScoped = false;\n\n isEpicScoped = await ctx.checkpoint({\n key: `issue.edit.is.scoped.${projectId}.${epicId}`,\n fn: async () => {\n if (epicId) {\n const scoped = await checkEpicScope(api, projectId, epicId);\n\n if (scoped) {\n ctx.logger.info('Epic is within Project Scope');\n } else {\n ctx.logger.warn(\n 'Chosen epic is not within the Project Scope. The issue will be created without an associated epic.',\n );\n }\n return scoped;\n }\n return false;\n },\n });\n\n const mappedUpdatedAt = convertDate(\n String(updatedAt),\n new Date().toISOString(),\n );\n\n const editIssueOptions: EditIssueOptions = {\n addLabels,\n assigneeIds: assignees,\n confidential,\n description,\n discussionLocked,\n dueDate,\n epicId: isEpicScoped ? epicId : undefined,\n issueType,\n labels,\n milestoneId,\n removeLabels,\n stateEvent,\n title,\n updatedAt: mappedUpdatedAt,\n weight,\n };\n\n const editedIssue = await ctx.checkpoint({\n key: `issue.edit.${projectId}.${issueIid}`,\n fn: async () => {\n const response = (await api.Issues.edit(\n projectId,\n issueIid,\n editIssueOptions,\n )) as IssueSchema;\n\n return {\n issueId: response.id,\n issueUrl: response.web_url,\n projectId: response.project_id,\n issueIid: response.iid,\n title: response.title,\n state: response.state,\n updatedAt: response.updated_at,\n };\n },\n });\n\n ctx.output('issueId', editedIssue.issueId);\n ctx.output('projectId', editedIssue.projectId);\n ctx.output('issueUrl', editedIssue.issueUrl);\n ctx.output('issueIid', editedIssue.issueIid);\n ctx.output('title', editedIssue.title);\n ctx.output('state', editedIssue.state);\n ctx.output('updatedAt', editedIssue.updatedAt);\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 edit/modify GitLab issue: ${getErrorMessage(error)}`,\n );\n }\n },\n });\n};\n"],"names":["z","IssueType","IssueStateEvent","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","checkEpicScope","convertDate","InputError","getErrorMessage"],"mappings":";;;;;;;;;;AA6BA,MAAM,wBAAA,GAA2BA,MAAE,MAAO,CAAA;AAAA,EACxC,SAAA,EAAWA,KACR,CAAA,MAAA,EACA,CAAA,QAAA;AAAA,IACC;AAAA,GACF;AAAA,EACF,QAAU,EAAAA,KAA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AAO,QAAS,CAAA,KAAA;AAAA,cAChB,WAAW,QAAS,CAAA;AAAA,aACtB;AAAA;AACF,SACD,CAAA;AAED,QAAI,GAAA,CAAA,MAAA,CAAO,SAAW,EAAA,WAAA,CAAY,OAAO,CAAA;AACzC,QAAI,GAAA,CAAA,MAAA,CAAO,WAAa,EAAA,WAAA,CAAY,SAAS,CAAA;AAC7C,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,WAAA,CAAY,QAAQ,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,WAAA,CAAY,QAAQ,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,OAAS,EAAA,WAAA,CAAY,KAAK,CAAA;AACrC,QAAI,GAAA,CAAA,MAAA,CAAO,OAAS,EAAA,WAAA,CAAY,KAAK,CAAA;AACrC,QAAI,GAAA,CAAA,MAAA,CAAO,WAAa,EAAA,WAAA,CAAY,SAAS,CAAA;AAAA,eACtC,KAAY,EAAA;AACnB,QAAI,IAAA,KAAA,YAAiBT,MAAE,QAAU,EAAA;AAE/B,UAAA,MAAM,IAAIU,iBAAA,CAAW,CAAqB,kBAAA,EAAA,KAAA,CAAM,OAAO,CAAI,CAAA,EAAA;AAAA,YACzD,kBAAkB,KAAM,CAAA;AAAA,WACzB,CAAA;AAAA;AAGH,QAAA,MAAM,IAAIA,iBAAA;AAAA,UACR,CAAA,oCAAA,EAAuCC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SAC/D;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabIssueEdit.cjs.js","sources":["../../src/actions/gitlabIssueEdit.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 { IssueStateEvent, IssueType } from '../commonGitlabConfig';\nimport { examples } from './gitlabIssueEdit.examples';\nimport { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';\nimport { EditIssueOptions, IssueSchema } from '@gitbeaker/rest';\nimport { getErrorMessage } from './helpers';\n\n/**\n * Creates a `gitlab:issue:edit` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const editGitlabIssueAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:issue:edit',\n description: 'Edit a Gitlab issue.',\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:\n 'The global ID or URL-encoded path of the project owned by the authenticated user.',\n }),\n issueIid: z =>\n z.number({\n description: \"The internal ID of a project's issue\",\n }),\n addLabels: z =>\n z\n .string({\n description:\n 'Comma-separated label names to add to an issue. If a label does not already exist, this creates a new project label and assigns it to the issue.',\n })\n .optional(),\n assignees: z =>\n z\n .array(z.number(), {\n description: 'IDs of the users to assign the issue to.',\n })\n .optional(),\n confidential: z =>\n z\n .boolean({\n description: 'Updates an issue to be confidential.',\n })\n .optional(),\n description: z =>\n z\n .string({\n description:\n 'The description of an issue. Limited to 1,048,576 characters.',\n })\n .max(1048576)\n .optional(),\n discussionLocked: z =>\n z\n .boolean({\n description:\n 'Flag indicating if the issue discussion is locked. If the discussion is locked only project members can add or edit comments.',\n })\n .optional(),\n dueDate: z =>\n z\n .string({\n description:\n 'The due date. Date time string in the format YYYY-MM-DD, for example 2016-03-11.',\n })\n .regex(/^\\d{4}-\\d{2}-\\d{2}$/, 'Invalid date format. Use YYYY-MM-DD')\n .optional(),\n epicId: z =>\n z\n .number({\n description:\n 'ID of the epic to add the issue to. Valid values are greater than or equal to 0.',\n })\n .min(0, 'Valid values should be equal or greater than zero')\n .optional(),\n issueType: z =>\n z\n .nativeEnum(IssueType, {\n description:\n 'Updates the type of issue. One of issue, incident, test_case or task.',\n })\n .optional(),\n labels: z =>\n z\n .string({\n description:\n 'Comma-separated label names for an issue. Set to an empty string to unassign all labels. If a label does not already exist, this creates a new project label and assigns it to the issue.',\n })\n .optional(),\n milestoneId: z =>\n z\n .number({\n description:\n 'The global ID of a milestone to assign the issue to. Set to 0 or provide an empty value to unassign a milestone',\n })\n .optional(),\n removeLabels: z =>\n z\n .string({\n description:\n 'Comma-separated label names to remove from an issue.',\n })\n .optional(),\n stateEvent: z =>\n z\n .nativeEnum(IssueStateEvent, {\n description:\n 'The state event of an issue. To close the issue, use close, and to reopen it, use reopen.',\n })\n .optional(),\n title: z =>\n z\n .string({\n description: 'The title of an issue.',\n })\n .optional(),\n updatedAt: z =>\n z\n .string({\n description:\n 'When the issue was updated. Date time string, ISO 8601 formatted',\n })\n .regex(\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/,\n 'Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ',\n )\n .optional(),\n weight: z =>\n z\n .number({\n description: 'The issue weight',\n })\n .min(0, 'Valid values should be equal or greater than zero')\n .max(10, 'Valid values should be equal or less than 10')\n .optional(),\n },\n output: {\n issueUrl: z =>\n z.string({\n description: 'Issue WebUrl',\n }),\n projectId: z =>\n z.number({\n description: 'The project id the issue belongs to WebUrl',\n }),\n issueId: z =>\n z.number({\n description: 'The issues Id',\n }),\n issueIid: z =>\n z.number({\n description: \"The issues internal ID of a project's issue\",\n }),\n state: z =>\n z.string({\n description: 'The state event of an issue',\n }),\n title: z =>\n z.string({\n description: 'The title of an issue.',\n }),\n updatedAt: z =>\n z.string({\n description: 'The last updated time of the issue.',\n }),\n },\n },\n async handler(ctx) {\n try {\n const {\n repoUrl,\n projectId,\n title,\n addLabels,\n removeLabels,\n issueIid,\n description,\n confidential = false,\n assignees = [],\n updatedAt = '',\n dueDate,\n discussionLocked = false,\n epicId,\n labels,\n issueType,\n milestoneId,\n stateEvent,\n weight,\n token,\n } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n let isEpicScoped = false;\n\n isEpicScoped = await ctx.checkpoint({\n key: `issue.edit.is.scoped.${projectId}.${epicId}`,\n fn: async () => {\n if (epicId) {\n const scoped = await checkEpicScope(api, projectId, epicId);\n\n if (scoped) {\n ctx.logger.info('Epic is within Project Scope');\n } else {\n ctx.logger.warn(\n 'Chosen epic is not within the Project Scope. The issue will be created without an associated epic.',\n );\n }\n return scoped;\n }\n return false;\n },\n });\n\n const mappedUpdatedAt = convertDate(\n String(updatedAt),\n new Date().toISOString(),\n );\n\n const editIssueOptions: EditIssueOptions = {\n addLabels,\n assigneeIds: assignees,\n confidential,\n description,\n discussionLocked,\n dueDate,\n epicId: isEpicScoped ? epicId : undefined,\n issueType,\n labels,\n milestoneId,\n removeLabels,\n stateEvent,\n title,\n updatedAt: mappedUpdatedAt,\n weight,\n };\n\n const editedIssue = await ctx.checkpoint({\n key: `issue.edit.${projectId}.${issueIid}`,\n fn: async () => {\n const response = (await api.Issues.edit(\n projectId,\n issueIid,\n editIssueOptions,\n )) as IssueSchema;\n\n return {\n issueId: response.id,\n issueUrl: response.web_url,\n projectId: response.project_id,\n issueIid: response.iid,\n title: response.title,\n state: response.state,\n updatedAt: response.updated_at,\n };\n },\n });\n\n ctx.output('issueId', editedIssue.issueId);\n ctx.output('projectId', editedIssue.projectId);\n ctx.output('issueUrl', editedIssue.issueUrl);\n ctx.output('issueIid', editedIssue.issueIid);\n ctx.output('title', editedIssue.title);\n ctx.output('state', editedIssue.state);\n ctx.output('updatedAt', editedIssue.updatedAt);\n } catch (error: any) {\n // Handling other errors\n throw new InputError(\n `Failed to edit/modify GitLab issue: ${getErrorMessage(error)}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","IssueType","IssueStateEvent","parseRepoUrl","getClient","checkEpicScope","convertDate","InputError","getErrorMessage"],"mappings":";;;;;;;;;AA+Ba,MAAA,qBAAA,GAAwB,CAAC,OAEhC,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,mBAAA;AAAA,IACJ,WAAa,EAAA,sBAAA;AAAA,cACbC,iCAAA;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,WACE,EAAA;AAAA,SACH,CAAA;AAAA,QACH,QAAA,EAAU,CACR,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,WAAW,CACT,CAAA,KAAA,CAAA,CACG,KAAM,CAAA,CAAA,CAAE,QAAU,EAAA;AAAA,UACjB,WAAa,E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AA,WAAA,CAAY,SAAS,CAAA;AAC7C,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,WAAA,CAAY,QAAQ,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,WAAA,CAAY,QAAQ,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,OAAS,EAAA,WAAA,CAAY,KAAK,CAAA;AACrC,QAAI,GAAA,CAAA,MAAA,CAAO,OAAS,EAAA,WAAA,CAAY,KAAK,CAAA;AACrC,QAAI,GAAA,CAAA,MAAA,CAAO,WAAa,EAAA,WAAA,CAAY,SAAS,CAAA;AAAA,eACtC,KAAY,EAAA;AAEnB,QAAA,MAAM,IAAIC,iBAAA;AAAA,UACR,CAAA,oCAAA,EAAuCC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SAC/D;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -2,23 +2,10 @@
2
2
 
3
3
  var errors = require('@backstage/errors');
4
4
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
- var zod = require('zod');
6
- var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
7
5
  var util = require('../util.cjs.js');
8
6
  var gitlabPipelineTrigger_examples = require('./gitlabPipelineTrigger.examples.cjs.js');
9
7
  var helpers = require('./helpers.cjs.js');
10
8
 
11
- const pipelineInputProperties = zod.z.object({
12
- projectId: zod.z.number().describe("Project Id"),
13
- tokenDescription: zod.z.string().describe("Pipeline token description"),
14
- branch: zod.z.string().describe("Project branch"),
15
- variables: zod.z.record(zod.z.string(), zod.z.string()).optional().describe(
16
- "A object/record of key-valued strings containing the pipeline variables."
17
- )
18
- });
19
- const pipelineOutputProperties = zod.z.object({
20
- pipelineUrl: zod.z.string({ description: "Pipeline Url" })
21
- });
22
9
  const createTriggerGitlabPipelineAction = (options) => {
23
10
  const { integrations } = options;
24
11
  return pluginScaffolderNode.createTemplateAction({
@@ -26,13 +13,36 @@ const createTriggerGitlabPipelineAction = (options) => {
26
13
  description: "Triggers a GitLab Pipeline.",
27
14
  examples: gitlabPipelineTrigger_examples.examples,
28
15
  schema: {
29
- input: commonGitlabConfig.default.merge(pipelineInputProperties),
30
- output: pipelineOutputProperties
16
+ input: {
17
+ repoUrl: (z) => z.string({
18
+ 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`
19
+ }),
20
+ token: (z) => z.string({
21
+ description: "The token to use for authorization to GitLab"
22
+ }).optional(),
23
+ projectId: (z) => z.number({
24
+ description: "Project Id"
25
+ }),
26
+ tokenDescription: (z) => z.string({
27
+ description: "Pipeline token description"
28
+ }),
29
+ branch: (z) => z.string({
30
+ description: "Project branch"
31
+ }),
32
+ variables: (z) => z.record(z.string(), z.string(), {
33
+ description: "A object/record of key-valued strings containing the pipeline variables."
34
+ }).optional()
35
+ },
36
+ output: {
37
+ pipelineUrl: (z) => z.string({
38
+ description: "Pipeline Url"
39
+ })
40
+ }
31
41
  },
32
42
  async handler(ctx) {
33
43
  let pipelineTriggerToken = void 0;
34
44
  let pipelineTriggerId = void 0;
35
- const { repoUrl, projectId, tokenDescription, token, branch, variables } = commonGitlabConfig.default.merge(pipelineInputProperties).parse(ctx.input);
45
+ const { repoUrl, projectId, tokenDescription, token, branch, variables } = ctx.input;
36
46
  const { host } = util.parseRepoUrl(repoUrl, integrations);
37
47
  const api = util.getClient({ host, integrations, token });
38
48
  try {
@@ -75,11 +85,6 @@ const createTriggerGitlabPipelineAction = (options) => {
75
85
  );
76
86
  ctx.output("pipelineUrl", pipelineTriggerResponse.web_url);
77
87
  } catch (error) {
78
- if (error instanceof zod.z.ZodError) {
79
- throw new errors.InputError(`Validation error: ${error.message}`, {
80
- validationErrors: error.errors
81
- });
82
- }
83
88
  throw new errors.InputError(
84
89
  `Failed to trigger Pipeline: ${helpers.getErrorMessage(error)}`
85
90
  );