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

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,30 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
+ ## 0.8.0-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/plugin-scaffolder-node@0.7.0-next.2
9
+ - @backstage/backend-plugin-api@1.2.0-next.2
10
+ - @backstage/config@1.3.2
11
+ - @backstage/errors@1.2.7
12
+ - @backstage/integration@1.16.1
13
+
14
+ ## 0.8.0-next.2
15
+
16
+ ### Patch Changes
17
+
18
+ - 9d04e91: Fix automated assignment of reviewers for instances without premium/ultimate license (404). Introduce opt-in flag for automatic reviewer assignment based on approval rules
19
+ - 9545c5f: `createGitlabProjectMigrateAction` can now output the `migrationId`
20
+ - fe44946: Fixed bug of passing wrong value to `onChange` handler when using `GitLab` autocomplete
21
+ - Updated dependencies
22
+ - @backstage/backend-plugin-api@1.2.0-next.1
23
+ - @backstage/config@1.3.2
24
+ - @backstage/errors@1.2.7
25
+ - @backstage/integration@1.16.1
26
+ - @backstage/plugin-scaffolder-node@0.7.0-next.1
27
+
3
28
  ## 0.8.0-next.1
4
29
 
5
30
  ### Minor Changes
@@ -41,6 +41,34 @@ async function getFileAction(fileInfo, target, api, logger, remoteFiles, default
41
41
  }
42
42
  return defaultCommitAction;
43
43
  }
44
+ async function getReviewersFromApprovalRules(api, mergerequestIId, repoID, ctx) {
45
+ try {
46
+ let mergeRequest = await api.MergeRequests.show(
47
+ repoID,
48
+ mergerequestIId
49
+ );
50
+ while (mergeRequest.detailed_merge_status === "preparing" || mergeRequest.detailed_merge_status === "approvals_syncing" || mergeRequest.detailed_merge_status === "checking") {
51
+ mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);
52
+ ctx.logger.info(`${mergeRequest.detailed_merge_status}`);
53
+ }
54
+ const approvalRules = await api.MergeRequestApprovals.allApprovalRules(
55
+ repoID,
56
+ {
57
+ mergerequestIId: mergeRequest.iid
58
+ }
59
+ );
60
+ return approvalRules.filter((rule) => rule.eligible_approvers !== void 0).map((rule) => {
61
+ return rule.eligible_approvers;
62
+ }).flat().map((user) => user.id);
63
+ } catch (e) {
64
+ ctx.logger.warn(
65
+ `Failed to retrieve approval rules for MR ${mergerequestIId}: ${helpers.getErrorMessage(
66
+ e
67
+ )}. Proceeding with MR creation without reviewers from approval rules.`
68
+ );
69
+ return [];
70
+ }
71
+ }
44
72
  const createPublishGitlabMergeRequestAction = (options) => {
45
73
  const { integrations } = options;
46
74
  return pluginScaffolderNode.createTemplateAction({
@@ -121,6 +149,11 @@ which uses additional API calls in order to detect whether to 'create', 'update'
121
149
  type: "string"
122
150
  },
123
151
  description: "Users that will be assigned as reviewers"
152
+ },
153
+ assignReviewersFromApprovalRules: {
154
+ title: "Assign reviewers from approval rules",
155
+ type: "boolean",
156
+ description: "Automatically assign reviewers from the approval rules of the MR. Includes Codeowners"
124
157
  }
125
158
  }
126
159
  },
@@ -307,31 +340,34 @@ which uses additional API calls in order to detect whether to 'create', 'update'
307
340
  reviewerIds
308
341
  }
309
342
  );
310
- while (mergeRequest.detailed_merge_status === "preparing" || mergeRequest.detailed_merge_status === "approvals_syncing" || mergeRequest.detailed_merge_status === "checking") {
311
- mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);
312
- ctx.logger.info(`${mergeRequest.detailed_merge_status}`);
313
- }
314
- const approvalRules = await api.MergeRequestApprovals.allApprovalRules(
315
- repoID,
316
- {
317
- mergerequestIId: mergeRequest.iid
318
- }
319
- );
320
- if (approvalRules.length !== 0) {
321
- const eligibleApprovers = approvalRules.filter((rule) => rule.eligible_approvers !== void 0).map((rule) => {
322
- return rule.eligible_approvers;
323
- }).flat();
324
- const eligibleUserIds = /* @__PURE__ */ new Set([
325
- ...eligibleApprovers.map((user) => user.id),
326
- ...reviewerIds ?? []
327
- ]);
328
- mergeRequest = await api.MergeRequests.edit(
329
- repoID,
330
- mergeRequest.iid,
331
- {
332
- reviewerIds: Array.from(eligibleUserIds)
343
+ if (ctx.input.assignReviewersFromApprovalRules) {
344
+ try {
345
+ const reviewersFromApprovalRules = await getReviewersFromApprovalRules(
346
+ api,
347
+ mergeRequest.iid,
348
+ repoID,
349
+ ctx
350
+ );
351
+ if (reviewersFromApprovalRules.length > 0) {
352
+ const eligibleUserIds = /* @__PURE__ */ new Set([
353
+ ...reviewersFromApprovalRules,
354
+ ...reviewerIds ?? []
355
+ ]);
356
+ mergeRequest = await api.MergeRequests.edit(
357
+ repoID,
358
+ mergeRequest.iid,
359
+ {
360
+ reviewerIds: Array.from(eligibleUserIds)
361
+ }
362
+ );
333
363
  }
334
- );
364
+ } catch (e) {
365
+ ctx.logger.warn(
366
+ `Failed to assign reviewers from approval rules: ${helpers.getErrorMessage(
367
+ e
368
+ )}.`
369
+ );
370
+ }
335
371
  }
336
372
  ctx.output("projectid", repoID);
337
373
  ctx.output("targetBranchName", targetBranch);
@@ -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 Gitlab,\n RepositoryTreeSchema,\n CommitAction,\n SimpleUserSchema,\n} from '@gitbeaker/rest';\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: InstanceType<typeof Gitlab>,\n logger: LoggerService,\n remoteFiles: 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 reviewers?: 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 reviewers: {\n title: 'Merge Request Reviewers',\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Users that will be assigned as reviewers',\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 reviewers,\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.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 explicity 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: 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 let mergeRequest = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,\n assigneeId,\n reviewerIds,\n },\n );\n\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 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 if (approvalRules.length !== 0) {\n const eligibleApprovers = approvalRules\n .filter(rule => rule.eligible_approvers !== undefined)\n .map(rule => {\n return rule.eligible_approvers as SimpleUserSchema[];\n })\n .flat();\n\n const eligibleUserIds = new Set([\n ...eligibleApprovers.map(user => user.id),\n ...(reviewerIds ?? []),\n ]);\n\n mergeRequest = await api.MergeRequests.edit(\n repoID,\n mergeRequest.iid,\n {\n reviewerIds: Array.from(eligibleUserIds),\n },\n );\n }\n\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output(\n 'mergeRequestUrl',\n 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"],"names":["createHash","path","createTemplateAction","examples","parseRepoUrl","createGitlabApi","getErrorMessage","resolveSafeChildPath","serializeDirectoryContents","InputError"],"mappings":";;;;;;;;;;;;;;AAuCA,SAAS,cAAc,IAA8B,EAAA;AACnD,EAAM,MAAA,IAAA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AAA,CAAA,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA;AAAA,UACF,iBAAA;AAAA,UACA,YAAA,CAAa,WAAW,YAAa,CAAA;AAAA,SACvC;AAAA,eACO,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;;;;"}
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 Gitlab,\n RepositoryTreeSchema,\n CommitAction,\n SimpleUserSchema,\n ExpandedMergeRequestSchema,\n Camelize,\n} from '@gitbeaker/rest';\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: InstanceType<typeof Gitlab>,\n logger: LoggerService,\n remoteFiles: 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\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\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 reviewers?: string[];\n assignReviewersFromApprovalRules?: boolean;\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 reviewers: {\n title: 'Merge Request Reviewers',\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Users that will be assigned as reviewers',\n },\n assignReviewersFromApprovalRules: {\n title: 'Assign reviewers from approval rules',\n type: 'boolean',\n description:\n 'Automatically assign reviewers from the approval rules of the MR. Includes Codeowners',\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 reviewers,\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.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 explicity 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: 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 let mergeRequest = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,\n assigneeId,\n reviewerIds,\n },\n );\n\n if (ctx.input.assignReviewersFromApprovalRules) {\n try {\n const reviewersFromApprovalRules =\n await getReviewersFromApprovalRules(\n api,\n mergeRequest.iid,\n repoID,\n ctx,\n );\n if (reviewersFromApprovalRules.length > 0) {\n const eligibleUserIds = new Set([\n ...reviewersFromApprovalRules,\n ...(reviewerIds ?? []),\n ]);\n\n mergeRequest = await api.MergeRequests.edit(\n repoID,\n mergeRequest.iid,\n {\n reviewerIds: Array.from(eligibleUserIds),\n },\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 ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output(\n 'mergeRequestUrl',\n 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"],"names":["createHash","path","getErrorMessage","createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","InputError"],"mappings":";;;;;;;;;;;;;;AAyCA,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;AA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,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA;AAAA,UACF,iBAAA;AAAA,UACA,YAAA,CAAa,WAAW,YAAa,CAAA;AAAA,SACvC;AAAA,eACO,CAAG,EAAA;AACV,QAAA,MAAM,IAAIO,iBAAA;AAAA,UACR,CAAA,+BAAA,EAAkCP,uBAAgB,CAAA,CAAC,CAAC,CAAA;AAAA,SACtD;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -54,6 +54,10 @@ const createGitlabProjectMigrateAction = (options) => {
54
54
  importedRepoUrl: {
55
55
  title: "URL to the newly imported repo",
56
56
  type: "string"
57
+ },
58
+ migrationId: {
59
+ title: "Id of the migration that imports the project",
60
+ type: "number"
57
61
  }
58
62
  }
59
63
  }
@@ -94,17 +98,21 @@ const createGitlabProjectMigrateAction = (options) => {
94
98
  access_token: sourceAccessToken
95
99
  };
96
100
  try {
97
- await api.Migrations.create(sourceConfig, migrationEntity);
101
+ const { id: migrationId } = await api.Migrations.create(
102
+ sourceConfig,
103
+ migrationEntity
104
+ );
105
+ ctx.output(
106
+ "importedRepoUrl",
107
+ `${destinationHost}/${destinationNamespace}/${destinationSlug}`
108
+ );
109
+ ctx.output("migrationId", migrationId);
98
110
  } catch (e) {
99
111
  throw new errors.InputError(
100
112
  `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.
101
113
  Error: ${e}`
102
114
  );
103
115
  }
104
- ctx.output(
105
- "importedRepoUrl",
106
- `${destinationHost}/${destinationNamespace}/${destinationSlug}`
107
- );
108
116
  }
109
117
  });
110
118
  };
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n await api.Migrations.create(sourceConfig, migrationEntity);\n } catch (e: any) {\n throw new InputError(\n `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.\\nError: ${e}`,\n );\n }\n\n ctx.output(\n 'importedRepoUrl',\n `${destinationHost}/${destinationNamespace}/${destinationSlug}`,\n );\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","createGitlabApi"],"mappings":";;;;;;;AA+Ba,MAAA,gCAAA,GAAmC,CAAC,OAE3C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAMJ,CAAA;AAAA,IACD,EAAI,EAAA,sBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAU,EAAA;AAAA,UACR,wBAAA;AAAA,UACA,gBAAA;AAAA,UACA,mBAAA;AAAA,UACA,gBAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA,IAAM,EAAA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AAM,IAAIC,iBAAA;AAAA,UACR,CAAA,sJAAA;AAAA,SACF;AAAA;AAGF,MAAA,MAAM,MAAMC,uBAAgB,CAAA;AAAA,QAC1B,YAAA;AAAA,QACA,KAAO,EAAA,sBAAA;AAAA,QACP,OAAS,EAAA;AAAA,OACV,CAAA;AAED,MAAA,MAAM,eAA4C,GAAA;AAAA,QAChD;AAAA,UACE,UAAY,EAAA,gBAAA;AAAA,UACZ,cAAA;AAAA,UACA,eAAA;AAAA,UACA;AAAA;AACF,OACF;AAEA,MAAA,MAAM,YAAe,GAAA;AAAA,QACnB,GAAK,EAAA,SAAA;AAAA,QACL,YAAc,EAAA;AAAA,OAChB;AAEA,MAAI,IAAA;AACF,QAAA,MAAM,GAAI,CAAA,UAAA,CAAW,MAAO,CAAA,YAAA,EAAc,eAAe,CAAA;AAAA,eAClD,CAAQ,EAAA;AACf,QAAA,MAAM,IAAID,iBAAA;AAAA,UACR,CAA2B,wBAAA,EAAA,cAAc,CAAoB,iBAAA,EAAA,cAAc,cAAc,SAAS,CAAA;AAAA,OAAA,EAA0C,CAAC,CAAA;AAAA,SAC/I;AAAA;AAGF,MAAI,GAAA,CAAA,MAAA;AAAA,QACF,iBAAA;AAAA,QACA,CAAG,EAAA,eAAe,CAAI,CAAA,EAAA,oBAAoB,IAAI,eAAe,CAAA;AAAA,OAC/D;AAAA;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n migrationId: {\n title: 'Id of the migration that imports the project',\n type: 'number',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n const { id: migrationId } = await api.Migrations.create(\n sourceConfig,\n migrationEntity,\n );\n\n ctx.output(\n 'importedRepoUrl',\n `${destinationHost}/${destinationNamespace}/${destinationSlug}`,\n );\n ctx.output('migrationId', migrationId);\n } catch (e: any) {\n throw new InputError(\n `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.\\nError: ${e}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","createGitlabApi"],"mappings":";;;;;;;AA+Ba,MAAA,gCAAA,GAAmC,CAAC,OAE3C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAMJ,CAAA;AAAA,IACD,EAAI,EAAA,sBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAU,EAAA;AAAA,UACR,wBAAA;AAAA,UACA,gBAAA;AAAA,UACA,mBAAA;AAAA,UACA,gBAAA;AAAA,UACA;AAAA,SACF;AAAA,QACA,IAAM,EAAA,QAAA;AAAA,QACN,UAAY,EAAA;AAAA,UACV,sBAAwB,EAAA;AAAA,YACtB,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,gCAAA;AAAA,YACP,WAAa,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AA,SACF;AAAA;AAGF,MAAA,MAAM,MAAMC,uBAAgB,CAAA;AAAA,QAC1B,YAAA;AAAA,QACA,KAAO,EAAA,sBAAA;AAAA,QACP,OAAS,EAAA;AAAA,OACV,CAAA;AAED,MAAA,MAAM,eAA4C,GAAA;AAAA,QAChD;AAAA,UACE,UAAY,EAAA,gBAAA;AAAA,UACZ,cAAA;AAAA,UACA,eAAA;AAAA,UACA;AAAA;AACF,OACF;AAEA,MAAA,MAAM,YAAe,GAAA;AAAA,QACnB,GAAK,EAAA,SAAA;AAAA,QACL,YAAc,EAAA;AAAA,OAChB;AAEA,MAAI,IAAA;AACF,QAAA,MAAM,EAAE,EAAI,EAAA,WAAA,EAAgB,GAAA,MAAM,IAAI,UAAW,CAAA,MAAA;AAAA,UAC/C,YAAA;AAAA,UACA;AAAA,SACF;AAEA,QAAI,GAAA,CAAA,MAAA;AAAA,UACF,iBAAA;AAAA,UACA,CAAG,EAAA,eAAe,CAAI,CAAA,EAAA,oBAAoB,IAAI,eAAe,CAAA;AAAA,SAC/D;AACA,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,WAAW,CAAA;AAAA,eAC9B,CAAQ,EAAA;AACf,QAAA,MAAM,IAAID,iBAAA;AAAA,UACR,CAA2B,wBAAA,EAAA,cAAc,CAAoB,iBAAA,EAAA,cAAc,cAAc,SAAS,CAAA;AAAA,OAAA,EAA0C,CAAC,CAAA;AAAA,SAC/I;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -57,7 +57,7 @@ function createHandleAutocompleteRequest(options) {
57
57
  return {
58
58
  results: response.map((project) => ({
59
59
  title: project.name.trim(),
60
- id: project.id.toString()
60
+ id: project.path
61
61
  }))
62
62
  };
63
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"autocomplete.cjs.js","sources":["../../src/autocomplete/autocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getClient } from '../util';\n\nexport function createHandleAutocompleteRequest(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n return async function handleAutocompleteRequest({\n resource,\n token,\n context,\n }: {\n resource: string;\n token: string;\n context: Record<string, string>;\n }): Promise<{\n results: {\n title?: string;\n id: string;\n }[];\n }> {\n const { integrations } = options;\n const client = getClient({\n host: context.host ?? 'gitlab.com',\n integrations,\n token,\n });\n\n switch (resource) {\n case 'groups': {\n let groups: any[] = [];\n let page = 1;\n const perPage = 100;\n let response = [];\n let continueFetch = true;\n while (continueFetch) {\n response = await client.Groups.all({\n pagination: 'offset',\n page,\n perPage,\n });\n\n groups = groups.concat(response);\n if (response.length < perPage) continueFetch = false;\n page++;\n }\n\n const result: {\n results: {\n title: string;\n id: string;\n }[];\n } = {\n results: groups.map(group => ({\n title: group.full_path,\n id: group.id.toString(),\n })),\n };\n // append also user context\n const user = await client.Users.showCurrentUser();\n result.results.push({\n title: user.username,\n id: user.id.toString(),\n });\n\n return result;\n }\n case 'repositories': {\n if (!context.id)\n throw new InputError('Missing groupId and userId context parameter');\n\n let response;\n if (\n context.id === (await client.Users.showCurrentUser())?.id.toString()\n ) {\n response = await client.Users.allProjects(context.id);\n } else {\n response = await client.Groups.allProjects(context.id);\n }\n\n return {\n results: response.map(project => ({\n title: project.name.trim(),\n id: project.id.toString(),\n })),\n };\n }\n default:\n throw new InputError(`Invalid resource: ${resource}`);\n }\n };\n}\n"],"names":["getClient","InputError"],"mappings":";;;;;AAoBO,SAAS,gCAAgC,OAE7C,EAAA;AACD,EAAA,OAA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,QAAS;AAAA,SACtB,CAAA;AAED,QAAO,OAAA,MAAA;AAAA;AACT,MACA,KAAK,cAAgB,EAAA;AACnB,QAAA,IAAI,CAAC,OAAQ,CAAA,EAAA;AACX,UAAM,MAAA,IAAIC,kBAAW,8CAA8C,CAAA;AAErE,QAAI,IAAA,QAAA;AACJ,QACE,IAAA,OAAA,CAAQ,QAAQ,MAAM,MAAA,CAAO,MAAM,eAAgB,EAAA,GAAI,EAAG,CAAA,QAAA,EAC1D,EAAA;AACA,UAAA,QAAA,GAAW,MAAM,MAAA,CAAO,KAAM,CAAA,WAAA,CAAY,QAAQ,EAAE,CAAA;AAAA,SAC/C,MAAA;AACL,UAAA,QAAA,GAAW,MAAM,MAAA,CAAO,MAAO,CAAA,WAAA,CAAY,QAAQ,EAAE,CAAA;AAAA;AAGvD,QAAO,OAAA;AAAA,UACL,OAAA,EAAS,QAAS,CAAA,GAAA,CAAI,CAAY,OAAA,MAAA;AAAA,YAChC,KAAA,EAAO,OAAQ,CAAA,IAAA,CAAK,IAAK,EAAA;AAAA,YACzB,EAAA,EAAI,OAAQ,CAAA,EAAA,CAAG,QAAS;AAAA,WACxB,CAAA;AAAA,SACJ;AAAA;AACF,MACA;AACE,QAAA,MAAM,IAAIA,iBAAA,CAAW,CAAqB,kBAAA,EAAA,QAAQ,CAAE,CAAA,CAAA;AAAA;AACxD,GACF;AACF;;;;"}
1
+ {"version":3,"file":"autocomplete.cjs.js","sources":["../../src/autocomplete/autocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getClient } from '../util';\n\nexport function createHandleAutocompleteRequest(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n return async function handleAutocompleteRequest({\n resource,\n token,\n context,\n }: {\n resource: string;\n token: string;\n context: Record<string, string>;\n }): Promise<{\n results: {\n title?: string;\n id: string;\n }[];\n }> {\n const { integrations } = options;\n const client = getClient({\n host: context.host ?? 'gitlab.com',\n integrations,\n token,\n });\n\n switch (resource) {\n case 'groups': {\n let groups: any[] = [];\n let page = 1;\n const perPage = 100;\n let response = [];\n let continueFetch = true;\n while (continueFetch) {\n response = await client.Groups.all({\n pagination: 'offset',\n page,\n perPage,\n });\n\n groups = groups.concat(response);\n if (response.length < perPage) continueFetch = false;\n page++;\n }\n\n const result: {\n results: {\n title: string;\n id: string;\n }[];\n } = {\n results: groups.map(group => ({\n title: group.full_path,\n id: group.id.toString(),\n })),\n };\n // append also user context\n const user = await client.Users.showCurrentUser();\n result.results.push({\n title: user.username,\n id: user.id.toString(),\n });\n\n return result;\n }\n case 'repositories': {\n if (!context.id)\n throw new InputError('Missing groupId and userId context parameter');\n\n let response;\n if (\n context.id === (await client.Users.showCurrentUser())?.id.toString()\n ) {\n response = await client.Users.allProjects(context.id);\n } else {\n response = await client.Groups.allProjects(context.id);\n }\n\n return {\n results: response.map(project => ({\n title: project.name.trim(),\n id: project.path,\n })),\n };\n }\n default:\n throw new InputError(`Invalid resource: ${resource}`);\n }\n };\n}\n"],"names":["getClient","InputError"],"mappings":";;;;;AAoBO,SAAS,gCAAgC,OAE7C,EAAA;AACD,EAAA,OAAO,eAAe,yBAA0B,CAAA;AAAA,IAC9C,QAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GAUC,EAAA;AACD,IAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,IAAA,MAAM,SAASA,cAAU,CAAA;AAAA,MACvB,IAAA,EAAM,QAAQ,IAAQ,IAAA,YAAA;AAAA,MACtB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AAQ,MAAM,MAAA,CAAO,MAAM,eAAgB,EAAA,GAAI,EAAG,CAAA,QAAA,EAC1D,EAAA;AACA,UAAA,QAAA,GAAW,MAAM,MAAA,CAAO,KAAM,CAAA,WAAA,CAAY,QAAQ,EAAE,CAAA;AAAA,SAC/C,MAAA;AACL,UAAA,QAAA,GAAW,MAAM,MAAA,CAAO,MAAO,CAAA,WAAA,CAAY,QAAQ,EAAE,CAAA;AAAA;AAGvD,QAAO,OAAA;AAAA,UACL,OAAA,EAAS,QAAS,CAAA,GAAA,CAAI,CAAY,OAAA,MAAA;AAAA,YAChC,KAAA,EAAO,OAAQ,CAAA,IAAA,CAAK,IAAK,EAAA;AAAA,YACzB,IAAI,OAAQ,CAAA;AAAA,WACZ,CAAA;AAAA,SACJ;AAAA;AACF,MACA;AACE,QAAA,MAAM,IAAIA,iBAAA,CAAW,CAAqB,kBAAA,EAAA,QAAQ,CAAE,CAAA,CAAA;AAAA;AACxD,GACF;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -188,6 +188,7 @@ declare const createPublishGitlabMergeRequestAction: (options: {
188
188
  removeSourceBranch?: boolean | undefined;
189
189
  assignee?: string | undefined;
190
190
  reviewers?: string[] | undefined;
191
+ assignReviewersFromApprovalRules?: boolean | undefined;
191
192
  }, _backstage_types.JsonObject>;
192
193
 
193
194
  /**
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-gitlab",
3
- "version": "0.8.0-next.1",
3
+ "version": "0.8.0-next.3",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "scaffolder",
7
- "pluginPackage": "@backstage/plugin-scaffolder-backend"
7
+ "pluginPackage": "@backstage/plugin-scaffolder-backend",
8
+ "features": {
9
+ ".": "@backstage/BackendFeature"
10
+ }
8
11
  },
9
12
  "publishConfig": {
10
13
  "access": "public"
@@ -51,11 +54,11 @@
51
54
  },
52
55
  "dependencies": {
53
56
  "@backstage/backend-common": "^0.25.0",
54
- "@backstage/backend-plugin-api": "1.2.0-next.0",
57
+ "@backstage/backend-plugin-api": "1.2.0-next.2",
55
58
  "@backstage/config": "1.3.2",
56
59
  "@backstage/errors": "1.2.7",
57
60
  "@backstage/integration": "1.16.1",
58
- "@backstage/plugin-scaffolder-node": "0.7.0-next.0",
61
+ "@backstage/plugin-scaffolder-node": "0.7.0-next.2",
59
62
  "@gitbeaker/rest": "^41.2.0",
60
63
  "luxon": "^3.0.0",
61
64
  "winston": "^3.2.1",
@@ -63,9 +66,9 @@
63
66
  "zod": "^3.22.4"
64
67
  },
65
68
  "devDependencies": {
66
- "@backstage/backend-test-utils": "1.3.0-next.1",
67
- "@backstage/cli": "0.30.0-next.1",
69
+ "@backstage/backend-test-utils": "1.3.0-next.3",
70
+ "@backstage/cli": "0.30.0-next.3",
68
71
  "@backstage/core-app-api": "1.15.5-next.0",
69
- "@backstage/plugin-scaffolder-node-test-utils": "0.1.19-next.1"
72
+ "@backstage/plugin-scaffolder-node-test-utils": "0.1.19-next.3"
70
73
  }
71
74
  }