@backstage/plugin-scaffolder-backend-module-gitlab 0.6.1-next.3 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
+ ## 0.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/plugin-scaffolder-node@0.6.1
9
+
10
+ ## 0.6.1
11
+
12
+ ### Patch Changes
13
+
14
+ - cdc8b4c: Improve error messages from Gitlab
15
+ - 2dbdccb: Removed circular import
16
+ - Updated dependencies
17
+ - @backstage/config@1.3.0
18
+ - @backstage/backend-plugin-api@1.0.2
19
+ - @backstage/plugin-scaffolder-node@0.6.0
20
+ - @backstage/errors@1.2.5
21
+ - @backstage/integration@1.15.2
22
+
3
23
  ## 0.6.1-next.3
4
24
 
5
25
  ### Patch Changes
@@ -6,6 +6,7 @@ var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
6
6
  var gitlabIssueCreate_examples = require('./gitlabIssueCreate.examples.cjs.js');
7
7
  var zod = require('zod');
8
8
  var util = require('../util.cjs.js');
9
+ var helpers = require('./helpers.cjs.js');
9
10
 
10
11
  const issueInputProperties = zod.z.object({
11
12
  projectId: zod.z.number().describe("Project Id"),
@@ -126,7 +127,9 @@ const createGitlabIssueAction = (options) => {
126
127
  validationErrors: error.errors
127
128
  });
128
129
  }
129
- throw new errors.InputError(`Failed to create GitLab issue: ${error.message}`);
130
+ throw new errors.InputError(
131
+ `Failed to create GitLab issue: ${helpers.getErrorMessage(error)}`
132
+ );
130
133
  }
131
134
  }
132
135
  });
@@ -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';\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 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 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 api.Issues.create(\n projectId,\n title,\n issueOptions,\n )) as IssueSchema;\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(`Failed to create GitLab issue: ${error.message}`);\n }\n },\n });\n};\n"],"names":["z","IssueType","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","checkEpicScope","convertDate","InputError"],"mappings":";;;;;;;;;AAyBA,MAAM,oBAAA,GAAuBA,MAAE,MAAO,CAAA;AAAA,EACpC,SAAW,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,YAAY,CAAA;AAAA,EAC3C,OAAOA,KAAE,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,sBAAsB,CAAA;AAAA,EACrD,SAAW,EAAAA,KAAA,CACR,KAAM,CAAAA,KAAA,CAAE,QAAU,EAAA;AAAA,IACjB,WAAa,EAAA;AAAA,GACd,EACA,QAAS,EAAA;AAAA,EACZ,YAAA,EAAcA,MAAE,OAAQ,CAAA,EAAE,aAAa,uBAAwB,EAAC,EAAE,QAAS,EAAA;AAAA,EAC3E,WAAA,EAAaA,KAAE,CAAA,MAAA,EAAS,CAAA,QAAA,CAAS,mBAAmB,CAAE,CAAA,GAAA,CAAI,OAAO,CAAA,CAAE,QAAS,EAAA;AAAA,EAC5E,WAAWA,KACR,CAAA,MAAA,EACA,CAAA,QAAA,CAAS,oBAAoB,C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AA,CAAS,GAAG,CAAA;AAAA,eAC5B,KAAY,EAAA;AACnB,QAAI,IAAA,KAAA,YAAiBR,MAAE,QAAU,EAAA;AAE/B,UAAA,MAAM,IAAIS,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,CAAW,CAAkC,+BAAA,EAAA,KAAA,CAAM,OAAO,CAAE,CAAA,CAAA;AAAA;AACxE;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 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 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 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 api.Issues.create(\n projectId,\n title,\n issueOptions,\n )) as IssueSchema;\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,GAAu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A;AAAA,UACA,WAAa,EAAA,SAAA;AAAA,UACb,YAAA;AAAA,UACA,MAAA,EAAQ,eAAe,MAAS,GAAA,KAAA,CAAA;AAAA,UAChC,MAAA;AAAA,UACA,SAAW,EAAA,eAAA;AAAA,UACX,OAAS,EAAA,aAAA;AAAA,UACT,mBAAA;AAAA,UACA,SAAA;AAAA,UACA,kCAAA;AAAA,UACA,WAAA;AAAA,UACA;AAAA,SACF;AAEA,QAAM,MAAA,QAAA,GAAY,MAAM,GAAA,CAAI,MAAO,CAAA,MAAA;AAAA,UACjC,SAAA;AAAA,UACA,KAAA;AAAA,UACA;AAAA,SACF;AAEA,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;AACnB,QAAI,IAAA,KAAA,YAAiBR,MAAE,QAAU,EAAA;AAE/B,UAAA,MAAM,IAAIS,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,+BAAA,EAAkCC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SAC1D;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -6,6 +6,7 @@ var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
6
6
  var gitlabIssueEdit_examples = require('./gitlabIssueEdit.examples.cjs.js');
7
7
  var zod = require('zod');
8
8
  var util = require('../util.cjs.js');
9
+ var helpers = require('./helpers.cjs.js');
9
10
 
10
11
  const editIssueInputProperties = zod.z.object({
11
12
  projectId: zod.z.number().describe(
@@ -152,7 +153,7 @@ const editGitlabIssueAction = (options) => {
152
153
  });
153
154
  }
154
155
  throw new errors.InputError(
155
- `Failed to edit/modify GitLab issue: ${error.message}`
156
+ `Failed to edit/modify GitLab issue: ${helpers.getErrorMessage(error)}`
156
157
  );
157
158
  }
158
159
  }
@@ -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 IssueType,\n IssueStateEvent,\n} from '../commonGitlabConfig';\nimport { examples } from './gitlabIssueEdit.examples';\nimport { z } from 'zod';\nimport { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';\nimport { IssueSchema, EditIssueOptions } from '@gitbeaker/rest';\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 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\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 response = (await api.Issues.edit(\n projectId,\n issueIid,\n editIssueOptions,\n )) as IssueSchema;\n\n ctx.output('issueId', response.id);\n ctx.output('projectId', response.project_id);\n ctx.output('issueUrl', response.web_url);\n ctx.output('issueIid', response.iid);\n ctx.output('title', response.title);\n ctx.output('state', response.state);\n ctx.output('updatedAt', response.updated_at);\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: ${error.message}`,\n );\n }\n },\n });\n};\n"],"names":["z","IssueType","IssueStateEvent","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","checkEpicScope","convertDate","InputError"],"mappings":";;;;;;;;;AA4BA,MAAM,wBAAA,GAA2BA,MAAE,MAAO,CAAA;AAAA,EACxC,SAAA,EAAWA,KACR,CAAA,MAAA,EACA,CAAA,QAAA;AAAA,IACC;AAAA,GACF;AAAA,EACF,QAAU,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,sCAAsC,CAAA;AAAA,EACpE,SAAA,EAAWA,MACR,MAAO,CAAA;AAAA,IACN,WACE,EAAA;AAAA,GACH,EACA,QAAS,EAAA;AAAA,EACZ,SAAW,EAAAA,KAAA,CACR,KAAM,CAAAA,KAAA,CAAE,QAAU,EAAA;AAAA,IACjB,WAAa,EAAA;AAAA,GACd,EACA,QAAS,EAAA;AAAA,EACZ,YAAA,EAAcA,MACX,OAAQ,CAAA,EAAE,aAAa,sCAAuC,EAAC,EAC/D,QAAS,EAAA;AAAA,EACZ,WAAA,EAAaA,KACV,CAAA,MAAA,EACA,CAAA,QAAA,CAAS,+DAA+D,CACxE,CAAA,GAAA,CAAI,OAAO,CAAA,CACX,QAAS,EAAA;AAAA,EACZ,gBAAA,EAAkBA,MACf,OAAQ,CAAA;AAAA,IACP,WACE,EAAA;AAAA,GACH,EACA,QAAS,EAAA;AAAA,EACZ,OAAA,EAASA,KACN,CAAA,MAAA,EACA,CAAA,QAAA;AAAA,IACC;AAAA,GAED,CAAA,KAAA,CAAM,qBAAuB,EAAA,qCAAqC,EAClE,QAAS,EAAA;AAAA,EACZ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A,CAAO,WAAa,EAAA,QAAA,CAAS,UAAU,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,QAAA,CAAS,OAAO,CAAA;AACvC,QAAI,GAAA,CAAA,MAAA,CAAO,UAAY,EAAA,QAAA,CAAS,GAAG,CAAA;AACnC,QAAI,GAAA,CAAA,MAAA,CAAO,OAAS,EAAA,QAAA,CAAS,KAAK,CAAA;AAClC,QAAI,GAAA,CAAA,MAAA,CAAO,OAAS,EAAA,QAAA,CAAS,KAAK,CAAA;AAClC,QAAI,GAAA,CAAA,MAAA,CAAO,WAAa,EAAA,QAAA,CAAS,UAAU,CAAA;AAAA,eACpC,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,EAAuC,MAAM,OAAO,CAAA;AAAA,SACtD;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 commonGitlabConfig, {\n IssueType,\n IssueStateEvent,\n} from '../commonGitlabConfig';\nimport { examples } from './gitlabIssueEdit.examples';\nimport { z } from 'zod';\nimport { checkEpicScope, convertDate, getClient, parseRepoUrl } from '../util';\nimport { IssueSchema, EditIssueOptions } 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 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\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 response = (await api.Issues.edit(\n projectId,\n issueIid,\n editIssueOptions,\n )) as IssueSchema;\n\n ctx.output('issueId', response.id);\n ctx.output('projectId', response.project_id);\n ctx.output('issueUrl', response.web_url);\n ctx.output('issueIid', response.iid);\n ctx.output('title', response.title);\n ctx.output('state', response.state);\n ctx.output('updatedAt', response.updated_at);\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,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,sCAAsC,CAAA;AAAA,EACpE,SAAA,EAAWA,MACR,MAAO,CAAA;AAAA,IACN,WACE,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,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;;;;"}
@@ -166,7 +166,9 @@ which uses additional API calls in order to detect whether to 'create', 'update'
166
166
  assigneeId = assigneeUser[0].id;
167
167
  } catch (e) {
168
168
  ctx.logger.warn(
169
- `Failed to find gitlab user id for ${assignee}: ${e}. Proceeding with MR creation without an assignee.`
169
+ `Failed to find gitlab user id for ${assignee}: ${helpers.getErrorMessage(
170
+ e
171
+ )}. Proceeding with MR creation without an assignee.`
170
172
  );
171
173
  }
172
174
  }
@@ -197,7 +199,9 @@ which uses additional API calls in order to detect whether to 'create', 'update'
197
199
  });
198
200
  } catch (e) {
199
201
  ctx.logger.warn(
200
- `Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${e}`
202
+ `Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${helpers.getErrorMessage(
203
+ e
204
+ )}`
201
205
  );
202
206
  }
203
207
  }
@@ -239,7 +243,9 @@ which uses additional API calls in order to detect whether to 'create', 'update'
239
243
  await api.Branches.create(repoID, branchName, String(targetBranch));
240
244
  } catch (e) {
241
245
  throw new errors.InputError(
242
- `The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${e}`
246
+ `The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${helpers.getErrorMessage(
247
+ e
248
+ )}`
243
249
  );
244
250
  }
245
251
  }
@@ -248,7 +254,9 @@ which uses additional API calls in order to detect whether to 'create', 'update'
248
254
  await api.Commits.create(repoID, branchName, title, actions);
249
255
  } catch (e) {
250
256
  throw new errors.InputError(
251
- `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${e}`
257
+ `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${helpers.getErrorMessage(
258
+ e
259
+ )}`
252
260
  );
253
261
  }
254
262
  }
@@ -271,7 +279,9 @@ which uses additional API calls in order to detect whether to 'create', 'update'
271
279
  ctx.output("projectPath", repoID);
272
280
  ctx.output("mergeRequestUrl", mergeRequestUrl);
273
281
  } catch (e) {
274
- throw new errors.InputError(`Merge request creation failed${e}`);
282
+ throw new errors.InputError(
283
+ `Merge request creation failed. ${helpers.getErrorMessage(e)}`
284
+ );
275
285
  }
276
286
  }
277
287
  });
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabMergeRequest.cjs.js","sources":["../../src/actions/gitlabMergeRequest.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 {\n createTemplateAction,\n parseRepoUrl,\n SerializedFile,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Gitlab, Types } from '@gitbeaker/core';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport {\n LoggerService,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabMergeRequest.examples';\nimport { createHash } from 'crypto';\n\nfunction computeSha256(file: SerializedFile): string {\n const hash = createHash('sha256');\n hash.update(file.content);\n return hash.digest('hex');\n}\n\nasync function getFileAction(\n fileInfo: { file: SerializedFile; targetPath?: string },\n target: { repoID: string; branch: string },\n api: Gitlab,\n logger: LoggerService,\n remoteFiles: Types.RepositoryTreeSchema[],\n defaultCommitAction:\n | 'create'\n | 'delete'\n | 'update'\n | 'skip'\n | 'auto' = 'auto',\n): Promise<'create' | 'delete' | 'update' | 'skip'> {\n if (defaultCommitAction === 'auto') {\n const filePath = path.join(fileInfo.targetPath ?? '', fileInfo.file.path);\n\n if (remoteFiles?.some(remoteFile => remoteFile.path === filePath)) {\n try {\n const targetFile = await api.RepositoryFiles.show(\n target.repoID,\n filePath,\n target.branch,\n );\n if (computeSha256(fileInfo.file) === targetFile.content_sha256) {\n return 'skip';\n }\n } catch (error) {\n logger.warn(\n `Unable to retrieve detailed information for remote file ${filePath}`,\n );\n }\n return 'update';\n }\n return 'create';\n }\n return defaultCommitAction;\n}\n\n/**\n * Create a new action that creates a gitlab merge request.\n *\n * @public\n */\nexport const createPublishGitlabMergeRequestAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n title: string;\n description: string;\n branchName: string;\n targetBranchName?: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update' | 'skip' | 'auto';\n /** @deprecated projectID passed as query parameters in the repoUrl */\n projectid?: string;\n removeSourceBranch?: boolean;\n assignee?: string;\n }>({\n id: 'publish:gitlab:merge-request',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository Location',\n description: `\\\nAccepts the format 'gitlab.com?repo=project_name&owner=group_name' where \\\n'project_name' is the repository name and 'group_name' is a group or username`,\n },\n /** @deprecated projectID is passed as query parameters in the repoUrl */\n projectid: {\n type: 'string',\n title: 'projectid',\n description: 'Project ID/Name(slug) of the Gitlab Project',\n },\n title: {\n type: 'string',\n title: 'Merge Request Name',\n description: 'The name for the merge request',\n },\n description: {\n type: 'string',\n title: 'Merge Request Description',\n description: 'The description of the merge request',\n },\n branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The source branch name of the merge request',\n },\n targetBranchName: {\n type: 'string',\n title: 'Target Branch Name',\n description: 'The target branch name of the merge request',\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description: `\\\nSubdirectory of working directory to copy changes from. \\\nFor reasons of backward compatibility, any specified 'targetPath' input will \\\nbe applied in place of an absent/falsy value for this input. \\\nCircumvent this behavior using '.'`,\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete', 'auto'],\n description: `\\\nThe action to be used for git commit. Defaults to the custom 'auto' action provided by backstage,\nwhich uses additional API calls in order to detect whether to 'create', 'update' or 'skip' each source file.`,\n },\n removeSourceBranch: {\n title: 'Delete source branch',\n type: 'boolean',\n description:\n 'Option to delete source branch once the MR has been merged. Default: false',\n },\n assignee: {\n title: 'Merge Request Assignee',\n type: 'string',\n description: 'User this merge request will be assigned to',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n targetBranchName: {\n title: 'Target branch name of the merge request',\n type: 'string',\n },\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n mergeRequestUrl: {\n title: 'MergeRequest(MR) URL',\n type: 'string',\n description: 'Link to the merge request in GitLab',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n assignee,\n branchName,\n targetBranchName,\n description,\n repoUrl,\n removeSourceBranch,\n targetPath,\n sourcePath,\n title,\n token,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let assigneeId = undefined;\n\n if (assignee !== undefined) {\n try {\n const assigneeUser = await api.Users.username(assignee);\n assigneeId = assigneeUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${assignee}: ${e}. Proceeding with MR creation without an assignee.`,\n );\n }\n }\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else if (targetPath) {\n // for backward compatibility\n fileRoot = resolveSafeChildPath(ctx.workspacePath, targetPath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n let targetBranch = targetBranchName;\n if (!targetBranch) {\n const projects = await api.Projects.show(repoID);\n\n const { default_branch: defaultBranch } = projects;\n targetBranch = defaultBranch!;\n }\n\n let remoteFiles: Types.RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.tree(repoID, {\n ref: targetBranch,\n recursive: true,\n path: targetPath ?? undefined,\n });\n } catch (e) {\n ctx.logger.warn(\n `Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${e}`,\n );\n }\n }\n const actions: Types.CommitAction[] =\n ctx.input.commitAction === 'skip'\n ? []\n : (\n (\n await Promise.all(\n fileContents.map(async file => {\n const action = await getFileAction(\n { file, targetPath },\n { repoID, branch: targetBranch! },\n api,\n ctx.logger,\n remoteFiles,\n ctx.input.commitAction,\n );\n return { file, action };\n }),\n )\n ).filter(o => o.action !== 'skip') as {\n file: SerializedFile;\n action: Types.CommitAction['action'];\n }[]\n ).map(({ file, action }) => ({\n action,\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n let createBranch: boolean;\n if (actions.length) {\n createBranch = true;\n } else {\n try {\n await api.Branches.show(repoID, branchName);\n createBranch = false;\n ctx.logger.info(\n `Using existing branch ${branchName} without modification.`,\n );\n } catch (e) {\n createBranch = true;\n }\n }\n if (createBranch) {\n try {\n await api.Branches.create(repoID, branchName, String(targetBranch));\n } catch (e) {\n throw new InputError(\n `The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${e}`,\n );\n }\n }\n if (actions.length) {\n try {\n await api.Commits.create(repoID, branchName, title, actions);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${e}`,\n );\n }\n }\n try {\n const mergeRequestUrl = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,\n assigneeId,\n },\n ).then((mergeRequest: { web_url: string }) => {\n return mergeRequest.web_url;\n });\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output('mergeRequestUrl', mergeRequestUrl);\n } catch (e) {\n throw new InputError(`Merge request creation failed${e}`);\n }\n },\n });\n};\n"],"names":["createHash","path","createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","InputError"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAS,cAAc,IAA8B,EAAA;AACnD,EAAM,MAAA,IAAA,GAAOA,kBAAW,QAAQ,CAAA;AAChC,EAAK,IAAA,CAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACxB,EAAO,OAAA,IAAA,CAAK,OAAO,KAAK,CAAA;AAC1B;AAEA,eAAe,cACb,QACA,EAAA,MAAA,EACA,KACA,MACA,EAAA,WAAA,EACA,sBAKa,MACqC,EAAA;AAClD,EAAA,IAAI,wBAAwB,MAAQ,EAAA;AAClC,IAAM,MAAA,QAAA,GAAWC,sBAAK,IAAK,CAAA,QAAA,CAAS,cAAc,EAAI,EAAA,QAAA,CAAS,KAAK,IAAI,CAAA;AAExE,IAAA,IAAI,aAAa,IAAK,CAAA,CAAA,UAAA,KAAc,UAAW,CAAA,IAAA,KAAS,QAAQ,CAAG,EAAA;AACjE,MAAI,IAAA;AACF,QAAM,MAAA,UAAA,GAAa,MAAM,GAAA,CAAI,eAAgB,CAAA,IAAA;AAAA,UAC3C,MAAO,CAAA,MAAA;AAAA,UACP,QAAA;AAAA,UACA,MAAO,CA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["../../src/actions/gitlabMergeRequest.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 {\n createTemplateAction,\n parseRepoUrl,\n SerializedFile,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Gitlab, Types } from '@gitbeaker/core';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport {\n LoggerService,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabMergeRequest.examples';\nimport { createHash } from 'crypto';\n\nfunction computeSha256(file: SerializedFile): string {\n const hash = createHash('sha256');\n hash.update(file.content);\n return hash.digest('hex');\n}\n\nasync function getFileAction(\n fileInfo: { file: SerializedFile; targetPath?: string },\n target: { repoID: string; branch: string },\n api: Gitlab,\n logger: LoggerService,\n remoteFiles: Types.RepositoryTreeSchema[],\n defaultCommitAction:\n | 'create'\n | 'delete'\n | 'update'\n | 'skip'\n | 'auto' = 'auto',\n): Promise<'create' | 'delete' | 'update' | 'skip'> {\n if (defaultCommitAction === 'auto') {\n const filePath = path.join(fileInfo.targetPath ?? '', fileInfo.file.path);\n\n if (remoteFiles?.some(remoteFile => remoteFile.path === filePath)) {\n try {\n const targetFile = await api.RepositoryFiles.show(\n target.repoID,\n filePath,\n target.branch,\n );\n if (computeSha256(fileInfo.file) === targetFile.content_sha256) {\n return 'skip';\n }\n } catch (error) {\n logger.warn(\n `Unable to retrieve detailed information for remote file ${filePath}`,\n );\n }\n return 'update';\n }\n return 'create';\n }\n return defaultCommitAction;\n}\n\n/**\n * Create a new action that creates a gitlab merge request.\n *\n * @public\n */\nexport const createPublishGitlabMergeRequestAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n title: string;\n description: string;\n branchName: string;\n targetBranchName?: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update' | 'skip' | 'auto';\n /** @deprecated projectID passed as query parameters in the repoUrl */\n projectid?: string;\n removeSourceBranch?: boolean;\n assignee?: string;\n }>({\n id: 'publish:gitlab:merge-request',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository Location',\n description: `\\\nAccepts the format 'gitlab.com?repo=project_name&owner=group_name' where \\\n'project_name' is the repository name and 'group_name' is a group or username`,\n },\n /** @deprecated projectID is passed as query parameters in the repoUrl */\n projectid: {\n type: 'string',\n title: 'projectid',\n description: 'Project ID/Name(slug) of the Gitlab Project',\n },\n title: {\n type: 'string',\n title: 'Merge Request Name',\n description: 'The name for the merge request',\n },\n description: {\n type: 'string',\n title: 'Merge Request Description',\n description: 'The description of the merge request',\n },\n branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The source branch name of the merge request',\n },\n targetBranchName: {\n type: 'string',\n title: 'Target Branch Name',\n description: 'The target branch name of the merge request',\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description: `\\\nSubdirectory of working directory to copy changes from. \\\nFor reasons of backward compatibility, any specified 'targetPath' input will \\\nbe applied in place of an absent/falsy value for this input. \\\nCircumvent this behavior using '.'`,\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete', 'auto'],\n description: `\\\nThe action to be used for git commit. Defaults to the custom 'auto' action provided by backstage,\nwhich uses additional API calls in order to detect whether to 'create', 'update' or 'skip' each source file.`,\n },\n removeSourceBranch: {\n title: 'Delete source branch',\n type: 'boolean',\n description:\n 'Option to delete source branch once the MR has been merged. Default: false',\n },\n assignee: {\n title: 'Merge Request Assignee',\n type: 'string',\n description: 'User this merge request will be assigned to',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n targetBranchName: {\n title: 'Target branch name of the merge request',\n type: 'string',\n },\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n mergeRequestUrl: {\n title: 'MergeRequest(MR) URL',\n type: 'string',\n description: 'Link to the merge request in GitLab',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n assignee,\n branchName,\n targetBranchName,\n description,\n repoUrl,\n removeSourceBranch,\n targetPath,\n sourcePath,\n title,\n token,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let assigneeId = undefined;\n\n if (assignee !== undefined) {\n try {\n const assigneeUser = await api.Users.username(assignee);\n assigneeId = assigneeUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${assignee}: ${getErrorMessage(\n e,\n )}. Proceeding with MR creation without an assignee.`,\n );\n }\n }\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else if (targetPath) {\n // for backward compatibility\n fileRoot = resolveSafeChildPath(ctx.workspacePath, targetPath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n let targetBranch = targetBranchName;\n if (!targetBranch) {\n const projects = await api.Projects.show(repoID);\n\n const { default_branch: defaultBranch } = projects;\n targetBranch = defaultBranch!;\n }\n\n let remoteFiles: Types.RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.tree(repoID, {\n ref: targetBranch,\n recursive: true,\n path: targetPath ?? undefined,\n });\n } catch (e) {\n ctx.logger.warn(\n `Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n const actions: Types.CommitAction[] =\n ctx.input.commitAction === 'skip'\n ? []\n : (\n (\n await Promise.all(\n fileContents.map(async file => {\n const action = await getFileAction(\n { file, targetPath },\n { repoID, branch: targetBranch! },\n api,\n ctx.logger,\n remoteFiles,\n ctx.input.commitAction,\n );\n return { file, action };\n }),\n )\n ).filter(o => o.action !== 'skip') as {\n file: SerializedFile;\n action: Types.CommitAction['action'];\n }[]\n ).map(({ file, action }) => ({\n action,\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n let createBranch: boolean;\n if (actions.length) {\n createBranch = true;\n } else {\n try {\n await api.Branches.show(repoID, branchName);\n createBranch = false;\n ctx.logger.info(\n `Using existing branch ${branchName} without modification.`,\n );\n } catch (e) {\n createBranch = true;\n }\n }\n if (createBranch) {\n try {\n await api.Branches.create(repoID, branchName, String(targetBranch));\n } catch (e) {\n throw new InputError(\n `The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n if (actions.length) {\n try {\n await api.Commits.create(repoID, branchName, title, actions);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n try {\n const mergeRequestUrl = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,\n assigneeId,\n },\n ).then((mergeRequest: { web_url: string }) => {\n return mergeRequest.web_url;\n });\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output('mergeRequestUrl', mergeRequestUrl);\n } catch (e) {\n throw new InputError(\n `Merge request creation failed. ${getErrorMessage(e)}`,\n );\n }\n },\n });\n};\n"],"names":["createHash","path","createTemplateAction","examples","parseRepoUrl","createGitlabApi","getErrorMessage","resolveSafeChildPath","serializeDirectoryContents","InputError"],"mappings":";;;;;;;;;;;;;;AAkCA,SAAS,cAAc,IAA8B,EAAA;AACnD,EAAM,MAAA,IAAA,GAAOA,kBAAW,QAAQ,CAAA;AAChC,EAAK,IAAA,CAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACxB,EAAO,OAAA,IAAA,CAAK,OAAO,KAAK,CAAA;AAC1B;AAEA,eAAe,cACb,QACA,EAAA,MAAA,EACA,KACA,MACA,EAAA,WAAA,EACA,sBAKa,MACqC,EAAA;AAClD,EAAA,IAAI,wBAAwB,MAAQ,EAAA;AAClC,IAAM,MAAA,QAAA,GAAWC,sBAAK,IAAK,CAAA,QAAA,CAAS,cAAc,EAAI,EAAA,QAAA,CAAS,KAAK,IAAI,CAAA;AAExE,IAAA,IAAI,aAAa,IAAK,CAAA,CAAA,UAAA,KAAc,UAAW,CAAA,IAAA,KAAS,QAAQ,CAAG,EAAA;AACjE,MAAI,IAAA;AACF,QAAM,MAAA,UAAA,GAAa,MAAM,GAAA,CAAI,eAAgB,CAAA,IAAA;AAAA,UAC3C,MAAO,CAAA,MAAA;AAAA,UACP,QAAA;AAAA,UACA,MAAO,CAAA;AAAA,SACT;AACA,QAAA,IAAI,aAAc,CAAA,QAAA,CAAS,IAAI,CAAA,KAAM,WAAW,cAAgB,EAAA;AAC9D,UAAO,OAAA,MAAA;AAAA;AACT,eACO,KAAO,EAAA;AACd,QAAO,MAAA,CAAA,IAAA;AAAA,UACL,2DAA2D,QAAQ,CAAA;AAAA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CAAA;AAAA,WACH;AAAA;AACF;AAEF,MAAA,IAAI,QAAQ,MAAQ,EAAA;AAClB,QAAI,IAAA;AACF,UAAA,MAAM,IAAI,OAAQ,CAAA,MAAA,CAAO,MAAQ,EAAA,UAAA,EAAY,OAAO,OAAO,CAAA;AAAA,iBACpD,CAAG,EAAA;AACV,UAAA,MAAM,IAAIG,iBAAA;AAAA,YACR,CAAA,0BAAA,EAA6B,UAAU,CAAwF,qFAAA,EAAAH,uBAAA;AAAA,cAC7H;AAAA,aACD,CAAA;AAAA,WACH;AAAA;AACF;AAEF,MAAI,IAAA;AACF,QAAM,MAAA,eAAA,GAAkB,MAAM,GAAA,CAAI,aAAc,CAAA,MAAA;AAAA,UAC9C,MAAA;AAAA,UACA,UAAA;AAAA,UACA,OAAO,YAAY,CAAA;AAAA,UACnB,KAAA;AAAA,UACA;AAAA,YACE,WAAA;AAAA,YACA,kBAAA,EAAoB,qBAAqB,kBAAqB,GAAA,KAAA;AAAA,YAC9D;AAAA;AACF,SACF,CAAE,IAAK,CAAA,CAAC,YAAsC,KAAA;AAC5C,UAAA,OAAO,YAAa,CAAA,OAAA;AAAA,SACrB,CAAA;AACD,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAI,GAAA,CAAA,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAAA,eACtC,CAAG,EAAA;AACV,QAAA,MAAM,IAAIG,iBAAA;AAAA,UACR,CAAA,+BAAA,EAAkCH,uBAAgB,CAAA,CAAC,CAAC,CAAA;AAAA,SACtD;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -6,6 +6,7 @@ var zod = require('zod');
6
6
  var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
7
7
  var util = require('../util.cjs.js');
8
8
  var gitlabPipelineTrigger_examples = require('./gitlabPipelineTrigger.examples.cjs.js');
9
+ var helpers = require('./helpers.cjs.js');
9
10
 
10
11
  const pipelineInputProperties = zod.z.object({
11
12
  projectId: zod.z.number().describe("Project Id"),
@@ -63,7 +64,9 @@ const createTriggerGitlabPipelineAction = (options) => {
63
64
  validationErrors: error.errors
64
65
  });
65
66
  }
66
- throw new errors.InputError(`Failed to trigger Pipeline: ${error.message}`);
67
+ throw new errors.InputError(
68
+ `Failed to trigger Pipeline: ${helpers.getErrorMessage(error)}`
69
+ );
67
70
  } finally {
68
71
  if (pipelineTokenResponse && pipelineTokenResponse.id) {
69
72
  try {
@@ -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';\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 pipelineTokenResponse: PipelineTriggerTokenSchema | null = null;\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 // Create a pipeline token\n pipelineTokenResponse = (await api.PipelineTriggerTokens.create(\n projectId,\n tokenDescription,\n )) as PipelineTriggerTokenSchema;\n\n if (!pipelineTokenResponse.token) {\n ctx.logger.error('Failed to create pipeline token.');\n return;\n }\n ctx.logger.info(\n `Pipeline token id ${pipelineTokenResponse.id} created.`,\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 pipelineTokenResponse.token,\n { variables },\n )) as ExpandedPipelineSchema;\n\n if (!pipelineTriggerResponse.id) {\n ctx.logger.error('Failed to trigger pipeline.');\n return;\n }\n\n ctx.logger.info(`Pipeline id ${pipelineTriggerResponse.id} triggered.`);\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(`Failed to trigger Pipeline: ${error.message}`);\n } finally {\n // Delete the pipeline token if it was created\n if (pipelineTokenResponse && pipelineTokenResponse.id) {\n try {\n await api.PipelineTriggerTokens.remove(\n projectId,\n pipelineTokenResponse.id,\n );\n ctx.logger.info(\n `Deleted pipeline token ${pipelineTokenResponse.id}.`,\n );\n } catch (error: any) {\n ctx.logger.error(\n `Failed to delete pipeline token id ${pipelineTokenResponse.id}.`,\n );\n }\n }\n }\n },\n });\n};\n"],"names":["z","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","InputError"],"mappings":";;;;;;;;;AA4BA,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;AAAA,KACV;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AACjB,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,IAAA,KAAA,YAAiBL,MAAE,QAAU,EAAA;AAE/B,UAAA,MAAM,IAAIM,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,CAAW,CAA+B,4BAAA,EAAA,KAAA,CAAM,OAAO,CAAE,CAAA,CAAA;AAAA,OACnE,SAAA;AAEA,QAAI,IAAA,qBAAA,IAAyB,sBAAsB,EAAI,EAAA;AACrD,UAAI,IAAA;AACF,YAAA,MAAM,IAAI,qBAAsB,CAAA,MAAA;AAAA,cAC9B,SAAA;AAAA,cACA,qBAAsB,CAAA;AAAA,aACxB;AACA,YAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,cACT,CAAA,uBAAA,EAA0B,sBAAsB,EAAE,CAAA,CAAA;AAAA,aACpD;AAAA,mBACO,KAAY,EAAA;AACnB,YAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,cACT,CAAA,mCAAA,EAAsC,sBAAsB,EAAE,CAAA,CAAA;AAAA,aAChE;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 { 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 pipelineTokenResponse: PipelineTriggerTokenSchema | null = null;\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 // Create a pipeline token\n pipelineTokenResponse = (await api.PipelineTriggerTokens.create(\n projectId,\n tokenDescription,\n )) as PipelineTriggerTokenSchema;\n\n if (!pipelineTokenResponse.token) {\n ctx.logger.error('Failed to create pipeline token.');\n return;\n }\n ctx.logger.info(\n `Pipeline token id ${pipelineTokenResponse.id} created.`,\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 pipelineTokenResponse.token,\n { variables },\n )) as ExpandedPipelineSchema;\n\n if (!pipelineTriggerResponse.id) {\n ctx.logger.error('Failed to trigger pipeline.');\n return;\n }\n\n ctx.logger.info(`Pipeline id ${pipelineTriggerResponse.id} triggered.`);\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 (pipelineTokenResponse && pipelineTokenResponse.id) {\n try {\n await api.PipelineTriggerTokens.remove(\n projectId,\n pipelineTokenResponse.id,\n );\n ctx.logger.info(\n `Deleted pipeline token ${pipelineTokenResponse.id}.`,\n );\n } catch (error: any) {\n ctx.logger.error(\n `Failed to delete pipeline token id ${pipelineTokenResponse.id}.`,\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,EA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Action = (options) => {
116
116
  } catch (e) {
117
117
  if (e.response?.statusCode !== 404) {
118
118
  throw new errors.InputError(
119
- `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`
119
+ `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${helpers.getErrorMessage(
120
+ e
121
+ )}`
120
122
  );
121
123
  }
122
124
  }
@@ -127,7 +129,9 @@ const createGitlabRepoPushAction = (options) => {
127
129
  await api.Branches.create(repoID, branchName, String(defaultBranch));
128
130
  } catch (e) {
129
131
  throw new errors.InputError(
130
- `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`
132
+ `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${helpers.getErrorMessage(
133
+ e
134
+ )}`
131
135
  );
132
136
  }
133
137
  }
@@ -143,7 +147,9 @@ const createGitlabRepoPushAction = (options) => {
143
147
  ctx.output("commitHash", commit.id);
144
148
  } catch (e) {
145
149
  throw new errors.InputError(
146
- `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${e}`
150
+ `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${helpers.getErrorMessage(
151
+ e
152
+ )}`
147
153
  );
148
154
  }
149
155
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabRepoPush.cjs.js","sources":["../../src/actions/gitlabRepoPush.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 {\n createTemplateAction,\n parseRepoUrl,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Types } from '@gitbeaker/core';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\n\n/**\n * Create a new action that commits into a gitlab repository.\n *\n * @public\n */\nexport const createGitlabRepoPushAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n branchName: string;\n commitMessage: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update';\n }>({\n id: 'gitlab:repo:push',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName', 'commitMessage'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository 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 branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The branch name for the commit',\n },\n commitMessage: {\n type: 'string',\n title: 'Commit Message',\n description: `The commit message`,\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description:\n 'Subdirectory of working directory to copy changes from',\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete'],\n description:\n 'The action to be used for git commit. Defaults to create.',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n commitHash: {\n title: 'The git commit hash of the commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n branchName,\n repoUrl,\n targetPath,\n sourcePath,\n token,\n commitAction,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n const actions: Types.CommitAction[] = fileContents.map(file => ({\n action: commitAction ?? 'create',\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n let branchExists = false;\n try {\n await api.Branches.show(repoID, branchName);\n branchExists = true;\n } catch (e: any) {\n if (e.response?.statusCode !== 404) {\n throw new InputError(\n `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`,\n );\n }\n }\n\n if (!branchExists) {\n // create a branch using the default branch as ref\n try {\n const projects = await api.Projects.show(repoID);\n const { default_branch: defaultBranch } = projects;\n await api.Branches.create(repoID, branchName, String(defaultBranch));\n } catch (e) {\n throw new InputError(\n `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`,\n );\n }\n }\n\n try {\n const commit = await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n );\n ctx.output('projectid', repoID);\n ctx.output('projectPath', repoID);\n ctx.output('commitHash', commit.id);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${e}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","path","InputError"],"mappings":";;;;;;;;;;;;;AAkCa,MAAA,0BAAA,GAA6B,CAAC,OAErC,KAAA;AACJ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AAAA,SACF;AACA,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,MAAA,CAAO,EAAE,CAAA;AAAA,eAC3B,CAAG,EAAA;AACV,QAAA,MAAM,IAAIA,iBAAA;AAAA,UACR,CAAA,0BAAA,EAA6B,UAAU,CAAA,qFAAA,EAAwF,CAAC,CAAA;AAAA,SAClI;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabRepoPush.cjs.js","sources":["../../src/actions/gitlabRepoPush.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 {\n createTemplateAction,\n parseRepoUrl,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { Types } from '@gitbeaker/core';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\n\n/**\n * Create a new action that commits into a gitlab repository.\n *\n * @public\n */\nexport const createGitlabRepoPushAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n branchName: string;\n commitMessage: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update';\n }>({\n id: 'gitlab:repo:push',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName', 'commitMessage'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository 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 branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The branch name for the commit',\n },\n commitMessage: {\n type: 'string',\n title: 'Commit Message',\n description: `The commit message`,\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description:\n 'Subdirectory of working directory to copy changes from',\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete'],\n description:\n 'The action to be used for git commit. Defaults to create.',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n commitHash: {\n title: 'The git commit hash of the commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n branchName,\n repoUrl,\n targetPath,\n sourcePath,\n token,\n commitAction,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n const actions: Types.CommitAction[] = fileContents.map(file => ({\n action: commitAction ?? 'create',\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n let branchExists = false;\n try {\n await api.Branches.show(repoID, branchName);\n branchExists = true;\n } catch (e: any) {\n if (e.response?.statusCode !== 404) {\n throw new InputError(\n `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n if (!branchExists) {\n // create a branch using the default branch as ref\n try {\n const projects = await api.Projects.show(repoID);\n const { default_branch: defaultBranch } = projects;\n await api.Branches.create(repoID, branchName, String(defaultBranch));\n } catch (e) {\n throw new InputError(\n `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n try {\n const commit = await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n );\n ctx.output('projectid', repoID);\n ctx.output('projectPath', repoID);\n ctx.output('commitHash', commit.id);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${getErrorMessage(\n e,\n )}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","path","InputError","getErrorMessage"],"mappings":";;;;;;;;;;;;;AAkCa,MAAA,0BAAA,GAA6B,CAAC,OAErC,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAQJ,CAAA;AAAA,IACD,EAAI,EAAA,kBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAU,EAAA,CAAC,SAAW,EAAA,YAAA,EAAc,eAAe,CAAA;AAAA,QACnD,IAAM,EAAA,QAAA;AAAA,QACN,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,qBAAA;AAAA,YACP,WAAa,EA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;AAAA,SACH;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -23,6 +23,14 @@ function createGitlabApi(options) {
23
23
  [tokenType]: token
24
24
  });
25
25
  }
26
+ function isGitlabError(e) {
27
+ return errors.isError(e) && "description" in e && typeof e.description === "string";
28
+ }
29
+ function getErrorMessage(e) {
30
+ if (isGitlabError(e)) return `${e} - ${e.description}`;
31
+ return String(e);
32
+ }
26
33
 
27
34
  exports.createGitlabApi = createGitlabApi;
35
+ exports.getErrorMessage = getErrorMessage;
28
36
  //# sourceMappingURL=helpers.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.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 */\nimport { parseRepoUrl } from '@backstage/plugin-scaffolder-node';\nimport { InputError } from '@backstage/errors';\nimport { Gitlab } from '@gitbeaker/node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Resources } from '@gitbeaker/core';\n\nexport function createGitlabApi(options: {\n integrations: ScmIntegrationRegistry;\n token?: string;\n repoUrl: string;\n}): Resources.Gitlab {\n const { integrations, token: providedToken, repoUrl } = options;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!integrationConfig.config.token && !providedToken) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = providedToken ?? integrationConfig.config.token!;\n const tokenType = providedToken ? 'oauthToken' : 'token';\n\n return new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n}\n"],"names":["parseRepoUrl","InputError","Gitlab"],"mappings":";;;;;;AAqBO,SAAS,gBAAgB,OAIX,EAAA;AACnB,EAAA,MAAM,EAAE,YAAA,EAAc,KAAO,EAAA,aAAA,EAAe,SAAY,GAAA,OAAA;AAExD,EAAA,MAAM,EAAE,IAAA,EAAS,GAAAA,iCAAA,CAAa,SAAS,YAAY,CAAA;AAEnD,EAAA,MAAM,iBAAoB,GAAA,YAAA,CAAa,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AAEzD,EAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,IAAA,MAAM,IAAIC,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA;AAGF,EAAA,IAAI,CAAC,iBAAA,CAAkB,MAAO,CAAA,KAAA,IAAS,CAAC,aAAe,EAAA;AACrD,IAAA,MAAM,IAAIA,iBAAA,CAAW,CAA+B,4BAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA;AAG5D,EAAM,MAAA,KAAA,GAAQ,aAAiB,IAAA,iBAAA,CAAkB,MAAO,CAAA,KAAA;AACxD,EAAM,MAAA,SAAA,GAAY,gBAAgB,YAAe,GAAA,OAAA;AAEjD,EAAA,OAAO,IAAIC,WAAO,CAAA;AAAA,IAChB,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,IAC/B,CAAC,SAAS,GAAG;AAAA,GACd,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.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 */\nimport { parseRepoUrl } from '@backstage/plugin-scaffolder-node';\nimport { ErrorLike, InputError, isError } from '@backstage/errors';\nimport { Gitlab } from '@gitbeaker/node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Resources } from '@gitbeaker/core';\n\nexport function createGitlabApi(options: {\n integrations: ScmIntegrationRegistry;\n token?: string;\n repoUrl: string;\n}): Resources.Gitlab {\n const { integrations, token: providedToken, repoUrl } = options;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!integrationConfig.config.token && !providedToken) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = providedToken ?? integrationConfig.config.token!;\n const tokenType = providedToken ? 'oauthToken' : 'token';\n\n return new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n}\n\ninterface GitlabError extends ErrorLike {\n // Errors from Gitlab may also include a description field that contains additional info\n description: string;\n}\n\nfunction isGitlabError(e: unknown): e is GitlabError {\n return isError(e) && 'description' in e && typeof e.description === 'string';\n}\n\nexport function getErrorMessage(e: unknown): string {\n if (isGitlabError(e)) return `${e} - ${e.description}`;\n return String(e);\n}\n"],"names":["parseRepoUrl","InputError","Gitlab","isError"],"mappings":";;;;;;AAqBO,SAAS,gBAAgB,OAIX,EAAA;AACnB,EAAA,MAAM,EAAE,YAAA,EAAc,KAAO,EAAA,aAAA,EAAe,SAAY,GAAA,OAAA;AAExD,EAAA,MAAM,EAAE,IAAA,EAAS,GAAAA,iCAAA,CAAa,SAAS,YAAY,CAAA;AAEnD,EAAA,MAAM,iBAAoB,GAAA,YAAA,CAAa,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AAEzD,EAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,IAAA,MAAM,IAAIC,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA;AAGF,EAAA,IAAI,CAAC,iBAAA,CAAkB,MAAO,CAAA,KAAA,IAAS,CAAC,aAAe,EAAA;AACrD,IAAA,MAAM,IAAIA,iBAAA,CAAW,CAA+B,4BAAA,EAAA,IAAI,CAAE,CAAA,CAAA;AAAA;AAG5D,EAAM,MAAA,KAAA,GAAQ,aAAiB,IAAA,iBAAA,CAAkB,MAAO,CAAA,KAAA;AACxD,EAAM,MAAA,SAAA,GAAY,gBAAgB,YAAe,GAAA,OAAA;AAEjD,EAAA,OAAO,IAAIC,WAAO,CAAA;AAAA,IAChB,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,IAC/B,CAAC,SAAS,GAAG;AAAA,GACd,CAAA;AACH;AAOA,SAAS,cAAc,CAA8B,EAAA;AACnD,EAAA,OAAOC,eAAQ,CAAC,CAAA,IAAK,iBAAiB,CAAK,IAAA,OAAO,EAAE,WAAgB,KAAA,QAAA;AACtE;AAEO,SAAS,gBAAgB,CAAoB,EAAA;AAClD,EAAI,IAAA,aAAA,CAAc,CAAC,CAAG,EAAA,OAAO,GAAG,CAAC,CAAA,GAAA,EAAM,EAAE,WAAW,CAAA,CAAA;AACpD,EAAA,OAAO,OAAO,CAAC,CAAA;AACjB;;;;;"}
package/dist/util.cjs.js CHANGED
@@ -76,10 +76,7 @@ async function getTopLevelParentGroup(client, groupId) {
76
76
  try {
77
77
  const topParentGroup = await client.Groups.show(groupId);
78
78
  if (topParentGroup.parent_id) {
79
- return getTopLevelParentGroup(
80
- client,
81
- topParentGroup.parent_id
82
- );
79
+ return getTopLevelParentGroup(client, topParentGroup.parent_id);
83
80
  }
84
81
  return topParentGroup;
85
82
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"util.cjs.js","sources":["../src/util.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 {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Gitlab, GroupSchema } from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from './commonGitlabConfig';\nimport * as util from './util';\n\nexport const parseRepoHost = (repoUrl: string): string => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n return parsed.host;\n};\n\nexport const getToken = (\n config: z.infer<typeof commonGitlabConfig>,\n integrations: ScmIntegrationRegistry,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(config.repoUrl);\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const token = config.token || integrationConfig.config.token!;\n\n return { token: token, integrationConfig: integrationConfig };\n};\n\nexport type RepoSpec = {\n repo: string;\n host: string;\n owner?: string;\n};\n\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): RepoSpec => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const repo: string = parsed.searchParams.get('repo')!;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n return { host, owner, repo };\n};\n\nexport function getClient(props: {\n host: string;\n token?: string;\n integrations: ScmIntegrationRegistry;\n}): InstanceType<typeof Gitlab> {\n const { host, token, integrations } = props;\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const { config } = integrationConfig;\n\n if (!config.token && !token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const requestToken = token || config.token!;\n const tokenType = token ? 'oauthToken' : 'token';\n\n const gitlabOptions: any = {\n host: config.baseUrl,\n };\n\n gitlabOptions[tokenType] = requestToken;\n return new Gitlab(gitlabOptions);\n}\n\nexport function convertDate(\n inputDate: string | undefined,\n defaultDate: string,\n) {\n try {\n return inputDate\n ? new Date(inputDate).toISOString()\n : new Date(defaultDate).toISOString();\n } catch (error) {\n throw new InputError(`Error converting input date - ${error}`);\n }\n}\n\nexport async function getTopLevelParentGroup(\n client: InstanceType<typeof Gitlab>,\n groupId: number,\n): Promise<GroupSchema> {\n try {\n const topParentGroup = await client.Groups.show(groupId);\n if (topParentGroup.parent_id) {\n return util.getTopLevelParentGroup(\n client,\n topParentGroup.parent_id as number,\n );\n }\n return topParentGroup as GroupSchema;\n } catch (error: any) {\n throw new InputError(\n `Error finding top-level parent group ID: ${error.message}`,\n );\n }\n}\n\nexport async function checkEpicScope(\n client: InstanceType<typeof Gitlab>,\n projectId: number,\n epicId: number,\n) {\n try {\n // If project exists, get the top level group id\n const project = await client.Projects.show(projectId);\n if (!project) {\n throw new InputError(\n `Project with id ${projectId} not found. Check your GitLab instance.`,\n );\n }\n const topParentGroup = await getTopLevelParentGroup(\n client,\n project.namespace.id,\n );\n if (!topParentGroup) {\n throw new InputError(`Couldn't find a suitable top-level parent group.`);\n }\n // Get the epic\n const epic = (await client.Epics.all(topParentGroup.id)).find(\n (x: any) => x.id === epicId,\n );\n if (!epic) {\n throw new InputError(\n `Epic with id ${epicId} not found in the top-level parent group ${topParentGroup.name}.`,\n );\n }\n\n const epicGroup = await client.Groups.show(epic.group_id as number);\n const projectNamespace: string = project.path_with_namespace as string;\n return projectNamespace.startsWith(epicGroup.full_path as string);\n } catch (error: any) {\n throw new InputError(`Could not find epic scope: ${error.message}`);\n }\n}\n"],"names":["InputError","Gitlab","util.getTopLevelParentGroup"],"mappings":";;;;;AA0Ba,MAAA,aAAA,GAAgB,CAAC,OAA4B,KAAA;AACxD,EAAI,IAAA,MAAA;AACJ,EAAI,IAAA;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAW,QAAA,EAAA,OAAO,CAAE,CAAA,CAAA;AAAA,WAC9B,KAAO,EAAA;AACd,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK,KAAK,CAAA;AAAA,KAChE;AAAA;AAEF,EAAA,OAAO,MAAO,CAAA,IAAA;AAChB;AAEa,MAAA,QAAA,GAAW,CACtB,MAAA,EACA,YAC4D,KAAA;AAC5D,EAAM,MAAA,IAAA,GAAO,aAAc,CAAA,MAAA,CAAO,OAAO,CAAA;AACzC,EAAA,MAAM,iBAAoB,GAAA,YAAA,CAAa,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AAEzD,EAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA;AAGF,EAAA,MAAM,KAAQ,GAAA,MAAA,CAAO,KAAS,IAAA,iBAAA,CAAkB,MAAO,CAAA,KAAA;AAEvD,EAAO,OAAA,EAAE,OAAc,iBAAqC,EAAA;AAC9D;AAQa,MAAA,YAAA,GAAe,CAC1B,OAAA,EACA,YACa,KAAA;AACb,EAAI,IAAA,MAAA;AACJ,EAAI,IAAA;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAW,QAAA,EAAA,OAAO,CAAE,CAAA,CAAA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BAAA;AAAA,MAC3B,MAAA;AAAA,MACA,QAAQ,SAAU,CAAA;AAAA,KACpB;AACA,IAAA,IAAI,CAAC,cAAgB,EAAA;AACnB,MAAM,MAAA,IAAIA,kBAAW,CAAkD,gDAAA,CAAA,CAAA;AAAA;AAGzE,IAAA,MAAM,QAAQ,MAAM,MAAA,CAAO,MAAM,GAAI,CAAA,cAAA,CAAe,EAAE,CAAG,EAAA,IAAA;AAAA,MACvD,CAAC,CAAW,KAAA,CAAA,CAAE,EAAO,KAAA;AAAA,KACvB;AACA,IAAA,IAAI,CAAC,IAAM,EAAA;AACT,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR,CAAgB,aAAA,EAAA,MAAM,CAA4C,yCAAA,EAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAAA,OACvF;AAAA;AAGF,IAAA,MAAM,YAAY,MAAM,MAAA,CAAO,MAAO,CAAA,IAAA,CAAK,KAAK,QAAkB,CAAA;AAClE,IAAA,MAAM,mBAA2B,OAAQ,CAAA,mBAAA;AACzC,IAAO,OAAA,gBAAA,CAAiB,UAAW,CAAA,SAAA,CAAU,SAAmB,CAAA;AAAA,WACzD,KAAY,EAAA;AACnB,IAAA,MAAM,IAAIA,iBAAA,CAAW,CAA8B,2BAAA,EAAA,KAAA,CAAM,OAAO,CAAE,CAAA,CAAA;AAAA;AAEtE;;;;;;;;;;"}
1
+ {"version":3,"file":"util.cjs.js","sources":["../src/util.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 {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Gitlab, GroupSchema } from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from './commonGitlabConfig';\n\nexport const parseRepoHost = (repoUrl: string): string => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n return parsed.host;\n};\n\nexport const getToken = (\n config: z.infer<typeof commonGitlabConfig>,\n integrations: ScmIntegrationRegistry,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(config.repoUrl);\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const token = config.token || integrationConfig.config.token!;\n\n return { token: token, integrationConfig: integrationConfig };\n};\n\nexport type RepoSpec = {\n repo: string;\n host: string;\n owner?: string;\n};\n\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): RepoSpec => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const repo: string = parsed.searchParams.get('repo')!;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n return { host, owner, repo };\n};\n\nexport function getClient(props: {\n host: string;\n token?: string;\n integrations: ScmIntegrationRegistry;\n}): InstanceType<typeof Gitlab> {\n const { host, token, integrations } = props;\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const { config } = integrationConfig;\n\n if (!config.token && !token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const requestToken = token || config.token!;\n const tokenType = token ? 'oauthToken' : 'token';\n\n const gitlabOptions: any = {\n host: config.baseUrl,\n };\n\n gitlabOptions[tokenType] = requestToken;\n return new Gitlab(gitlabOptions);\n}\n\nexport function convertDate(\n inputDate: string | undefined,\n defaultDate: string,\n) {\n try {\n return inputDate\n ? new Date(inputDate).toISOString()\n : new Date(defaultDate).toISOString();\n } catch (error) {\n throw new InputError(`Error converting input date - ${error}`);\n }\n}\n\nexport async function getTopLevelParentGroup(\n client: InstanceType<typeof Gitlab>,\n groupId: number,\n): Promise<GroupSchema> {\n try {\n const topParentGroup = await client.Groups.show(groupId);\n if (topParentGroup.parent_id) {\n return getTopLevelParentGroup(client, topParentGroup.parent_id as number);\n }\n return topParentGroup as GroupSchema;\n } catch (error: any) {\n throw new InputError(\n `Error finding top-level parent group ID: ${error.message}`,\n );\n }\n}\n\nexport async function checkEpicScope(\n client: InstanceType<typeof Gitlab>,\n projectId: number,\n epicId: number,\n) {\n try {\n // If project exists, get the top level group id\n const project = await client.Projects.show(projectId);\n if (!project) {\n throw new InputError(\n `Project with id ${projectId} not found. Check your GitLab instance.`,\n );\n }\n const topParentGroup = await getTopLevelParentGroup(\n client,\n project.namespace.id,\n );\n if (!topParentGroup) {\n throw new InputError(`Couldn't find a suitable top-level parent group.`);\n }\n // Get the epic\n const epic = (await client.Epics.all(topParentGroup.id)).find(\n (x: any) => x.id === epicId,\n );\n if (!epic) {\n throw new InputError(\n `Epic with id ${epicId} not found in the top-level parent group ${topParentGroup.name}.`,\n );\n }\n\n const epicGroup = await client.Groups.show(epic.group_id as number);\n const projectNamespace: string = project.path_with_namespace as string;\n return projectNamespace.startsWith(epicGroup.full_path as string);\n } catch (error: any) {\n throw new InputError(`Could not find epic scope: ${error.message}`);\n }\n}\n"],"names":["InputError","Gitlab"],"mappings":";;;;;AAyBa,MAAA,aAAA,GAAgB,CAAC,OAA4B,KAAA;AACxD,EAAI,IAAA,MAAA;AACJ,EAAI,IAAA;AACF,IAA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;AACA,IAAA,IAAI,CAAC,IAAM,EAAA;AACT,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR,CAAgB,aAAA,EAAA,MAAM,CAA4C,yCAAA,EAAA,cAAA,CAAe,IAAI,CAAA,CAAA;AAAA,OACvF;AAAA;AAGF,IAAA,MAAM,YAAY,MAAM,MAAA,CAAO,MAAO,CAAA,IAAA,CAAK,KAAK,QAAkB,CAAA;AAClE,IAAA,MAAM,mBAA2B,OAAQ,CAAA,mBAAA;AACzC,IAAO,OAAA,gBAAA,CAAiB,UAAW,CAAA,SAAA,CAAU,SAAmB,CAAA;AAAA,WACzD,KAAY,EAAA;AACnB,IAAA,MAAM,IAAIA,iBAAA,CAAW,CAA8B,2BAAA,EAAA,KAAA,CAAM,OAAO,CAAE,CAAA,CAAA;AAAA;AAEtE;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-gitlab",
3
- "version": "0.6.1-next.3",
3
+ "version": "0.6.2",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "scaffolder",
@@ -51,11 +51,11 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@backstage/backend-common": "^0.25.0",
54
- "@backstage/backend-plugin-api": "1.0.2-next.2",
55
- "@backstage/config": "1.2.0",
56
- "@backstage/errors": "1.2.4",
57
- "@backstage/integration": "1.15.1",
58
- "@backstage/plugin-scaffolder-node": "0.5.1-next.3",
54
+ "@backstage/backend-plugin-api": "^1.0.2",
55
+ "@backstage/config": "^1.3.0",
56
+ "@backstage/errors": "^1.2.5",
57
+ "@backstage/integration": "^1.15.2",
58
+ "@backstage/plugin-scaffolder-node": "^0.6.1",
59
59
  "@gitbeaker/core": "^35.8.0",
60
60
  "@gitbeaker/node": "^35.8.0",
61
61
  "@gitbeaker/rest": "^39.25.0",
@@ -65,9 +65,9 @@
65
65
  "zod": "^3.22.4"
66
66
  },
67
67
  "devDependencies": {
68
- "@backstage/backend-test-utils": "1.1.0-next.3",
69
- "@backstage/cli": "0.29.0-next.3",
70
- "@backstage/core-app-api": "1.15.1",
71
- "@backstage/plugin-scaffolder-node-test-utils": "0.1.15-next.3"
68
+ "@backstage/backend-test-utils": "^1.1.0",
69
+ "@backstage/cli": "^0.29.2",
70
+ "@backstage/core-app-api": "^1.15.2",
71
+ "@backstage/plugin-scaffolder-node-test-utils": "^0.1.16"
72
72
  }
73
73
  }