@backstage/plugin-scaffolder-backend-module-gitlab 0.11.10 → 0.11.11-next.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,12 +1,23 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
- ## 0.11.10
3
+ ## 0.11.11-next.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - 6fb2a41: Added support for requiring user-provided credentials for GitLab mutation actions when `scaffolder.requireScmUserCredentials` is enabled.
7
+ - bbba6b5: Added support for requiring user-provided credentials for GitLab mutation actions when `scaffolder.requireScmUserCredentials` is enabled.
8
+ - cd77db3: Added an `autoMerge` boolean input to the `publish:gitlab:merge-request` scaffolder action. When set to `true`, the merge request is automatically merged once all merge checks succeed, using GitLab's auto-merge feature.
8
9
  - Updated dependencies
9
- - @backstage/integration@2.1.1
10
+ - @backstage/integration@2.1.2-next.0
11
+ - @backstage/plugin-scaffolder-node@0.13.7-next.1
12
+ - @backstage/backend-plugin-api@1.10.1-next.0
13
+
14
+ ## 0.11.10-next.0
15
+
16
+ ### Patch Changes
17
+
18
+ - 3c7c082: Fixed `gitlab:repo:push` failing with `400 Bad request - Provide at least one action` when the workspace has no file changes to commit (e.g. re-running a template against an already up-to-date branch). The action now detects an empty action list, skips the commit API call, and logs a warning whenever `allowEmpty` is not true (covering both the default of unset and an explicit `false`). The `commitHash` output is omitted in this no-op case and is now declared optional. Pass `allowEmpty: true` to retain the previous behavior of forwarding an empty commit to GitLab.
19
+ - Updated dependencies
20
+ - @backstage/plugin-scaffolder-node@0.13.7-next.0
10
21
 
11
22
  ## 0.11.9
12
23
 
@@ -73,7 +73,10 @@ _deprecated_: \`projectid\` passed as query parameters in the \`repoUrl\``
73
73
  assignReviewersFromApprovalRules: (z) => z.boolean().optional().describe(
74
74
  "Automatically assign reviewers from the approval rules of the MR. Includes `CODEOWNERS`"
75
75
  ),
76
- labels: (z) => z.string().or(z.string().array()).optional().describe("Labels with which to tag the created merge request")
76
+ labels: (z) => z.string().or(z.string().array()).optional().describe("Labels with which to tag the created merge request"),
77
+ autoMerge: (z) => z.boolean().optional().describe(
78
+ "Automatically merge the MR when all merge checks succeed. Uses GitLab auto-merge. Default: `false`"
79
+ )
77
80
  },
78
81
  output: {
79
82
  targetBranchName: (z) => z.string().describe("Target branch name of the merge request"),
@@ -95,7 +98,8 @@ _deprecated_: \`projectid\` passed as query parameters in the \`repoUrl\``
95
98
  sourcePath,
96
99
  title,
97
100
  token,
98
- labels
101
+ labels,
102
+ autoMerge
99
103
  } = ctx.input;
100
104
  const { owner, repo, project } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
101
105
  const repoID = project ? project : `${owner}/${repo}`;
@@ -317,6 +321,25 @@ _deprecated_: \`projectid\` passed as query parameters in the \`repoUrl\``
317
321
  return { mrWebUrl };
318
322
  }
319
323
  });
324
+ if (autoMerge) {
325
+ await ctx.checkpoint({
326
+ key: `auto.merge.mr.${repoID}.${branchName}`,
327
+ fn: async () => {
328
+ try {
329
+ await api.MergeRequests.merge(repoID, mrId, {
330
+ autoMerge: true
331
+ });
332
+ return null;
333
+ } catch (e) {
334
+ throw new errors.InputError(
335
+ `Enabling auto-merge for merge request ${mrId} failed. ${helpers.getErrorMessage(
336
+ e
337
+ )}`
338
+ );
339
+ }
340
+ }
341
+ });
342
+ }
320
343
  ctx.output("projectid", repoID);
321
344
  ctx.output("targetBranchName", targetBranch);
322
345
  ctx.output("projectPath", repoID);
@@ -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 {\n Camelize,\n CommitAction,\n ExpandedMergeRequestSchema,\n Gitlab,\n RepositoryTreeSchema,\n SimpleUserSchema,\n} from '@gitbeaker/rest';\nimport path from 'node: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 './gitlabMergeRequest.examples';\n\nimport { getFileAction } from '../util';\n\nasync function getReviewersFromApprovalRules(\n api: InstanceType<typeof Gitlab>,\n mergerequestIId: number,\n repoID: string,\n ctx: any,\n): Promise<number[]> {\n try {\n // Because we don't know the code owners before the MR is created, we can't check the approval rules beforehand.\n // Getting the approval rules beforehand is very difficult, especially, because of the inheritance rules for groups.\n // Code owners take a moment to be processed and added to the approval rules after the MR is created.\n\n let mergeRequest:\n | ExpandedMergeRequestSchema\n | Camelize<ExpandedMergeRequestSchema> = await api.MergeRequests.show(\n repoID,\n mergerequestIId,\n );\n\n while (\n mergeRequest.detailed_merge_status === 'preparing' ||\n mergeRequest.detailed_merge_status === 'approvals_syncing' ||\n mergeRequest.detailed_merge_status === 'checking'\n ) {\n mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);\n ctx.logger.info(`${mergeRequest.detailed_merge_status}`);\n }\n\n const approvalRules = await api.MergeRequestApprovals.allApprovalRules(\n repoID,\n {\n mergerequestIId: mergeRequest.iid,\n },\n );\n\n return approvalRules\n .filter(rule => rule.eligible_approvers !== undefined)\n .map(rule => {\n return rule.eligible_approvers as SimpleUserSchema[];\n })\n .flat()\n .map(user => user.id);\n } catch (e) {\n ctx.logger.warn(\n `Failed to retrieve approval rules for MR ${mergerequestIId}: ${getErrorMessage(\n e,\n )}. Proceeding with MR creation without reviewers from approval rules.`,\n );\n return [];\n }\n}\n\nconst commitActions = ['create', 'delete', 'update', 'skip', 'auto'] as const;\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 requireScmUserCredentials?: boolean;\n}) => {\n const { integrations, requireScmUserCredentials } = options;\n\n return createTemplateAction({\n id: 'publish:gitlab:merge-request',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string().describe(`\\\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 title: z => z.string().describe('The name for the merge request'),\n description: z =>\n z\n .string()\n .optional()\n .describe('The description of the merge request'),\n branchName: z =>\n z.string().describe('The source branch name of the merge request'),\n targetBranchName: z =>\n z\n .string()\n .optional()\n .describe(\n 'The target branch name of the merge request (defaults to _default branch of repository_)',\n ),\n sourcePath: z =>\n z.string().optional().describe(`\\\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 targetPath: z =>\n z\n .string()\n .optional()\n .describe('Subdirectory of repository to apply changes to'),\n token: z =>\n z\n .string()\n .optional()\n .describe('The token to use for authorization to GitLab'),\n commitAction: z =>\n z.enum(commitActions).optional().describe(`\\\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 /** @deprecated projectID passed as query parameters in the repoUrl */\n projectid: z =>\n z\n .string()\n .optional()\n .describe(\n `\\\nProject ID/Name(slug) of the GitLab Project\n_deprecated_: \\`projectid\\` passed as query parameters in the \\`repoUrl\\``,\n ),\n removeSourceBranch: z =>\n z\n .boolean()\n .optional()\n .describe(\n 'Option to delete source branch once the MR has been merged. Default: `false`',\n ),\n assignee: z =>\n z\n .string()\n .optional()\n .describe('User this merge request will be assigned to'),\n reviewers: z =>\n z\n .string()\n .array()\n .optional()\n .describe('Users that will be assigned as reviewers'),\n assignReviewersFromApprovalRules: z =>\n z\n .boolean()\n .optional()\n .describe(\n 'Automatically assign reviewers from the approval rules of the MR. Includes `CODEOWNERS`',\n ),\n labels: z =>\n z\n .string()\n .or(z.string().array())\n .optional()\n .describe('Labels with which to tag the created merge request'),\n },\n output: {\n targetBranchName: z =>\n z.string().describe('Target branch name of the merge request'),\n projectid: z => z.string().describe('GitLab Project id/Name(slug)'),\n projectPath: z => z.string().describe('GitLab Project path'),\n mergeRequestUrl: z =>\n z.string().describe('Link to the merge request in GitLab'),\n },\n },\n async handler(ctx) {\n const {\n assignee,\n reviewers,\n branchName,\n targetBranchName,\n description,\n repoUrl,\n removeSourceBranch,\n targetPath,\n sourcePath,\n title,\n token,\n labels,\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 requireScmUserCredentials,\n });\n\n let assigneeId: number | undefined = undefined;\n\n if (assignee !== undefined) {\n try {\n const assigneeUser = await api.Users.all({ 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 reviewerIds: number[] | undefined = undefined; // Explicitly set to undefined. Strangely, passing an empty array to the API will result the other options being undefined also being explicitly passed to the Gitlab API call (e.g. assigneeId)\n if (reviewers !== undefined) {\n reviewerIds = (\n await Promise.all(\n reviewers.map(async reviewer => {\n try {\n const reviewerUser = await api.Users.all({\n username: reviewer,\n });\n return reviewerUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${reviewer}: ${e}. Proceeding with MR creation without reviewer.`,\n );\n return undefined;\n }\n }),\n )\n ).filter(id => id !== undefined) as number[];\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 const defaultBranch = projects.default_branch ?? projects.defaultBranch;\n if (typeof defaultBranch !== 'string' || !defaultBranch) {\n throw new InputError(\n `The branch creation failed. Target branch was not provided, and could not find default branch from project settings. Project: ${JSON.stringify(\n project,\n )}`,\n );\n }\n targetBranch = defaultBranch;\n }\n\n let remoteFiles: RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.allRepositoryTrees(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: 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: 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 = actions.length > 0;\n\n try {\n const branch = await api.Branches.show(repoID, branchName);\n if (createBranch) {\n const mergeRequests = await api.MergeRequests.all({\n projectId: repoID,\n source_branch: branchName,\n });\n\n if (mergeRequests.length > 0) {\n // If an open MR exists, include the MR link in the error message\n throw new InputError(\n `The branch creation failed because the branch already exists at: ${branch.web_url}. Additionally, there is a Merge Request for this branch: ${mergeRequests[0].web_url}`,\n );\n } else {\n // If no open MR, just notify about the existing branch\n throw new InputError(\n `The branch creation failed because the branch already exists at: ${branch.web_url}.`,\n );\n }\n }\n\n ctx.logger.info(\n `Using existing branch ${branchName} without modification.`,\n );\n } catch (e) {\n if (e instanceof InputError) {\n throw e;\n }\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\n await ctx.checkpoint({\n key: `commit.to.${repoID}.${branchName}`,\n fn: async () => {\n if (actions.length) {\n try {\n const commit = await api.Commits.create(\n repoID,\n branchName,\n title,\n actions,\n );\n return 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 return null;\n },\n });\n\n const { mrId, mrWebUrl } = await ctx.checkpoint({\n key: `create.mr.${repoID}.${branchName}`,\n fn: async () => {\n try {\n const mergeRequest = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch\n ? removeSourceBranch\n : false,\n assigneeId,\n reviewerIds,\n labels,\n },\n );\n return {\n mrId: mergeRequest.iid,\n mrWebUrl: mergeRequest.web_url ?? mergeRequest.webUrl,\n };\n } catch (e) {\n throw new InputError(\n `Merge request creation failed. ${getErrorMessage(e)}`,\n );\n }\n },\n });\n\n await ctx.checkpoint({\n key: `create.mr.assign.reviewers.${repoID}.${branchName}`,\n fn: async () => {\n if (ctx.input.assignReviewersFromApprovalRules) {\n try {\n const reviewersFromApprovalRules =\n await getReviewersFromApprovalRules(api, mrId, repoID, ctx);\n if (reviewersFromApprovalRules.length > 0) {\n const eligibleUserIds = new Set([\n ...reviewersFromApprovalRules,\n ...(reviewerIds ?? []),\n ]);\n\n const mergeRequest = await api.MergeRequests.edit(\n repoID,\n mrId,\n {\n reviewerIds: Array.from(eligibleUserIds),\n },\n );\n return {\n mrWebUrl: mergeRequest.web_url ?? mergeRequest.webUrl,\n };\n }\n } catch (e) {\n ctx.logger.warn(\n `Failed to assign reviewers from approval rules: ${getErrorMessage(\n e,\n )}.`,\n );\n }\n }\n return { mrWebUrl };\n },\n });\n\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output('mergeRequestUrl', mrWebUrl as string);\n },\n });\n};\n"],"names":["getErrorMessage","createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","InputError","getFileAction","path"],"mappings":";;;;;;;;;;;;;;AAuCA,eAAe,6BAAA,CACb,GAAA,EACA,eAAA,EACA,MAAA,EACA,GAAA,EACmB;AACnB,EAAA,IAAI;AAKF,IAAA,IAAI,YAAA,GAEuC,MAAM,GAAA,CAAI,aAAA,CAAc,IAAA;AAAA,MACjE,MAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,OACE,YAAA,CAAa,0BAA0B,WAAA,IACvC,YAAA,CAAa,0BAA0B,mBAAA,IACvC,YAAA,CAAa,0BAA0B,UAAA,EACvC;AACA,MAAA,YAAA,GAAe,MAAM,GAAA,CAAI,aAAA,CAAc,IAAA,CAAK,MAAA,EAAQ,aAAa,GAAG,CAAA;AACpE,MAAA,GAAA,CAAI,MAAA,CAAO,IAAA,CAAK,CAAA,EAAG,YAAA,CAAa,qBAAqB,CAAA,CAAE,CAAA;AAAA,IACzD;AAEA,IAAA,MAAM,aAAA,GAAgB,MAAM,GAAA,CAAI,qBAAA,CAAsB,gBAAA;AAAA,MACpD,MAAA;AAAA,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ACzC,gBAAA,MAAM,eAAA,uBAAsB,GAAA,CAAI;AAAA,kBAC9B,GAAG,0BAAA;AAAA,kBACH,GAAI,eAAe;AAAC,iBACrB,CAAA;AAED,gBAAA,MAAM,YAAA,GAAe,MAAM,GAAA,CAAI,aAAA,CAAc,IAAA;AAAA,kBAC3C,MAAA;AAAA,kBACA,IAAA;AAAA,kBACA;AAAA,oBACE,WAAA,EAAa,KAAA,CAAM,IAAA,CAAK,eAAe;AAAA;AACzC,iBACF;AACA,gBAAA,OAAO;AAAA,kBACL,QAAA,EAAU,YAAA,CAAa,OAAA,IAAW,YAAA,CAAa;AAAA,iBACjD;AAAA,cACF;AAAA,YACF,SAAS,CAAA,EAAG;AACV,cAAA,GAAA,CAAI,MAAA,CAAO,IAAA;AAAA,gBACT,CAAA,gDAAA,EAAmDA,uBAAA;AAAA,kBACjD;AAAA,iBACD,CAAA,CAAA;AAAA,eACH;AAAA,YACF;AAAA,UACF;AACA,UAAA,OAAO,EAAE,QAAA,EAAS;AAAA,QACpB;AAAA,OACD,CAAA;AAED,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,MAAA,GAAA,CAAI,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,MAAA,GAAA,CAAI,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,MAAA,GAAA,CAAI,MAAA,CAAO,mBAAmB,QAAkB,CAAA;AAAA,IAClD;AAAA,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 {\n Camelize,\n CommitAction,\n ExpandedMergeRequestSchema,\n Gitlab,\n RepositoryTreeSchema,\n SimpleUserSchema,\n} from '@gitbeaker/rest';\nimport path from 'node: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 './gitlabMergeRequest.examples';\n\nimport { getFileAction } from '../util';\n\nasync function getReviewersFromApprovalRules(\n api: InstanceType<typeof Gitlab>,\n mergerequestIId: number,\n repoID: string,\n ctx: any,\n): Promise<number[]> {\n try {\n // Because we don't know the code owners before the MR is created, we can't check the approval rules beforehand.\n // Getting the approval rules beforehand is very difficult, especially, because of the inheritance rules for groups.\n // Code owners take a moment to be processed and added to the approval rules after the MR is created.\n\n let mergeRequest:\n | ExpandedMergeRequestSchema\n | Camelize<ExpandedMergeRequestSchema> = await api.MergeRequests.show(\n repoID,\n mergerequestIId,\n );\n\n while (\n mergeRequest.detailed_merge_status === 'preparing' ||\n mergeRequest.detailed_merge_status === 'approvals_syncing' ||\n mergeRequest.detailed_merge_status === 'checking'\n ) {\n mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);\n ctx.logger.info(`${mergeRequest.detailed_merge_status}`);\n }\n\n const approvalRules = await api.MergeRequestApprovals.allApprovalRules(\n repoID,\n {\n mergerequestIId: mergeRequest.iid,\n },\n );\n\n return approvalRules\n .filter(rule => rule.eligible_approvers !== undefined)\n .map(rule => {\n return rule.eligible_approvers as SimpleUserSchema[];\n })\n .flat()\n .map(user => user.id);\n } catch (e) {\n ctx.logger.warn(\n `Failed to retrieve approval rules for MR ${mergerequestIId}: ${getErrorMessage(\n e,\n )}. Proceeding with MR creation without reviewers from approval rules.`,\n );\n return [];\n }\n}\n\nconst commitActions = ['create', 'delete', 'update', 'skip', 'auto'] as const;\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 requireScmUserCredentials?: boolean;\n}) => {\n const { integrations, requireScmUserCredentials } = options;\n\n return createTemplateAction({\n id: 'publish:gitlab:merge-request',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string().describe(`\\\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 title: z => z.string().describe('The name for the merge request'),\n description: z =>\n z\n .string()\n .optional()\n .describe('The description of the merge request'),\n branchName: z =>\n z.string().describe('The source branch name of the merge request'),\n targetBranchName: z =>\n z\n .string()\n .optional()\n .describe(\n 'The target branch name of the merge request (defaults to _default branch of repository_)',\n ),\n sourcePath: z =>\n z.string().optional().describe(`\\\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 targetPath: z =>\n z\n .string()\n .optional()\n .describe('Subdirectory of repository to apply changes to'),\n token: z =>\n z\n .string()\n .optional()\n .describe('The token to use for authorization to GitLab'),\n commitAction: z =>\n z.enum(commitActions).optional().describe(`\\\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 /** @deprecated projectID passed as query parameters in the repoUrl */\n projectid: z =>\n z\n .string()\n .optional()\n .describe(\n `\\\nProject ID/Name(slug) of the GitLab Project\n_deprecated_: \\`projectid\\` passed as query parameters in the \\`repoUrl\\``,\n ),\n removeSourceBranch: z =>\n z\n .boolean()\n .optional()\n .describe(\n 'Option to delete source branch once the MR has been merged. Default: `false`',\n ),\n assignee: z =>\n z\n .string()\n .optional()\n .describe('User this merge request will be assigned to'),\n reviewers: z =>\n z\n .string()\n .array()\n .optional()\n .describe('Users that will be assigned as reviewers'),\n assignReviewersFromApprovalRules: z =>\n z\n .boolean()\n .optional()\n .describe(\n 'Automatically assign reviewers from the approval rules of the MR. Includes `CODEOWNERS`',\n ),\n labels: z =>\n z\n .string()\n .or(z.string().array())\n .optional()\n .describe('Labels with which to tag the created merge request'),\n autoMerge: z =>\n z\n .boolean()\n .optional()\n .describe(\n 'Automatically merge the MR when all merge checks succeed. Uses GitLab auto-merge. Default: `false`',\n ),\n },\n output: {\n targetBranchName: z =>\n z.string().describe('Target branch name of the merge request'),\n projectid: z => z.string().describe('GitLab Project id/Name(slug)'),\n projectPath: z => z.string().describe('GitLab Project path'),\n mergeRequestUrl: z =>\n z.string().describe('Link to the merge request in GitLab'),\n },\n },\n async handler(ctx) {\n const {\n assignee,\n reviewers,\n branchName,\n targetBranchName,\n description,\n repoUrl,\n removeSourceBranch,\n targetPath,\n sourcePath,\n title,\n token,\n labels,\n autoMerge,\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 requireScmUserCredentials,\n });\n\n let assigneeId: number | undefined = undefined;\n\n if (assignee !== undefined) {\n try {\n const assigneeUser = await api.Users.all({ 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 reviewerIds: number[] | undefined = undefined; // Explicitly set to undefined. Strangely, passing an empty array to the API will result the other options being undefined also being explicitly passed to the Gitlab API call (e.g. assigneeId)\n if (reviewers !== undefined) {\n reviewerIds = (\n await Promise.all(\n reviewers.map(async reviewer => {\n try {\n const reviewerUser = await api.Users.all({\n username: reviewer,\n });\n return reviewerUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${reviewer}: ${e}. Proceeding with MR creation without reviewer.`,\n );\n return undefined;\n }\n }),\n )\n ).filter(id => id !== undefined) as number[];\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 const defaultBranch = projects.default_branch ?? projects.defaultBranch;\n if (typeof defaultBranch !== 'string' || !defaultBranch) {\n throw new InputError(\n `The branch creation failed. Target branch was not provided, and could not find default branch from project settings. Project: ${JSON.stringify(\n project,\n )}`,\n );\n }\n targetBranch = defaultBranch;\n }\n\n let remoteFiles: RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.allRepositoryTrees(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: 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: 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 = actions.length > 0;\n\n try {\n const branch = await api.Branches.show(repoID, branchName);\n if (createBranch) {\n const mergeRequests = await api.MergeRequests.all({\n projectId: repoID,\n source_branch: branchName,\n });\n\n if (mergeRequests.length > 0) {\n // If an open MR exists, include the MR link in the error message\n throw new InputError(\n `The branch creation failed because the branch already exists at: ${branch.web_url}. Additionally, there is a Merge Request for this branch: ${mergeRequests[0].web_url}`,\n );\n } else {\n // If no open MR, just notify about the existing branch\n throw new InputError(\n `The branch creation failed because the branch already exists at: ${branch.web_url}.`,\n );\n }\n }\n\n ctx.logger.info(\n `Using existing branch ${branchName} without modification.`,\n );\n } catch (e) {\n if (e instanceof InputError) {\n throw e;\n }\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\n await ctx.checkpoint({\n key: `commit.to.${repoID}.${branchName}`,\n fn: async () => {\n if (actions.length) {\n try {\n const commit = await api.Commits.create(\n repoID,\n branchName,\n title,\n actions,\n );\n return 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 return null;\n },\n });\n\n const { mrId, mrWebUrl } = await ctx.checkpoint({\n key: `create.mr.${repoID}.${branchName}`,\n fn: async () => {\n try {\n const mergeRequest = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch\n ? removeSourceBranch\n : false,\n assigneeId,\n reviewerIds,\n labels,\n },\n );\n return {\n mrId: mergeRequest.iid,\n mrWebUrl: mergeRequest.web_url ?? mergeRequest.webUrl,\n };\n } catch (e) {\n throw new InputError(\n `Merge request creation failed. ${getErrorMessage(e)}`,\n );\n }\n },\n });\n\n await ctx.checkpoint({\n key: `create.mr.assign.reviewers.${repoID}.${branchName}`,\n fn: async () => {\n if (ctx.input.assignReviewersFromApprovalRules) {\n try {\n const reviewersFromApprovalRules =\n await getReviewersFromApprovalRules(api, mrId, repoID, ctx);\n if (reviewersFromApprovalRules.length > 0) {\n const eligibleUserIds = new Set([\n ...reviewersFromApprovalRules,\n ...(reviewerIds ?? []),\n ]);\n\n const mergeRequest = await api.MergeRequests.edit(\n repoID,\n mrId,\n {\n reviewerIds: Array.from(eligibleUserIds),\n },\n );\n return {\n mrWebUrl: mergeRequest.web_url ?? mergeRequest.webUrl,\n };\n }\n } catch (e) {\n ctx.logger.warn(\n `Failed to assign reviewers from approval rules: ${getErrorMessage(\n e,\n )}.`,\n );\n }\n }\n return { mrWebUrl };\n },\n });\n if (autoMerge) {\n await ctx.checkpoint({\n key: `auto.merge.mr.${repoID}.${branchName}`,\n fn: async () => {\n try {\n await api.MergeRequests.merge(repoID, mrId, {\n autoMerge: true,\n });\n return null;\n } catch (e) {\n throw new InputError(\n `Enabling auto-merge for merge request ${mrId} failed. ${getErrorMessage(\n e,\n )}`,\n );\n }\n },\n });\n }\n\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output('mergeRequestUrl', mrWebUrl as string);\n },\n });\n};\n"],"names":["getErrorMessage","createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","InputError","getFileAction","path"],"mappings":";;;;;;;;;;;;;;AAuCA,eAAe,6BAAA,CACb,GAAA,EACA,eAAA,EACA,MAAA,EACA,GAAA,EACmB;AACnB,EAAA,IAAI;AAKF,IAAA,IAAI,YAAA,GAEuC,MAAM,GAAA,CAAI,aAAA,CAAc,IAAA;AAAA,MACjE,MAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,OACE,YAAA,CAAa,0BAA0B,WAAA,IACvC,YAAA,CAAa,0BAA0B,mBAAA,IACvC,YAAA,CAAa,0BAA0B,UAAA,EACvC;AACA,MAAA,YAAA,GAAe,MA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AAI;AACF,cAAA,MAAM,GAAA,CAAI,aAAA,CAAc,KAAA,CAAM,MAAA,EAAQ,IAAA,EAAM;AAAA,gBAC1C,SAAA,EAAW;AAAA,eACZ,CAAA;AACD,cAAA,OAAO,IAAA;AAAA,YACT,SAAS,CAAA,EAAG;AACV,cAAA,MAAM,IAAIO,iBAAA;AAAA,gBACR,CAAA,sCAAA,EAAyC,IAAI,CAAA,SAAA,EAAYP,uBAAA;AAAA,kBACvD;AAAA,iBACD,CAAA;AAAA,eACH;AAAA,YACF;AAAA,UACF;AAAA,SACD,CAAA;AAAA,MACH;AAEA,MAAA,GAAA,CAAI,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,MAAA,GAAA,CAAI,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,MAAA,GAAA,CAAI,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,MAAA,GAAA,CAAI,MAAA,CAAO,mBAAmB,QAAkB,CAAA;AAAA,IAClD;AAAA,GACD,CAAA;AACH;;;;"}
@@ -127,6 +127,25 @@ const examples = [
127
127
  }
128
128
  ]
129
129
  })
130
+ },
131
+ {
132
+ description: "Create a merge request that auto-merges when the pipeline succeeds",
133
+ example: yaml__default.default.stringify({
134
+ steps: [
135
+ {
136
+ id: "createMergeRequest",
137
+ action: "publish:gitlab:merge-request",
138
+ name: "Create a Merge Request",
139
+ input: {
140
+ repoUrl: "gitlab.com?repo=repo&owner=owner",
141
+ title: "Create my new MR",
142
+ branchName: "new-mr",
143
+ description: "MR description",
144
+ autoMerge: true
145
+ }
146
+ }
147
+ ]
148
+ })
130
149
  }
131
150
  ];
132
151
 
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabMergeRequest.examples.cjs.js","sources":["../../src/actions/gitlabMergeRequest.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 */\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Create a merge request with a specific assignee',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n description: 'This MR is really good',\n sourcePath: './path/to/my/changes',\n branchName: 'new-mr',\n assignee: 'my-assignee',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Create a merge request with removal of source branch after merge',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n description: 'This MR is really good',\n sourcePath: './path/to/my/changes',\n branchName: 'new-mr',\n removeSourceBranch: true,\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a target branch',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n description: 'This MR is really good',\n sourcePath: './path/to/my/changes',\n branchName: 'new-mr',\n targetBranchName: 'test',\n targetPath: 'Subdirectory',\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a commit action as create',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n commitAction: 'create',\n targetPath: 'source',\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a commit action as delete',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n commitAction: 'delete',\n targetPath: 'source',\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a commit action as update',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n commitAction: 'update',\n targetPath: 'source',\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAkBO,MAAM,QAAA,GAA8B;AAAA,EACzC;AAAA,IACE,WAAA,EAAa,iDAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAA,CAAU;AAAA,MACtB,KAAA,EAAO;AAAA,QACL;AAAA,UACE,EAAA,EAAI,oBAAA;AAAA,UACJ,MAAA,EAAQ,8BAAA;AAAA,UACR,IAAA,EAAM,wBAAA;AAAA,UACN,KAAA,EAAO;AAAA,YACL,OAAA,EAAS,kCAAA;AAAA,YACT,KAAA,EAAO,kBAAA;AAAA,YACP,WAAA,EAAa,wBAAA;AAAA,YACb,UAAA,EAAY,sBAAA;AAAA,YACZ,UAAA,EAAY,QAAA;AAAA,YACZ,QAAA,EAAU;AAAA;AACZ;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAA,EACE,kEAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAA,CAAU;AAAA,MACtB,KAAA,EAAO;AAAA,QACL;AAAA,UACE,EAAA,EAAI,oBAAA;AAAA,UACJ,MAAA,EAAQ,8BAAA;AAAA,UACR,IAAA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,sBAAK,SAAA,CAAU;AAAA,MACtB,KAAA,EAAO;AAAA,QACL;AAAA,UACE,EAAA,EAAI,oBAAA;AAAA,UACJ,MAAA,EAAQ,8BAAA;AAAA,UACR,IAAA,EAAM,wBAAA;AAAA,UACN,KAAA,EAAO;AAAA,YACL,OAAA,EAAS,kCAAA;AAAA,YACT,KAAA,EAAO,kBAAA;AAAA,YACP,UAAA,EAAY,QAAA;AAAA,YACZ,WAAA,EAAa,gBAAA;AAAA,YACb,YAAA,EAAc,QAAA;AAAA,YACd,UAAA,EAAY;AAAA;AACd;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAA,EAAa,uDAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAA,CAAU;AAAA,MACtB,KAAA,EAAO;AAAA,QACL;AAAA,UACE,EAAA,EAAI,oBAAA;AAAA,UACJ,MAAA,EAAQ,8BAAA;AAAA,UACR,IAAA,EAAM,wBAAA;AAAA,UACN,KAAA,EAAO;AAAA,YACL,OAAA,EAAS,kCAAA;AAAA,YACT,KAAA,EAAO,kBAAA;AAAA,YACP,UAAA,EAAY,QAAA;AAAA,YACZ,WAAA,EAAa,gBAAA;AAAA,YACb,YAAA,EAAc,QAAA;AAAA,YACd,UAAA,EAAY;AAAA;AACd;AACF;AACF,KACD;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"gitlabMergeRequest.examples.cjs.js","sources":["../../src/actions/gitlabMergeRequest.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 */\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description: 'Create a merge request with a specific assignee',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n description: 'This MR is really good',\n sourcePath: './path/to/my/changes',\n branchName: 'new-mr',\n assignee: 'my-assignee',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Create a merge request with removal of source branch after merge',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n description: 'This MR is really good',\n sourcePath: './path/to/my/changes',\n branchName: 'new-mr',\n removeSourceBranch: true,\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a target branch',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n description: 'This MR is really good',\n sourcePath: './path/to/my/changes',\n branchName: 'new-mr',\n targetBranchName: 'test',\n targetPath: 'Subdirectory',\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a commit action as create',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n commitAction: 'create',\n targetPath: 'source',\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a commit action as delete',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n commitAction: 'delete',\n targetPath: 'source',\n },\n },\n ],\n }),\n },\n {\n description: 'Create a merge request with a commit action as update',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n commitAction: 'update',\n targetPath: 'source',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Create a merge request that auto-merges when the pipeline succeeds',\n example: yaml.stringify({\n steps: [\n {\n id: 'createMergeRequest',\n action: 'publish:gitlab:merge-request',\n name: 'Create a Merge Request',\n input: {\n repoUrl: 'gitlab.com?repo=repo&owner=owner',\n title: 'Create my new MR',\n branchName: 'new-mr',\n description: 'MR description',\n autoMerge: true,\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAkBO,MAAM,QAAA,GAA8B;AAAA,EACzC;AAAA,IACE,WAAA,EAAa,iDAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAA,CAAU;AAAA,MACtB,KAAA,EAAO;AAAA,QACL;AAAA,UACE,EAAA,EAAI,oBAAA;AAAA,UACJ,MAAA,EAAQ,8BAAA;AAAA,UACR,IAAA,EAAM,wBAAA;AAAA,UACN,KAAA,EAAO;AAAA,YACL,OAAA,EAAS,kCAAA;AAAA,YACT,KAAA,EAAO,kBAAA;AAAA,YACP,WAAA,EAAa,wBAAA;AAAA,YACb,UAAA,EAAY,sBAAA;AAAA,YACZ,UAAA,EAAY,QAAA;AAAA,YACZ,QAAA,EAAU;AAAA;AACZ;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAA,EACE,kEAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAA,CAAU;AAAA,MACtB,KAAA,EAAO;AAAA,QACL;AAAA,UACE,EAAA,EAAI,oBAAA;AA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AA,EAAW;AAAA;AACb;AACF;AACF,KACD;AAAA;AAEL;;;;"}
@@ -52,8 +52,8 @@ const createGitlabRepoPushAction = (options) => {
52
52
  description: "Gitlab Project path"
53
53
  }),
54
54
  commitHash: (z) => z.string({
55
- description: "The git commit hash of the commit"
56
- })
55
+ description: "The git commit hash of the commit, or omitted when there were no file changes to commit and `allowEmpty` is not true (covers both the default of unset and an explicit `false`)."
56
+ }).optional()
57
57
  }
58
58
  },
59
59
  async handler(ctx) {
@@ -149,6 +149,14 @@ const createGitlabRepoPushAction = (options) => {
149
149
  );
150
150
  }
151
151
  }
152
+ if (actions.length === 0 && !allowEmpty) {
153
+ ctx.logger.warn(
154
+ `No file changes to commit to ${repoID} on branch '${branchName}'; skipping commit. Set 'allowEmpty: true' to create an empty commit.`
155
+ );
156
+ ctx.output("projectid", repoID);
157
+ ctx.output("projectPath", repoID);
158
+ return;
159
+ }
152
160
  try {
153
161
  const commitId = await ctx.checkpoint({
154
162
  key: `commit.create.${repoID}.${branchName}`,
@@ -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 path from 'node:path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport {\n createTemplateAction,\n parseRepoUrl,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { CommitAction } from '@gitbeaker/rest';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { getFileAction } from '../util';\nimport { SerializedFile } from '@backstage/plugin-scaffolder-node';\nimport { RepositoryTreeSchema } from '@gitbeaker/rest';\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 requireScmUserCredentials?: boolean;\n}) => {\n const { integrations, requireScmUserCredentials } = options;\n\n return createTemplateAction({\n id: 'gitlab:repo:push',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n }),\n branchName: z =>\n z.string({\n description: 'The branch name for the commit',\n }),\n commitMessage: z =>\n z.string({\n description: `The commit message`,\n }),\n sourcePath: z =>\n z\n .string({\n description:\n 'Subdirectory of working directory to copy changes from',\n })\n .optional(),\n targetPath: z =>\n z\n .string({\n description: 'Subdirectory of repository to apply changes to',\n })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n commitAction: z =>\n z\n .enum(['create', 'update', 'delete', 'auto'], {\n description:\n 'The action to be used for git commit. Defaults to create, but can be set to update or delete',\n })\n .optional(),\n allowEmpty: z =>\n z\n .boolean({\n description: 'Allow an empty commit to be created.',\n })\n .optional(),\n },\n output: {\n projectid: z =>\n z.string({\n description: 'Gitlab Project id/Name(slug)',\n }),\n projectPath: z =>\n z.string({\n description: 'Gitlab Project path',\n }),\n commitHash: z =>\n z.string({\n description: 'The git commit hash of the commit',\n }),\n },\n },\n async handler(ctx) {\n const {\n branchName,\n repoUrl,\n targetPath,\n sourcePath,\n token,\n commitAction,\n allowEmpty,\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 requireScmUserCredentials,\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 let remoteFiles: RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.allRepositoryTrees(repoID, {\n ref: branchName,\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: ${branchName}) : ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n const fileActionMap: {\n file: SerializedFile;\n action: 'create' | 'delete' | 'update' | 'skip';\n }[] = [];\n for (const file of fileContents) {\n const action = await getFileAction(\n { file, targetPath },\n { repoID, branch: branchName },\n api,\n ctx.logger,\n remoteFiles,\n ctx.input.commitAction,\n );\n fileActionMap.push({ file, action });\n }\n\n const actions: CommitAction[] = fileActionMap\n .filter(o => o.action !== 'skip')\n .map(({ file, action }) => ({\n action: action as CommitAction['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 const branchExists = await ctx.checkpoint({\n key: `branch.exists.${repoID}.${branchName}`,\n fn: async () => {\n try {\n await api.Branches.show(repoID, branchName);\n return true;\n } catch (e: any) {\n if (e.cause?.response?.status !== 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 return false;\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 commitId = await ctx.checkpoint({\n key: `commit.create.${repoID}.${branchName}`,\n fn: async () => {\n const commit =\n allowEmpty !== undefined\n ? await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n { allowEmpty } as any,\n )\n : await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n );\n return commit.id;\n },\n });\n\n ctx.output('projectid', repoID);\n ctx.output('projectPath', repoID);\n ctx.output('commitHash', commitId);\n } catch (e) {\n if (commitAction !== 'create') {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please verify that all files you're trying to modify exist in the repository. ${getErrorMessage(\n e,\n )}`,\n );\n }\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","getErrorMessage","getFileAction","path","InputError"],"mappings":";;;;;;;;;;;;;;AAqCO,MAAM,0BAAA,GAA6B,CAAC,OAAA,KAGrC;AACJ,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AAEpD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,kBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa,CAAA,sJAAA;AAAA,SACd,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa;AAAA,SACd,CAAA;AAAA,QACH,aAAA,EAAe,CAAA,CAAA,KACb,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa,CAAA,kBAAA;AAAA,SAC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MAAM,CAAA;AAC9B,QAAA,GAAA,CAAI,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAA,GAAA,CAAI,MAAA,CAAO,cAAc,QAAQ,CAAA;AAAA,MACnC,SAAS,CAAA,EAAG;AACV,QAAA,IAAI,iBAAiB,QAAA,EAAU;AAC7B,UAAA,MAAM,IAAIG,iBAAA;AAAA,YACR,CAAA,0BAAA,EAA6B,UAAU,CAAA,uFAAA,EAA0FH,uBAAA;AAAA,cAC/H;AAAA,aACD,CAAA;AAAA,WACH;AAAA,QACF;AACA,QAAA,MAAM,IAAIG,iBAAA;AAAA,UACR,CAAA,0BAAA,EAA6B,UAAU,CAAA,qFAAA,EAAwFH,uBAAA;AAAA,YAC7H;AAAA,WACD,CAAA;AAAA,SACH;AAAA,MACF;AAAA,IACF;AAAA,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 path from 'node:path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport {\n createTemplateAction,\n parseRepoUrl,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { CommitAction } from '@gitbeaker/rest';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { getFileAction } from '../util';\nimport { SerializedFile } from '@backstage/plugin-scaffolder-node';\nimport { RepositoryTreeSchema } from '@gitbeaker/rest';\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 requireScmUserCredentials?: boolean;\n}) => {\n const { integrations, requireScmUserCredentials } = options;\n\n return createTemplateAction({\n id: 'gitlab:repo:push',\n examples,\n schema: {\n input: {\n repoUrl: z =>\n z.string({\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n }),\n branchName: z =>\n z.string({\n description: 'The branch name for the commit',\n }),\n commitMessage: z =>\n z.string({\n description: `The commit message`,\n }),\n sourcePath: z =>\n z\n .string({\n description:\n 'Subdirectory of working directory to copy changes from',\n })\n .optional(),\n targetPath: z =>\n z\n .string({\n description: 'Subdirectory of repository to apply changes to',\n })\n .optional(),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n commitAction: z =>\n z\n .enum(['create', 'update', 'delete', 'auto'], {\n description:\n 'The action to be used for git commit. Defaults to create, but can be set to update or delete',\n })\n .optional(),\n allowEmpty: z =>\n z\n .boolean({\n description: 'Allow an empty commit to be created.',\n })\n .optional(),\n },\n output: {\n projectid: z =>\n z.string({\n description: 'Gitlab Project id/Name(slug)',\n }),\n projectPath: z =>\n z.string({\n description: 'Gitlab Project path',\n }),\n commitHash: z =>\n z\n .string({\n description:\n 'The git commit hash of the commit, or omitted when there were no file changes to commit and `allowEmpty` is not true (covers both the default of unset and an explicit `false`).',\n })\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n branchName,\n repoUrl,\n targetPath,\n sourcePath,\n token,\n commitAction,\n allowEmpty,\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 requireScmUserCredentials,\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 let remoteFiles: RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.allRepositoryTrees(repoID, {\n ref: branchName,\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: ${branchName}) : ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n const fileActionMap: {\n file: SerializedFile;\n action: 'create' | 'delete' | 'update' | 'skip';\n }[] = [];\n for (const file of fileContents) {\n const action = await getFileAction(\n { file, targetPath },\n { repoID, branch: branchName },\n api,\n ctx.logger,\n remoteFiles,\n ctx.input.commitAction,\n );\n fileActionMap.push({ file, action });\n }\n\n const actions: CommitAction[] = fileActionMap\n .filter(o => o.action !== 'skip')\n .map(({ file, action }) => ({\n action: action as CommitAction['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 const branchExists = await ctx.checkpoint({\n key: `branch.exists.${repoID}.${branchName}`,\n fn: async () => {\n try {\n await api.Branches.show(repoID, branchName);\n return true;\n } catch (e: any) {\n if (e.cause?.response?.status !== 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 return false;\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 if (actions.length === 0 && !allowEmpty) {\n ctx.logger.warn(\n `No file changes to commit to ${repoID} on branch '${branchName}'; skipping commit. Set 'allowEmpty: true' to create an empty commit.`,\n );\n ctx.output('projectid', repoID);\n ctx.output('projectPath', repoID);\n return;\n }\n\n try {\n const commitId = await ctx.checkpoint({\n key: `commit.create.${repoID}.${branchName}`,\n fn: async () => {\n const commit =\n allowEmpty !== undefined\n ? await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n { allowEmpty } as any,\n )\n : await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n );\n return commit.id;\n },\n });\n\n ctx.output('projectid', repoID);\n ctx.output('projectPath', repoID);\n ctx.output('commitHash', commitId);\n } catch (e) {\n if (commitAction !== 'create') {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please verify that all files you're trying to modify exist in the repository. ${getErrorMessage(\n e,\n )}`,\n );\n }\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","getErrorMessage","getFileAction","path","InputError"],"mappings":";;;;;;;;;;;;;;AAqCO,MAAM,0BAAA,GAA6B,CAAC,OAAA,KAGrC;AACJ,EAAA,MAAM,EAAE,YAAA,EAAc,yBAAA,EAA0B,GAAI,OAAA;AAEpD,EAAA,OAAOA,yCAAA,CAAqB;AAAA,IAC1B,EAAA,EAAI,kBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAA,EAAQ;AAAA,MACN,KAAA,EAAO;AAAA,QACL,OAAA,EAAS,CAAA,CAAA,KACP,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa,CAAA,sJAAA;AAAA,SACd,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CAAE,MAAA,CAAO;AAAA,UACP,WAAA,EAAa;AAAA,S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,IAAI,YAAY;AACd,YAAA,MAAM,MAAA,GACJ,UAAA,KAAe,KAAA,CAAA,GACX,MAAM,IAAI,OAAA,CAAQ,MAAA;AAAA,cAChB,MAAA;AAAA,cACA,UAAA;AAAA,cACA,IAAI,KAAA,CAAM,aAAA;AAAA,cACV,OAAA;AAAA,cACA,EAAE,UAAA;AAAW,aACf,GACA,MAAM,GAAA,CAAI,OAAA,CAAQ,MAAA;AAAA,cAChB,MAAA;AAAA,cACA,UAAA;AAAA,cACA,IAAI,KAAA,CAAM,aAAA;AAAA,cACV;AAAA,aACF;AACN,YAAA,OAAO,MAAA,CAAO,EAAA;AAAA,UAChB;AAAA,SACD,CAAA;AAED,QAAA,GAAA,CAAI,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAA,GAAA,CAAI,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAA,GAAA,CAAI,MAAA,CAAO,cAAc,QAAQ,CAAA;AAAA,MACnC,SAAS,CAAA,EAAG;AACV,QAAA,IAAI,iBAAiB,QAAA,EAAU;AAC7B,UAAA,MAAM,IAAIG,iBAAA;AAAA,YACR,CAAA,0BAAA,EAA6B,UAAU,CAAA,uFAAA,EAA0FH,uBAAA;AAAA,cAC/H;AAAA,aACD,CAAA;AAAA,WACH;AAAA,QACF;AACA,QAAA,MAAM,IAAIG,iBAAA;AAAA,UACR,CAAA,0BAAA,EAA6B,UAAU,CAAA,qFAAA,EAAwFH,uBAAA;AAAA,YAC7H;AAAA,WACD,CAAA;AAAA,SACH;AAAA,MACF;AAAA,IACF;AAAA,GACD,CAAA;AACH;;;;"}
package/dist/index.d.ts CHANGED
@@ -203,6 +203,7 @@ declare const createPublishGitlabMergeRequestAction: (options: {
203
203
  reviewers?: string[] | undefined;
204
204
  assignReviewersFromApprovalRules?: boolean | undefined;
205
205
  labels?: string | string[] | undefined;
206
+ autoMerge?: boolean | undefined;
206
207
  }, {
207
208
  targetBranchName: string;
208
209
  projectid: string;
@@ -317,7 +318,7 @@ declare const createGitlabRepoPushAction: (options: {
317
318
  }, {
318
319
  projectid: string;
319
320
  projectPath: string;
320
- commitHash: string;
321
+ commitHash?: string | undefined;
321
322
  }, "v2">;
322
323
 
323
324
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-gitlab",
3
- "version": "0.11.10",
3
+ "version": "0.11.11-next.1",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "scaffolder",
@@ -53,11 +53,11 @@
53
53
  "test": "backstage-cli package test"
54
54
  },
55
55
  "dependencies": {
56
- "@backstage/backend-plugin-api": "^1.10.0",
57
- "@backstage/config": "^1.3.8",
58
- "@backstage/errors": "^1.3.1",
59
- "@backstage/integration": "^2.1.1",
60
- "@backstage/plugin-scaffolder-node": "^0.13.6",
56
+ "@backstage/backend-plugin-api": "1.10.1-next.0",
57
+ "@backstage/config": "1.3.8",
58
+ "@backstage/errors": "1.3.1",
59
+ "@backstage/integration": "2.1.2-next.0",
60
+ "@backstage/plugin-scaffolder-node": "0.13.7-next.1",
61
61
  "@gitbeaker/core": "^43.8.0",
62
62
  "@gitbeaker/requester-utils": "^43.8.0",
63
63
  "@gitbeaker/rest": "^43.8.0",
@@ -66,8 +66,8 @@
66
66
  "zod": "^3.25.76 || ^4.0.0"
67
67
  },
68
68
  "devDependencies": {
69
- "@backstage/backend-test-utils": "^1.11.6",
70
- "@backstage/cli": "^0.36.5",
71
- "@backstage/plugin-scaffolder-node-test-utils": "^0.3.14"
69
+ "@backstage/backend-test-utils": "1.11.7-next.0",
70
+ "@backstage/cli": "0.36.6-next.0",
71
+ "@backstage/plugin-scaffolder-node-test-utils": "0.3.15-next.1"
72
72
  }
73
73
  }