@backstage/plugin-scaffolder-backend-module-gitlab 0.6.1-next.2 → 0.6.1

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,29 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cdc8b4c: Improve error messages from Gitlab
8
+ - 2dbdccb: Removed circular import
9
+ - Updated dependencies
10
+ - @backstage/config@1.3.0
11
+ - @backstage/backend-plugin-api@1.0.2
12
+ - @backstage/plugin-scaffolder-node@0.6.0
13
+ - @backstage/errors@1.2.5
14
+ - @backstage/integration@1.15.2
15
+
16
+ ## 0.6.1-next.3
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+ - @backstage/backend-plugin-api@1.0.2-next.2
22
+ - @backstage/config@1.2.0
23
+ - @backstage/errors@1.2.4
24
+ - @backstage/integration@1.15.1
25
+ - @backstage/plugin-scaffolder-node@0.5.1-next.3
26
+
3
27
  ## 0.6.1-next.2
4
28
 
5
29
  ### Patch Changes
@@ -120,6 +120,21 @@ function createPublishGitlabAction(options) {
120
120
  description: "The visibility of the project. Can be private, internal, or public. The default value is private.",
121
121
  type: "string",
122
122
  enum: ["private", "public", "internal"]
123
+ },
124
+ only_allow_merge_if_all_discussions_are_resolved: {
125
+ title: "All threads must be resolved",
126
+ description: "Set whether merge requests can only be merged when all the discussions are resolved.",
127
+ type: "boolean"
128
+ },
129
+ only_allow_merge_if_pipeline_succeeds: {
130
+ title: "Pipelines must succeed",
131
+ description: "Set whether merge requests can only be merged with successful pipelines. This setting is named Pipelines must succeed in the project settings.",
132
+ type: "boolean"
133
+ },
134
+ allow_merge_on_skipped_pipeline: {
135
+ title: "Skipped pipelines are considered successful",
136
+ description: "Set whether or not merge requests can be merged with skipped jobs.",
137
+ type: "boolean"
123
138
  }
124
139
  }
125
140
  },
@@ -1 +1 @@
1
- {"version":3,"file":"gitlab.cjs.js","sources":["../../src/actions/gitlab.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { Gitlab } from '@gitbeaker/node';\nimport {\n initRepoAndPush,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport { examples } from './gitlab.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitLab.\n *\n * @public\n */\nexport function createPublishGitlabAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n defaultBranch?: string;\n /** @deprecated in favour of settings.visibility field */\n repoVisibility?: 'private' | 'internal' | 'public';\n sourcePath?: string;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n setUserAsOwner?: boolean;\n /** @deprecated in favour of settings.topics field */\n topics?: string[];\n settings?: {\n path?: string;\n auto_devops_enabled?: boolean;\n ci_config_path?: string;\n description?: string;\n merge_method?: 'merge' | 'rebase_merge' | 'ff';\n squash_option?: 'default_off' | 'default_on' | 'never' | 'always';\n topics?: string[];\n visibility?: 'private' | 'internal' | 'public';\n };\n branches?: Array<{\n name: string;\n protect?: boolean;\n create?: boolean;\n ref?: string;\n }>;\n projectVariables?: Array<{\n key: string;\n value: string;\n description?: string;\n variable_type?: string;\n protected?: boolean;\n masked?: boolean;\n raw?: boolean;\n environment_scope?: string;\n }>;\n }>({\n id: 'publish:gitlab',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to GitLab.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n repoVisibility: {\n title: 'Repository Visibility',\n description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'master'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',\n type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n setUserAsOwner: {\n title: 'Set User As Owner',\n type: 'boolean',\n description:\n 'Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host',\n },\n topics: {\n title: 'Topic labels',\n description:\n 'Topic labels to apply on the repository. (deprecated, use settings.topics instead)',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n settings: {\n title: 'Project settings',\n description:\n 'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes',\n type: 'object',\n properties: {\n path: {\n title: 'Project path',\n description:\n 'Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).',\n type: 'string',\n },\n auto_devops_enabled: {\n title: 'Auto DevOps enabled',\n description: 'Enable Auto DevOps for this project',\n type: 'boolean',\n },\n ci_config_path: {\n title: 'CI config path',\n description: 'Custom CI config path for this project',\n type: 'string',\n },\n description: {\n title: 'Project description',\n description: 'Short project description',\n type: 'string',\n },\n merge_method: {\n title: 'Merge Method to use',\n description: 'Merge Methods (merge, rebase_merge, ff)',\n type: 'string',\n enum: ['merge', 'rebase_merge', 'ff'],\n },\n squash_option: {\n title: 'Squash option',\n description:\n 'Set squash option for the project (never, always, default_on, default_off)',\n type: 'string',\n enum: ['default_off', 'default_on', 'never', 'always'],\n },\n topics: {\n title: 'Topic labels',\n description: 'Topic labels to apply on the repository',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n visibility: {\n title: 'Project visibility',\n description:\n 'The visibility of the project. Can be private, internal, or public. The default value is private.',\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n },\n },\n branches: {\n title: 'Project branches settings',\n type: 'array',\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: {\n title: 'Branch name',\n type: 'string',\n },\n protect: {\n title: 'Should branch be protected',\n description: `Will mark branch as protected. The default value is 'false'`,\n type: 'boolean',\n },\n create: {\n title: 'Should branch be created',\n description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,\n type: 'boolean',\n },\n ref: {\n title: 'Branch reference',\n description: `Branch reference to create branch from. The default value is 'master'`,\n type: 'string',\n },\n },\n },\n },\n projectVariables: {\n title: 'Project variables',\n description:\n 'Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable',\n type: 'array',\n items: {\n type: 'object',\n required: ['key', 'value'],\n properties: {\n key: {\n title: 'Variable key',\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n type: 'string',\n },\n value: {\n title: 'Variable value',\n description: 'The value of a variable',\n type: 'string',\n },\n description: {\n title: 'Variable description',\n description: `The description of the variable. The default value is 'null'`,\n type: 'string',\n },\n variable_type: {\n title: 'Variable type',\n description: `The type of a variable. The default value is 'env_var'`,\n type: 'string',\n enum: ['env_var', 'file'],\n },\n protected: {\n title: 'Variable protection',\n description: `Whether the variable is protected. The default value is 'false'`,\n type: 'boolean',\n },\n raw: {\n title: 'Variable raw',\n description: `Whether the variable is in raw format. The default value is 'false'`,\n type: 'boolean',\n },\n environment_scope: {\n title: 'Variable environment scope',\n description: `The environment_scope of the variable. The default value is '*'`,\n type: 'string',\n },\n },\n },\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n projectId: {\n title: 'The ID of the project',\n type: 'number',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n repoVisibility = 'private',\n defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n setUserAsOwner = false,\n topics = [],\n settings = {},\n branches = [],\n projectVariables = [],\n } = ctx.input;\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\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 && !ctx.input.token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = ctx.input.token || integrationConfig.config.token!;\n const tokenType = ctx.input.token ? 'oauthToken' : 'token';\n\n const client = new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n\n let targetNamespaceId;\n\n try {\n const namespaceResponse = (await client.Namespaces.show(owner)) as {\n id: number;\n };\n\n targetNamespaceId = namespaceResponse.id;\n } catch (e) {\n if (e.response && e.response.statusCode === 404) {\n throw new InputError(\n `The namespace ${owner} is not found or the user doesn't have permissions to access it`,\n );\n }\n throw e;\n }\n\n const { id: userId } = (await client.Users.current()) as {\n id: number;\n };\n\n if (!targetNamespaceId) {\n targetNamespaceId = userId;\n }\n\n const { id: projectId, http_url_to_repo } = await client.Projects.create({\n namespace_id: targetNamespaceId,\n name: repo,\n visibility: repoVisibility,\n ...(topics.length ? { topics } : {}),\n ...(Object.keys(settings).length ? { ...settings } : {}),\n });\n\n // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab\n // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to\n // create the repository, but not to push the default protected branch (e.g. master).\n // In order to set the user as owner of the newly created repository we need to check that the\n // GitLab integration configuration for the matching host contains a token and use\n // such token to bootstrap a new privileged client.\n if (setUserAsOwner && integrationConfig.config.token) {\n const adminClient = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: integrationConfig.config.token,\n });\n\n await adminClient.ProjectMembers.add(projectId, userId, 50);\n }\n\n const remoteUrl = (http_url_to_repo as string).replace(/\\.git$/, '');\n const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl: http_url_to_repo as string,\n defaultBranch,\n auth: {\n username: 'oauth2',\n password: token,\n },\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n });\n\n if (branches) {\n for (const branch of branches) {\n const {\n name,\n protect = false,\n create = false,\n ref = 'master',\n } = branch;\n\n if (create) {\n try {\n await client.Branches.create(projectId, name, ref);\n } catch (e) {\n throw new InputError(\n `Branch creation failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(\n `Branch ${name} created for ${projectId} with ref ${ref}`,\n );\n }\n\n if (protect) {\n try {\n await client.ProtectedBranches.protect(projectId, name);\n } catch (e) {\n throw new InputError(\n `Branch protection failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(`Branch ${name} protected for ${projectId}`);\n }\n }\n }\n\n if (projectVariables) {\n for (const variable of projectVariables) {\n const variableWithDefaults = Object.assign(variable, {\n variable_type: variable.variable_type ?? 'env_var',\n protected: variable.protected ?? false,\n masked: variable.masked ?? false,\n raw: variable.raw ?? false,\n environment_scope: variable.environment_scope ?? '*',\n });\n\n try {\n await client.ProjectVariables.create(\n projectId,\n variableWithDefaults,\n );\n } catch (e) {\n throw new InputError(\n `Environment variable creation failed for ${\n variableWithDefaults.key\n }. ${printGitlabError(e)}`,\n );\n }\n }\n }\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('projectId', projectId);\n },\n });\n}\n\nfunction printGitlabError(error: any): string {\n return JSON.stringify({ code: error.code, message: error.description });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","Gitlab","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AAkCO,SAAS,0BAA0B,OAGvC,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCAuCJ,CAAA;AAAA,IACD,EAAI,EAAA,gBAAA;AAAA,IACJ,WACE,EAAA,2FAAA;AAAA,cACFC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,qBAAA;AAAA,Y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iBAAA,EAAmB,SAAS,iBAAqB,IAAA;AAAA,WAClD,CAAA;AAED,UAAI,IAAA;AACF,YAAA,MAAM,OAAO,gBAAiB,CAAA,MAAA;AAAA,cAC5B,SAAA;AAAA,cACA;AAAA,aACF;AAAA,mBACO,CAAG,EAAA;AACV,YAAA,MAAM,IAAIA,iBAAA;AAAA,cACR,4CACE,oBAAqB,CAAA,GACvB,CAAK,EAAA,EAAA,gBAAA,CAAiB,CAAC,CAAC,CAAA;AAAA,aAC1B;AAAA;AACF;AACF;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,YAAA,EAAc,UAAU,CAAA;AACjD,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AAAA;AACnC,GACD,CAAA;AACH;AAEA,SAAS,iBAAiB,KAAoB,EAAA;AAC5C,EAAO,OAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,MAAM,IAAM,EAAA,OAAA,EAAS,KAAM,CAAA,WAAA,EAAa,CAAA;AACxE;;;;"}
1
+ {"version":3,"file":"gitlab.cjs.js","sources":["../../src/actions/gitlab.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { Gitlab } from '@gitbeaker/node';\nimport {\n initRepoAndPush,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport { examples } from './gitlab.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitLab.\n *\n * @public\n */\nexport function createPublishGitlabAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n defaultBranch?: string;\n /** @deprecated in favour of settings.visibility field */\n repoVisibility?: 'private' | 'internal' | 'public';\n sourcePath?: string;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n setUserAsOwner?: boolean;\n /** @deprecated in favour of settings.topics field */\n topics?: string[];\n settings?: {\n path?: string;\n auto_devops_enabled?: boolean;\n ci_config_path?: string;\n description?: string;\n merge_method?: 'merge' | 'rebase_merge' | 'ff';\n squash_option?: 'default_off' | 'default_on' | 'never' | 'always';\n topics?: string[];\n visibility?: 'private' | 'internal' | 'public';\n only_allow_merge_if_all_discussions_are_resolved?: boolean;\n only_allow_merge_if_pipeline_succeeds?: boolean;\n allow_merge_on_skipped_pipeline?: boolean;\n };\n branches?: Array<{\n name: string;\n protect?: boolean;\n create?: boolean;\n ref?: string;\n }>;\n projectVariables?: Array<{\n key: string;\n value: string;\n description?: string;\n variable_type?: string;\n protected?: boolean;\n masked?: boolean;\n raw?: boolean;\n environment_scope?: string;\n }>;\n }>({\n id: 'publish:gitlab',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to GitLab.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n repoVisibility: {\n title: 'Repository Visibility',\n description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'master'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',\n type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n setUserAsOwner: {\n title: 'Set User As Owner',\n type: 'boolean',\n description:\n 'Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host',\n },\n topics: {\n title: 'Topic labels',\n description:\n 'Topic labels to apply on the repository. (deprecated, use settings.topics instead)',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n settings: {\n title: 'Project settings',\n description:\n 'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes',\n type: 'object',\n properties: {\n path: {\n title: 'Project path',\n description:\n 'Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).',\n type: 'string',\n },\n auto_devops_enabled: {\n title: 'Auto DevOps enabled',\n description: 'Enable Auto DevOps for this project',\n type: 'boolean',\n },\n ci_config_path: {\n title: 'CI config path',\n description: 'Custom CI config path for this project',\n type: 'string',\n },\n description: {\n title: 'Project description',\n description: 'Short project description',\n type: 'string',\n },\n merge_method: {\n title: 'Merge Method to use',\n description: 'Merge Methods (merge, rebase_merge, ff)',\n type: 'string',\n enum: ['merge', 'rebase_merge', 'ff'],\n },\n squash_option: {\n title: 'Squash option',\n description:\n 'Set squash option for the project (never, always, default_on, default_off)',\n type: 'string',\n enum: ['default_off', 'default_on', 'never', 'always'],\n },\n topics: {\n title: 'Topic labels',\n description: 'Topic labels to apply on the repository',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n visibility: {\n title: 'Project visibility',\n description:\n 'The visibility of the project. Can be private, internal, or public. The default value is private.',\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n only_allow_merge_if_all_discussions_are_resolved: {\n title: 'All threads must be resolved',\n description:\n 'Set whether merge requests can only be merged when all the discussions are resolved.',\n type: 'boolean',\n },\n only_allow_merge_if_pipeline_succeeds: {\n title: 'Pipelines must succeed',\n description:\n 'Set whether merge requests can only be merged with successful pipelines. This setting is named Pipelines must succeed in the project settings.',\n type: 'boolean',\n },\n allow_merge_on_skipped_pipeline: {\n title: 'Skipped pipelines are considered successful',\n description:\n 'Set whether or not merge requests can be merged with skipped jobs.',\n type: 'boolean',\n },\n },\n },\n branches: {\n title: 'Project branches settings',\n type: 'array',\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: {\n title: 'Branch name',\n type: 'string',\n },\n protect: {\n title: 'Should branch be protected',\n description: `Will mark branch as protected. The default value is 'false'`,\n type: 'boolean',\n },\n create: {\n title: 'Should branch be created',\n description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,\n type: 'boolean',\n },\n ref: {\n title: 'Branch reference',\n description: `Branch reference to create branch from. The default value is 'master'`,\n type: 'string',\n },\n },\n },\n },\n projectVariables: {\n title: 'Project variables',\n description:\n 'Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable',\n type: 'array',\n items: {\n type: 'object',\n required: ['key', 'value'],\n properties: {\n key: {\n title: 'Variable key',\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n type: 'string',\n },\n value: {\n title: 'Variable value',\n description: 'The value of a variable',\n type: 'string',\n },\n description: {\n title: 'Variable description',\n description: `The description of the variable. The default value is 'null'`,\n type: 'string',\n },\n variable_type: {\n title: 'Variable type',\n description: `The type of a variable. The default value is 'env_var'`,\n type: 'string',\n enum: ['env_var', 'file'],\n },\n protected: {\n title: 'Variable protection',\n description: `Whether the variable is protected. The default value is 'false'`,\n type: 'boolean',\n },\n raw: {\n title: 'Variable raw',\n description: `Whether the variable is in raw format. The default value is 'false'`,\n type: 'boolean',\n },\n environment_scope: {\n title: 'Variable environment scope',\n description: `The environment_scope of the variable. The default value is '*'`,\n type: 'string',\n },\n },\n },\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n projectId: {\n title: 'The ID of the project',\n type: 'number',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n repoVisibility = 'private',\n defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n setUserAsOwner = false,\n topics = [],\n settings = {},\n branches = [],\n projectVariables = [],\n } = ctx.input;\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\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 && !ctx.input.token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = ctx.input.token || integrationConfig.config.token!;\n const tokenType = ctx.input.token ? 'oauthToken' : 'token';\n\n const client = new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n\n let targetNamespaceId;\n\n try {\n const namespaceResponse = (await client.Namespaces.show(owner)) as {\n id: number;\n };\n\n targetNamespaceId = namespaceResponse.id;\n } catch (e) {\n if (e.response && e.response.statusCode === 404) {\n throw new InputError(\n `The namespace ${owner} is not found or the user doesn't have permissions to access it`,\n );\n }\n throw e;\n }\n\n const { id: userId } = (await client.Users.current()) as {\n id: number;\n };\n\n if (!targetNamespaceId) {\n targetNamespaceId = userId;\n }\n\n const { id: projectId, http_url_to_repo } = await client.Projects.create({\n namespace_id: targetNamespaceId,\n name: repo,\n visibility: repoVisibility,\n ...(topics.length ? { topics } : {}),\n ...(Object.keys(settings).length ? { ...settings } : {}),\n });\n\n // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab\n // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to\n // create the repository, but not to push the default protected branch (e.g. master).\n // In order to set the user as owner of the newly created repository we need to check that the\n // GitLab integration configuration for the matching host contains a token and use\n // such token to bootstrap a new privileged client.\n if (setUserAsOwner && integrationConfig.config.token) {\n const adminClient = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: integrationConfig.config.token,\n });\n\n await adminClient.ProjectMembers.add(projectId, userId, 50);\n }\n\n const remoteUrl = (http_url_to_repo as string).replace(/\\.git$/, '');\n const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl: http_url_to_repo as string,\n defaultBranch,\n auth: {\n username: 'oauth2',\n password: token,\n },\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n });\n\n if (branches) {\n for (const branch of branches) {\n const {\n name,\n protect = false,\n create = false,\n ref = 'master',\n } = branch;\n\n if (create) {\n try {\n await client.Branches.create(projectId, name, ref);\n } catch (e) {\n throw new InputError(\n `Branch creation failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(\n `Branch ${name} created for ${projectId} with ref ${ref}`,\n );\n }\n\n if (protect) {\n try {\n await client.ProtectedBranches.protect(projectId, name);\n } catch (e) {\n throw new InputError(\n `Branch protection failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(`Branch ${name} protected for ${projectId}`);\n }\n }\n }\n\n if (projectVariables) {\n for (const variable of projectVariables) {\n const variableWithDefaults = Object.assign(variable, {\n variable_type: variable.variable_type ?? 'env_var',\n protected: variable.protected ?? false,\n masked: variable.masked ?? false,\n raw: variable.raw ?? false,\n environment_scope: variable.environment_scope ?? '*',\n });\n\n try {\n await client.ProjectVariables.create(\n projectId,\n variableWithDefaults,\n );\n } catch (e) {\n throw new InputError(\n `Environment variable creation failed for ${\n variableWithDefaults.key\n }. ${printGitlabError(e)}`,\n );\n }\n }\n }\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('projectId', projectId);\n },\n });\n}\n\nfunction printGitlabError(error: any): string {\n return JSON.stringify({ code: error.code, message: error.description });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","Gitlab","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AAkCO,SAAS,0BAA0B,OAGvC,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCA0CJ,CAAA;AAAA,IACD,EAAI,EAAA,gBAAA;AAAA,IACJ,WACE,EAAA,2FAAA;AAAA,cACFC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,qBAAA;AAAA,YACP,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA,CAAA,sJAAA;AAAA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AA,MAAW,YAAY,gBAAkB,EAAA;AACvC,UAAM,MAAA,oBAAA,GAAuB,MAAO,CAAA,MAAA,CAAO,QAAU,EAAA;AAAA,YACnD,aAAA,EAAe,SAAS,aAAiB,IAAA,SAAA;AAAA,YACzC,SAAA,EAAW,SAAS,SAAa,IAAA,KAAA;AAAA,YACjC,MAAA,EAAQ,SAAS,MAAU,IAAA,KAAA;AAAA,YAC3B,GAAA,EAAK,SAAS,GAAO,IAAA,KAAA;AAAA,YACrB,iBAAA,EAAmB,SAAS,iBAAqB,IAAA;AAAA,WAClD,CAAA;AAED,UAAI,IAAA;AACF,YAAA,MAAM,OAAO,gBAAiB,CAAA,MAAA;AAAA,cAC5B,SAAA;AAAA,cACA;AAAA,aACF;AAAA,mBACO,CAAG,EAAA;AACV,YAAA,MAAM,IAAIA,iBAAA;AAAA,cACR,4CACE,oBAAqB,CAAA,GACvB,CAAK,EAAA,EAAA,gBAAA,CAAiB,CAAC,CAAC,CAAA;AAAA,aAC1B;AAAA;AACF;AACF;AAGF,MAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,YAAA,EAAc,UAAU,CAAA;AACjD,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AAAA;AACnC,GACD,CAAA;AACH;AAEA,SAAS,iBAAiB,KAAoB,EAAA;AAC5C,EAAO,OAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,MAAM,IAAM,EAAA,OAAA,EAAS,KAAM,CAAA,WAAA,EAAa,CAAA;AACxE;;;;"}
@@ -148,6 +148,43 @@ const examples = [
148
148
  }
149
149
  ]
150
150
  })
151
+ },
152
+ {
153
+ description: "Initializes a GitLab repository with pipeline must succeed and allow merge on skipped pipeline settings.",
154
+ example: yaml__default.default.stringify({
155
+ steps: [
156
+ {
157
+ id: "publish",
158
+ action: "publish:gitlab",
159
+ name: "Publish to GitLab",
160
+ input: {
161
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
162
+ settings: {
163
+ only_allow_merge_if_pipeline_succeeds: true,
164
+ allow_merge_on_skipped_pipeline: true
165
+ }
166
+ }
167
+ }
168
+ ]
169
+ })
170
+ },
171
+ {
172
+ description: "Initializes a GitLab repository with setting to require all threads (discussions) on merge request to be resolved before merging.",
173
+ example: yaml__default.default.stringify({
174
+ steps: [
175
+ {
176
+ id: "publish",
177
+ action: "publish:gitlab",
178
+ name: "Publish to GitLab",
179
+ input: {
180
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
181
+ settings: {
182
+ only_allow_merge_if_all_discussions_are_resolved: true
183
+ }
184
+ }
185
+ }
186
+ ]
187
+ })
151
188
  }
152
189
  ];
153
190
 
@@ -1 +1 @@
1
- {"version":3,"file":"gitlab.examples.cjs.js","sources":["../../src/actions/gitlab.examples.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 { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Initializes a git repository with the content in the workspace, and publishes it to GitLab with the default configuration.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n },\n },\n ],\n }),\n },\n {\n description: 'Add a description.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n gitCommitMessage: 'Started a project.',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with aditional settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n ci_config_path: '.gitlab-ci.yml',\n visibility: 'public',\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with fast forward merge and always squash settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n merge_method: 'ff',\n squash_option: 'always',\n },\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with branch settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n branches: [\n {\n name: 'dev',\n create: true,\n protect: true,\n ref: 'master',\n },\n {\n name: 'master',\n protect: true,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with environment variables.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n projectVariables: [\n {\n key: 'key1',\n value: 'value1',\n protected: true,\n masked: false,\n },\n {\n key: 'key2',\n value: 'value2',\n protected: true,\n masked: false,\n },\n ],\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,4HAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA;AAAA;AACX;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,oBAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,WAAa,EAAA;AAAA;AACf;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,0GAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,WAAa,EAAA,6BAAA;AAAA,YACb,gBAAkB,EAAA;AAAA;AACpB;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,0DAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;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A,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,gBAAkB,EAAA;AAAA,cAChB;AAAA,gBACE,GAAK,EAAA,MAAA;AAAA,gBACL,KAAO,EAAA,QAAA;AAAA,gBACP,SAAW,EAAA,IAAA;AAAA,gBACX,MAAQ,EAAA;AAAA,eACV;AAAA,cACA;AAAA,gBACE,GAAK,EAAA,MAAA;AAAA,gBACL,KAAO,EAAA,QAAA;AAAA,gBACP,SAAW,EAAA,IAAA;AAAA,gBACX,MAAQ,EAAA;AAAA;AACV;AACF;AACF;AACF;AACF,KACD;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"gitlab.examples.cjs.js","sources":["../../src/actions/gitlab.examples.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 { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Initializes a git repository with the content in the workspace, and publishes it to GitLab with the default configuration.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n },\n },\n ],\n }),\n },\n {\n description: 'Add a description.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n gitCommitMessage: 'Started a project.',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with aditional settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n ci_config_path: '.gitlab-ci.yml',\n visibility: 'public',\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with fast forward merge and always squash settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n merge_method: 'ff',\n squash_option: 'always',\n },\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with branch settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n branches: [\n {\n name: 'dev',\n create: true,\n protect: true,\n ref: 'master',\n },\n {\n name: 'master',\n protect: true,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with environment variables.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n projectVariables: [\n {\n key: 'key1',\n value: 'value1',\n protected: true,\n masked: false,\n },\n {\n key: 'key2',\n value: 'value2',\n protected: true,\n masked: false,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with pipeline must succeed and allow merge on skipped pipeline settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n only_allow_merge_if_pipeline_succeeds: true,\n allow_merge_on_skipped_pipeline: true,\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with setting to require all threads (discussions) on merge request to be resolved before merging.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n only_allow_merge_if_all_discussions_are_resolved: true,\n },\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,4HAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA;AAAA;AACX;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,oBAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,WAAa,EAAA;AAAA;AACf;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,W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AAS,EAAA,+CAAA;AAAA,YACT,QAAU,EAAA;AAAA,cACR,qCAAuC,EAAA,IAAA;AAAA,cACvC,+BAAiC,EAAA;AAAA;AACnC;AACF;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,mIAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,QAAU,EAAA;AAAA,cACR,gDAAkD,EAAA;AAAA;AACpD;AACF;AACF;AACF,KACD;AAAA;AAEL;;;;"}
@@ -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,CAC7B,CAAA,KAAA;AAAA,IACC,oDAAA;AAAA,IACA;AAAA,IAED,QAAS,EAAA;AAAA,EACZ,SAASA,KACN,CAAA,MAAA,EAC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AA,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,GAAuBA,MAAE,MAAO,CAAA;AAAA,EACpC,SAAW,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,YAAY,CAAA;AAAA,EAC3C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,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,MAAA,EAAQA,MACL,MAAO,CAAA;AAAA,IACN,WACE,EAAA;AAAA,GACH,CACA,CAAA,GAAA,CAAI,CAAG,EAAA,mDAAmD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AAO,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,EAAA;AAAA,GACH,EACA,QAAS,EAAA;AAAA,EACZ,SAAW,EAAAA,KAAA,CACR,KAAM,CAAAA,KAAA,CAAE,QAAU,EAAA;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AC,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,CAAA;AAAA,SACT;AACA,QAAA,IAAI,aAAc,CAAA,QAAA,CAAS,IAAI,CAAA,KAAM,WAAW,cAAgB,EAAA;AAC9D,UAAO,O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GAAA,EAAM,CAAC,CAAA;AAAA,WACvH;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,IAAIA,iBAAA;AAAA,YACR,CAAA,0BAAA,EAA6B,UAAU,CAAA,qFAAA,EAAwF,CAAC,CAAA;AAAA,WAClI;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,IAAIA,iBAAA,CAAW,CAAgC,6BAAA,EAAA,CAAC,CAAE,CAAA,CAAA;AAAA;AAC1D;AACF,GACD,CAAA;AACH;;;;"}
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, 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,SACrE;AAAA;AAEF,MAAO,OAAA,QAAA;AAAA;AAET,IAAO,OAAA,QAAA;AAAA;AAET,EAAO,OAAA,mBAAA;AACT;AAOa,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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,MAAA,IAAI,qBAA2D,GAAA,IAAA;AAE/D,MAAA,MAAM,EAAE,OAAA,EAAS,SAAW,EAAA,gBAAA,EAAkB,OAAO,MAAQ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AAM,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,EAAE,WAAA,EAAa,gBAAgB;AACvD,CAAC,CAAA;AAQY,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,E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AI,EAAA;AAC/B,UAAI,GAAA,CAAA,MAAA,CAAO,MAAM,6BAA6B,CAAA;AAC9C,UAAA;AAAA;AAGF,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAe,YAAA,EAAA,uBAAA,CAAwB,EAAE,CAAa,WAAA,CAAA,CAAA;AAEtE,QAAI,GAAA,CAAA,MAAA,CAAO,aAAe,EAAA,uBAAA,CAAwB,OAAO,CAAA;AAAA,eAClD,KAAY,EAAA;AACnB,QAAI,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;AAAA,UACR,CAAA,4BAAA,EAA+BC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SACvD;AAAA,OACA,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;;;;"}
@@ -116,7 +116,9 @@ const createGitlabRepoPushAction = (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,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAQJ,CAAA;AAAA,IACD,EAAI,EAAA,kBAAA;AAA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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,EAAA,CAAA,sJAAA;AAAA,WACf;AAAA,UACA,UAAY,EAAA;AAAA,YACV,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,oBAA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  });
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/index.d.ts CHANGED
@@ -35,6 +35,9 @@ declare function createPublishGitlabAction(options: {
35
35
  squash_option?: "always" | "never" | "default_off" | "default_on" | undefined;
36
36
  topics?: string[] | undefined;
37
37
  visibility?: "internal" | "private" | "public" | undefined;
38
+ only_allow_merge_if_all_discussions_are_resolved?: boolean | undefined;
39
+ only_allow_merge_if_pipeline_succeeds?: boolean | undefined;
40
+ allow_merge_on_skipped_pipeline?: boolean | undefined;
38
41
  } | undefined;
39
42
  branches?: {
40
43
  name: string;
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,O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GAAA,MAAM,MAAO,CAAA,QAAA,CAAS,KAAK,SAAS,CAAA;AACpD,IAAA,IAAI,CAAC,OAAS,EAAA;AACZ,MAAA,MAAM,IAAIA,iBAAA;AAAA,QACR,mBAAmB,SAAS,CAAA,uCAAA;AAAA,OAC9B;AAAA;AAEF,IAAA,MAAM,iBAAiB,MAAM,sBAAA;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,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;AAAA,WAC9B,KAAO,EAAA;AACd,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK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AA,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;;;;;;;;;;"}
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.2",
3
+ "version": "0.6.1",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "scaffolder",
@@ -30,6 +30,13 @@
30
30
  },
31
31
  "main": "./dist/index.cjs.js",
32
32
  "types": "./dist/index.d.ts",
33
+ "typesVersions": {
34
+ "*": {
35
+ "index": [
36
+ "dist/index.d.ts"
37
+ ]
38
+ }
39
+ },
33
40
  "files": [
34
41
  "dist"
35
42
  ],
@@ -44,11 +51,11 @@
44
51
  },
45
52
  "dependencies": {
46
53
  "@backstage/backend-common": "^0.25.0",
47
- "@backstage/backend-plugin-api": "1.0.2-next.2",
48
- "@backstage/config": "1.2.0",
49
- "@backstage/errors": "1.2.4",
50
- "@backstage/integration": "1.15.1",
51
- "@backstage/plugin-scaffolder-node": "0.5.1-next.2",
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.0",
52
59
  "@gitbeaker/core": "^35.8.0",
53
60
  "@gitbeaker/node": "^35.8.0",
54
61
  "@gitbeaker/rest": "^39.25.0",
@@ -58,9 +65,9 @@
58
65
  "zod": "^3.22.4"
59
66
  },
60
67
  "devDependencies": {
61
- "@backstage/backend-test-utils": "1.1.0-next.2",
62
- "@backstage/cli": "0.29.0-next.2",
63
- "@backstage/core-app-api": "1.15.1",
64
- "@backstage/plugin-scaffolder-node-test-utils": "0.1.15-next.2"
68
+ "@backstage/backend-test-utils": "^1.1.0",
69
+ "@backstage/cli": "^0.29.0",
70
+ "@backstage/core-app-api": "^1.15.2",
71
+ "@backstage/plugin-scaffolder-node-test-utils": "^0.1.15"
65
72
  }
66
73
  }