@backstage/plugin-scaffolder-backend-module-gitlab 0.11.10-next.0 → 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 +11 -0
- package/dist/actions/gitlab.cjs.js +13 -0
- package/dist/actions/gitlab.cjs.js.map +1 -1
- package/dist/actions/gitlabGroupAccessAction.cjs.js +7 -2
- package/dist/actions/gitlabGroupAccessAction.cjs.js.map +1 -1
- package/dist/actions/gitlabGroupEnsureExists.cjs.js +7 -2
- package/dist/actions/gitlabGroupEnsureExists.cjs.js.map +1 -1
- package/dist/actions/gitlabIssueCreate.cjs.js +7 -2
- package/dist/actions/gitlabIssueCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabIssueEdit.cjs.js +7 -2
- package/dist/actions/gitlabIssueEdit.cjs.js.map +1 -1
- package/dist/actions/gitlabMergeRequest.cjs.js +28 -4
- package/dist/actions/gitlabMergeRequest.cjs.js.map +1 -1
- package/dist/actions/gitlabMergeRequest.examples.cjs.js +19 -0
- package/dist/actions/gitlabMergeRequest.examples.cjs.js.map +1 -1
- package/dist/actions/gitlabPipelineTrigger.cjs.js +7 -2
- package/dist/actions/gitlabPipelineTrigger.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js +6 -8
- package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js +7 -2
- package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectVariableCreate.cjs.js +7 -2
- package/dist/actions/gitlabProjectVariableCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabRepoPush.cjs.js +3 -2
- package/dist/actions/gitlabRepoPush.cjs.js.map +1 -1
- package/dist/actions/helpers.cjs.js +11 -1
- package/dist/actions/helpers.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/module.cjs.js +35 -10
- package/dist/module.cjs.js.map +1 -1
- package/dist/util.cjs.js +12 -2
- package/dist/util.cjs.js.map +1 -1
- package/package.json +6 -6
|
@@ -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}) => {\n const { integrations } = 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 });\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,KAErC;AACJ,EAAA,MAAM,EAAE,cAAa,GAAI,OAAA;AAEzB,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,SACd,CAAA;AAAA,QACH,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EACE;AAAA,SACH,EACA,QAAA,EAAS;AAAA,QACd,UAAA,EAAY,CAAA,CAAA,KACV,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EAAa;AAAA,SACd,EACA,QAAA,EAAS;AAAA,QACd,KAAA,EAAO,CAAA,CAAA,KACL,CAAA,CACG,MAAA,CAAO;AAAA,UACN,WAAA,EAAa;AAAA,SACd,EACA,QAAA,EAAS;AAAA,QACd,YAAA,EAAc,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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,SACd,CAAA;AAAA,QACH,aAAA,EAAe,CAA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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;;;;"}
|
|
@@ -5,7 +5,12 @@ var errors = require('@backstage/errors');
|
|
|
5
5
|
var rest = require('@gitbeaker/rest');
|
|
6
6
|
|
|
7
7
|
function createGitlabApi(options) {
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
integrations,
|
|
10
|
+
token: providedToken,
|
|
11
|
+
repoUrl,
|
|
12
|
+
requireScmUserCredentials
|
|
13
|
+
} = options;
|
|
9
14
|
const { host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
10
15
|
const integrationConfig = integrations.gitlab.byHost(host);
|
|
11
16
|
if (!integrationConfig) {
|
|
@@ -13,6 +18,11 @@ function createGitlabApi(options) {
|
|
|
13
18
|
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
14
19
|
);
|
|
15
20
|
}
|
|
21
|
+
if (requireScmUserCredentials && !providedToken) {
|
|
22
|
+
throw new errors.InputError(
|
|
23
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
16
26
|
if (!integrationConfig.config.token && !providedToken) {
|
|
17
27
|
throw new errors.InputError(`No token available for host ${host}`);
|
|
18
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { parseRepoUrl } from '@backstage/plugin-scaffolder-node';\nimport { ErrorLike, InputError, isError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Gitlab } from '@gitbeaker/rest';\nimport { GitbeakerRequestError } from '@gitbeaker/requester-utils';\n\nexport function createGitlabApi(options: {\n integrations: ScmIntegrationRegistry;\n token?: string;\n repoUrl: string;\n}): InstanceType<typeof Gitlab> {\n const {
|
|
1
|
+
{"version":3,"file":"helpers.cjs.js","sources":["../../src/actions/helpers.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { parseRepoUrl } from '@backstage/plugin-scaffolder-node';\nimport { ErrorLike, InputError, isError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Gitlab } from '@gitbeaker/rest';\nimport { GitbeakerRequestError } from '@gitbeaker/requester-utils';\n\nexport function createGitlabApi(options: {\n integrations: ScmIntegrationRegistry;\n token?: string;\n repoUrl: string;\n requireScmUserCredentials?: boolean;\n}): InstanceType<typeof Gitlab> {\n const {\n integrations,\n token: providedToken,\n repoUrl,\n requireScmUserCredentials,\n } = options;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (requireScmUserCredentials && !providedToken) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n if (!integrationConfig.config.token && !providedToken) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = providedToken ?? integrationConfig.config.token!;\n const tokenType = providedToken ? 'oauthToken' : 'token';\n\n return new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n}\n\ninterface GitlabError extends ErrorLike {\n // Errors from Gitlab may also include a description field that contains additional info\n description: string;\n}\n\nfunction isGitlabError(e: unknown): e is GitlabError {\n return isError(e) && 'description' in e && typeof e.description === 'string';\n}\n\nfunction isGitbeakerRequestError(e: unknown): e is GitbeakerRequestError {\n return isError(e) && e.name === 'GitbeakerRequestError';\n}\n\nexport function getErrorMessage(e: unknown): string {\n if (isGitbeakerRequestError(e) && e.cause)\n return `${e} - ${e.cause.description}`;\n if (isGitlabError(e)) return `${e} - ${e.description}`;\n return String(e);\n}\n"],"names":["parseRepoUrl","InputError","Gitlab","isError"],"mappings":";;;;;;AAqBO,SAAS,gBAAgB,OAAA,EAKA;AAC9B,EAAA,MAAM;AAAA,IACJ,YAAA;AAAA,IACA,KAAA,EAAO,aAAA;AAAA,IACP,OAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,EAAE,IAAA,EAAK,GAAIA,iCAAA,CAAa,SAAS,YAAY,CAAA;AAEnD,EAAA,MAAM,iBAAA,GAAoB,YAAA,CAAa,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA;AAEzD,EAAA,IAAI,CAAC,iBAAA,EAAmB;AACtB,IAAA,MAAM,IAAIC,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA,EACF;AAEA,EAAA,IAAI,yBAAA,IAA6B,CAAC,aAAA,EAAe;AAC/C,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,yCAAyC,IAAI,CAAA,qDAAA;AAAA,KAC/C;AAAA,EACF;AAEA,EAAA,IAAI,CAAC,iBAAA,CAAkB,MAAA,CAAO,KAAA,IAAS,CAAC,aAAA,EAAe;AACrD,IAAA,MAAM,IAAIA,iBAAA,CAAW,CAAA,4BAAA,EAA+B,IAAI,CAAA,CAAE,CAAA;AAAA,EAC5D;AAEA,EAAA,MAAM,KAAA,GAAQ,aAAA,IAAiB,iBAAA,CAAkB,MAAA,CAAO,KAAA;AACxD,EAAA,MAAM,SAAA,GAAY,gBAAgB,YAAA,GAAe,OAAA;AAEjD,EAAA,OAAO,IAAIC,WAAA,CAAO;AAAA,IAChB,IAAA,EAAM,kBAAkB,MAAA,CAAO,OAAA;AAAA,IAC/B,CAAC,SAAS,GAAG;AAAA,GACd,CAAA;AACH;AAOA,SAAS,cAAc,CAAA,EAA8B;AACnD,EAAA,OAAOC,eAAQ,CAAC,CAAA,IAAK,iBAAiB,CAAA,IAAK,OAAO,EAAE,WAAA,KAAgB,QAAA;AACtE;AAEA,SAAS,wBAAwB,CAAA,EAAwC;AACvE,EAAA,OAAOA,cAAA,CAAQ,CAAC,CAAA,IAAK,CAAA,CAAE,IAAA,KAAS,uBAAA;AAClC;AAEO,SAAS,gBAAgB,CAAA,EAAoB;AAClD,EAAA,IAAI,uBAAA,CAAwB,CAAC,CAAA,IAAK,CAAA,CAAE,KAAA;AAClC,IAAA,OAAO,CAAA,EAAG,CAAC,CAAA,GAAA,EAAM,CAAA,CAAE,MAAM,WAAW,CAAA,CAAA;AACtC,EAAA,IAAI,aAAA,CAAc,CAAC,CAAA,EAAG,OAAO,GAAG,CAAC,CAAA,GAAA,EAAM,EAAE,WAAW,CAAA,CAAA;AACpD,EAAA,OAAO,OAAO,CAAC,CAAA;AACjB;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ declare function createPublishGitlabAction(options: {
|
|
|
72
72
|
*/
|
|
73
73
|
declare const createGitlabGroupEnsureExistsAction: (options: {
|
|
74
74
|
integrations: ScmIntegrationRegistry;
|
|
75
|
+
requireScmUserCredentials?: boolean;
|
|
75
76
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
76
77
|
repoUrl: string;
|
|
77
78
|
path: (string | {
|
|
@@ -91,6 +92,7 @@ declare const createGitlabGroupEnsureExistsAction: (options: {
|
|
|
91
92
|
*/
|
|
92
93
|
declare const createGitlabGroupAccessAction: (options: {
|
|
93
94
|
integrations: ScmIntegrationRegistry;
|
|
95
|
+
requireScmUserCredentials?: boolean;
|
|
94
96
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
95
97
|
repoUrl: string;
|
|
96
98
|
path: string | number;
|
|
@@ -114,6 +116,7 @@ declare const createGitlabGroupAccessAction: (options: {
|
|
|
114
116
|
*/
|
|
115
117
|
declare const createGitlabIssueAction: (options: {
|
|
116
118
|
integrations: ScmIntegrationRegistry;
|
|
119
|
+
requireScmUserCredentials?: boolean;
|
|
117
120
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
118
121
|
repoUrl: string;
|
|
119
122
|
projectId: number;
|
|
@@ -145,6 +148,7 @@ declare const createGitlabIssueAction: (options: {
|
|
|
145
148
|
*/
|
|
146
149
|
declare const editGitlabIssueAction: (options: {
|
|
147
150
|
integrations: ScmIntegrationRegistry;
|
|
151
|
+
requireScmUserCredentials?: boolean;
|
|
148
152
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
149
153
|
repoUrl: string;
|
|
150
154
|
projectId: number;
|
|
@@ -182,6 +186,7 @@ declare const editGitlabIssueAction: (options: {
|
|
|
182
186
|
*/
|
|
183
187
|
declare const createPublishGitlabMergeRequestAction: (options: {
|
|
184
188
|
integrations: ScmIntegrationRegistry;
|
|
189
|
+
requireScmUserCredentials?: boolean;
|
|
185
190
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
186
191
|
repoUrl: string;
|
|
187
192
|
title: string;
|
|
@@ -198,6 +203,7 @@ declare const createPublishGitlabMergeRequestAction: (options: {
|
|
|
198
203
|
reviewers?: string[] | undefined;
|
|
199
204
|
assignReviewersFromApprovalRules?: boolean | undefined;
|
|
200
205
|
labels?: string | string[] | undefined;
|
|
206
|
+
autoMerge?: boolean | undefined;
|
|
201
207
|
}, {
|
|
202
208
|
targetBranchName: string;
|
|
203
209
|
projectid: string;
|
|
@@ -213,6 +219,7 @@ declare const createPublishGitlabMergeRequestAction: (options: {
|
|
|
213
219
|
*/
|
|
214
220
|
declare const createTriggerGitlabPipelineAction: (options: {
|
|
215
221
|
integrations: ScmIntegrationRegistry;
|
|
222
|
+
requireScmUserCredentials?: boolean;
|
|
216
223
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
217
224
|
repoUrl: string;
|
|
218
225
|
projectId: number;
|
|
@@ -232,6 +239,7 @@ declare const createTriggerGitlabPipelineAction: (options: {
|
|
|
232
239
|
*/
|
|
233
240
|
declare const createGitlabProjectAccessTokenAction: (options: {
|
|
234
241
|
integrations: ScmIntegrationRegistry;
|
|
242
|
+
requireScmUserCredentials?: boolean;
|
|
235
243
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
236
244
|
projectId: string | number;
|
|
237
245
|
repoUrl: string;
|
|
@@ -252,6 +260,7 @@ declare const createGitlabProjectAccessTokenAction: (options: {
|
|
|
252
260
|
*/
|
|
253
261
|
declare const createGitlabProjectDeployTokenAction: (options: {
|
|
254
262
|
integrations: ScmIntegrationRegistry;
|
|
263
|
+
requireScmUserCredentials?: boolean;
|
|
255
264
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
256
265
|
repoUrl: string;
|
|
257
266
|
projectId: string | number;
|
|
@@ -272,6 +281,7 @@ declare const createGitlabProjectDeployTokenAction: (options: {
|
|
|
272
281
|
*/
|
|
273
282
|
declare const createGitlabProjectVariableAction: (options: {
|
|
274
283
|
integrations: ScmIntegrationRegistry;
|
|
284
|
+
requireScmUserCredentials?: boolean;
|
|
275
285
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
276
286
|
repoUrl: string;
|
|
277
287
|
projectId: string | number;
|
|
@@ -295,6 +305,7 @@ declare const createGitlabProjectVariableAction: (options: {
|
|
|
295
305
|
*/
|
|
296
306
|
declare const createGitlabRepoPushAction: (options: {
|
|
297
307
|
integrations: ScmIntegrationRegistry;
|
|
308
|
+
requireScmUserCredentials?: boolean;
|
|
298
309
|
}) => _backstage_plugin_scaffolder_node.TemplateAction<{
|
|
299
310
|
repoUrl: string;
|
|
300
311
|
branchName: string;
|
package/dist/module.cjs.js
CHANGED
|
@@ -32,20 +32,45 @@ const gitlabModule = backendPluginApi.createBackendModule({
|
|
|
32
32
|
},
|
|
33
33
|
async init({ scaffolder, autocomplete: autocomplete$1, config }) {
|
|
34
34
|
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
35
|
+
const requireScmUserCredentials = config.getOptionalBoolean("scaffolder.requireScmUserCredentials") ?? false;
|
|
35
36
|
scaffolder.addActions(
|
|
36
|
-
gitlabGroupEnsureExists.createGitlabGroupEnsureExistsAction({
|
|
37
|
-
|
|
37
|
+
gitlabGroupEnsureExists.createGitlabGroupEnsureExistsAction({
|
|
38
|
+
integrations,
|
|
39
|
+
requireScmUserCredentials
|
|
40
|
+
}),
|
|
41
|
+
gitlabGroupAccessAction.createGitlabGroupAccessAction({
|
|
42
|
+
integrations,
|
|
43
|
+
requireScmUserCredentials
|
|
44
|
+
}),
|
|
38
45
|
gitlabProjectMigrate.createGitlabProjectMigrateAction({ integrations }),
|
|
39
|
-
gitlabIssueCreate.createGitlabIssueAction({ integrations }),
|
|
40
|
-
gitlabProjectAccessTokenCreate.createGitlabProjectAccessTokenAction({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
gitlabIssueCreate.createGitlabIssueAction({ integrations, requireScmUserCredentials }),
|
|
47
|
+
gitlabProjectAccessTokenCreate.createGitlabProjectAccessTokenAction({
|
|
48
|
+
integrations,
|
|
49
|
+
requireScmUserCredentials
|
|
50
|
+
}),
|
|
51
|
+
gitlabProjectDeployTokenCreate.createGitlabProjectDeployTokenAction({
|
|
52
|
+
integrations,
|
|
53
|
+
requireScmUserCredentials
|
|
54
|
+
}),
|
|
55
|
+
gitlabProjectVariableCreate.createGitlabProjectVariableAction({
|
|
56
|
+
integrations,
|
|
57
|
+
requireScmUserCredentials
|
|
58
|
+
}),
|
|
59
|
+
gitlabRepoPush.createGitlabRepoPushAction({
|
|
60
|
+
integrations,
|
|
61
|
+
requireScmUserCredentials
|
|
62
|
+
}),
|
|
44
63
|
gitlabUserInfo.createGitlabUserInfoAction({ integrations }),
|
|
45
|
-
gitlabIssueEdit.editGitlabIssueAction({ integrations }),
|
|
64
|
+
gitlabIssueEdit.editGitlabIssueAction({ integrations, requireScmUserCredentials }),
|
|
46
65
|
gitlab.createPublishGitlabAction({ config, integrations }),
|
|
47
|
-
gitlabMergeRequest.createPublishGitlabMergeRequestAction({
|
|
48
|
-
|
|
66
|
+
gitlabMergeRequest.createPublishGitlabMergeRequestAction({
|
|
67
|
+
integrations,
|
|
68
|
+
requireScmUserCredentials
|
|
69
|
+
}),
|
|
70
|
+
gitlabPipelineTrigger.createTriggerGitlabPipelineAction({
|
|
71
|
+
integrations,
|
|
72
|
+
requireScmUserCredentials
|
|
73
|
+
})
|
|
49
74
|
);
|
|
50
75
|
autocomplete$1.addAutocompleteProvider({
|
|
51
76
|
id: "gitlab",
|
package/dist/module.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.cjs.js","sources":["../src/module.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 */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { scaffolderAutocompleteExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport {\n createGitlabGroupEnsureExistsAction,\n createGitlabGroupAccessAction,\n createGitlabIssueAction,\n createGitlabProjectAccessTokenAction,\n createGitlabProjectDeployTokenAction,\n createGitlabProjectVariableAction,\n createGitlabRepoPushAction,\n createGitlabUserInfoAction,\n createPublishGitlabAction,\n createPublishGitlabMergeRequestAction,\n createTriggerGitlabPipelineAction,\n editGitlabIssueAction,\n} from './actions';\nimport { createGitlabProjectMigrateAction } from './actions/gitlabProjectMigrate';\nimport { createHandleAutocompleteRequest } from './autocomplete/autocomplete';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node';\n\n/**\n * @public\n * The GitLab Module for the Scaffolder Backend\n */\nexport const gitlabModule = createBackendModule({\n pluginId: 'scaffolder',\n moduleId: 'gitlab',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n autocomplete: scaffolderAutocompleteExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ scaffolder, autocomplete, config }) {\n const integrations = ScmIntegrations.fromConfig(config);\n\n scaffolder.addActions(\n createGitlabGroupEnsureExistsAction({
|
|
1
|
+
{"version":3,"file":"module.cjs.js","sources":["../src/module.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 */\nimport {\n coreServices,\n createBackendModule,\n} from '@backstage/backend-plugin-api';\nimport { ScmIntegrations } from '@backstage/integration';\nimport { scaffolderAutocompleteExtensionPoint } from '@backstage/plugin-scaffolder-node/alpha';\nimport {\n createGitlabGroupEnsureExistsAction,\n createGitlabGroupAccessAction,\n createGitlabIssueAction,\n createGitlabProjectAccessTokenAction,\n createGitlabProjectDeployTokenAction,\n createGitlabProjectVariableAction,\n createGitlabRepoPushAction,\n createGitlabUserInfoAction,\n createPublishGitlabAction,\n createPublishGitlabMergeRequestAction,\n createTriggerGitlabPipelineAction,\n editGitlabIssueAction,\n} from './actions';\nimport { createGitlabProjectMigrateAction } from './actions/gitlabProjectMigrate';\nimport { createHandleAutocompleteRequest } from './autocomplete/autocomplete';\nimport { scaffolderActionsExtensionPoint } from '@backstage/plugin-scaffolder-node';\n\n/**\n * @public\n * The GitLab Module for the Scaffolder Backend\n */\nexport const gitlabModule = createBackendModule({\n pluginId: 'scaffolder',\n moduleId: 'gitlab',\n register({ registerInit }) {\n registerInit({\n deps: {\n scaffolder: scaffolderActionsExtensionPoint,\n autocomplete: scaffolderAutocompleteExtensionPoint,\n config: coreServices.rootConfig,\n },\n async init({ scaffolder, autocomplete, config }) {\n const integrations = ScmIntegrations.fromConfig(config);\n const requireScmUserCredentials =\n config.getOptionalBoolean('scaffolder.requireScmUserCredentials') ??\n false;\n\n scaffolder.addActions(\n createGitlabGroupEnsureExistsAction({\n integrations,\n requireScmUserCredentials,\n }),\n createGitlabGroupAccessAction({\n integrations,\n requireScmUserCredentials,\n }),\n createGitlabProjectMigrateAction({ integrations }),\n createGitlabIssueAction({ integrations, requireScmUserCredentials }),\n createGitlabProjectAccessTokenAction({\n integrations,\n requireScmUserCredentials,\n }),\n createGitlabProjectDeployTokenAction({\n integrations,\n requireScmUserCredentials,\n }),\n createGitlabProjectVariableAction({\n integrations,\n requireScmUserCredentials,\n }),\n createGitlabRepoPushAction({\n integrations,\n requireScmUserCredentials,\n }),\n createGitlabUserInfoAction({ integrations }),\n editGitlabIssueAction({ integrations, requireScmUserCredentials }),\n createPublishGitlabAction({ config, integrations }),\n createPublishGitlabMergeRequestAction({\n integrations,\n requireScmUserCredentials,\n }),\n createTriggerGitlabPipelineAction({\n integrations,\n requireScmUserCredentials,\n }),\n );\n\n autocomplete.addAutocompleteProvider({\n id: 'gitlab',\n handler: createHandleAutocompleteRequest({ integrations }),\n });\n },\n });\n },\n});\n"],"names":["createBackendModule","scaffolderActionsExtensionPoint","scaffolderAutocompleteExtensionPoint","coreServices","autocomplete","ScmIntegrations","createGitlabGroupEnsureExistsAction","createGitlabGroupAccessAction","createGitlabProjectMigrateAction","createGitlabIssueAction","createGitlabProjectAccessTokenAction","createGitlabProjectDeployTokenAction","createGitlabProjectVariableAction","createGitlabRepoPushAction","createGitlabUserInfoAction","editGitlabIssueAction","createPublishGitlabAction","createPublishGitlabMergeRequestAction","createTriggerGitlabPipelineAction","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AAsB,EAAE,YAAA,EAAc,yBAAA,EAA2B,CAAA;AAAA,UACjEC,gCAAA,CAA0B,EAAE,MAAA,EAAQ,YAAA,EAAc,CAAA;AAAA,UAClDC,wDAAA,CAAsC;AAAA,YACpC,YAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA,UACDC,uDAAA,CAAkC;AAAA,YAChC,YAAA;AAAA,YACA;AAAA,WACD;AAAA,SACH;AAEA,QAAAd,cAAA,CAAa,uBAAA,CAAwB;AAAA,UACnC,EAAA,EAAI,QAAA;AAAA,UACJ,OAAA,EAASe,4CAAA,CAAgC,EAAE,YAAA,EAAc;AAAA,SAC1D,CAAA;AAAA,MACH;AAAA,KACD,CAAA;AAAA,EACH;AACF,CAAC;;;;"}
|
package/dist/util.cjs.js
CHANGED
|
@@ -20,7 +20,7 @@ const parseRepoHost = (repoUrl) => {
|
|
|
20
20
|
}
|
|
21
21
|
return parsed.host;
|
|
22
22
|
};
|
|
23
|
-
const getToken = (config, integrations) => {
|
|
23
|
+
const getToken = (config, integrations, requireScmUserCredentials = false) => {
|
|
24
24
|
const host = parseRepoHost(config.repoUrl);
|
|
25
25
|
const integrationConfig = integrations.gitlab.byHost(host);
|
|
26
26
|
if (!integrationConfig) {
|
|
@@ -28,6 +28,11 @@ const getToken = (config, integrations) => {
|
|
|
28
28
|
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
|
+
if (requireScmUserCredentials && !config.token) {
|
|
32
|
+
throw new errors.InputError(
|
|
33
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
31
36
|
const token = config.token || integrationConfig.config.token;
|
|
32
37
|
return { token, integrationConfig };
|
|
33
38
|
};
|
|
@@ -52,13 +57,18 @@ const parseRepoUrl = (repoUrl, integrations) => {
|
|
|
52
57
|
return { host, owner, repo };
|
|
53
58
|
};
|
|
54
59
|
function getClient(props) {
|
|
55
|
-
const { host, token, integrations } = props;
|
|
60
|
+
const { host, token, integrations, requireScmUserCredentials } = props;
|
|
56
61
|
const integrationConfig = integrations.gitlab.byHost(host);
|
|
57
62
|
if (!integrationConfig) {
|
|
58
63
|
throw new errors.InputError(
|
|
59
64
|
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
60
65
|
);
|
|
61
66
|
}
|
|
67
|
+
if (requireScmUserCredentials && !token) {
|
|
68
|
+
throw new errors.InputError(
|
|
69
|
+
`No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
62
72
|
const { config } = integrationConfig;
|
|
63
73
|
if (!config.token && !token) {
|
|
64
74
|
throw new errors.InputError(`No token available for host ${host}`);
|
package/dist/util.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.cjs.js","sources":["../src/util.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Gitlab, GroupSchema, RepositoryTreeSchema } from '@gitbeaker/rest';\nimport { z } from 'zod/v3';\nimport commonGitlabConfig from './commonGitlabConfig';\n\nimport { SerializedFile } from '@backstage/plugin-scaffolder-node';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\n\nexport const parseRepoHost = (repoUrl: string): string => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n return parsed.host;\n};\n\nexport const getToken = (\n config: z.infer<typeof commonGitlabConfig>,\n integrations: ScmIntegrationRegistry,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(config.repoUrl);\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const token = config.token || integrationConfig.config.token!;\n\n return { token: token, integrationConfig: integrationConfig };\n};\n\nexport type RepoSpec = {\n repo: string;\n host: string;\n owner?: string;\n};\n\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): RepoSpec => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const repo: string = parsed.searchParams.get('repo')!;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n return { host, owner, repo };\n};\n\nexport function getClient(props: {\n host: string;\n token?: string;\n integrations: ScmIntegrationRegistry;\n}): InstanceType<typeof Gitlab> {\n const { host, token, integrations } = props;\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const { config } = integrationConfig;\n\n if (!config.token && !token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const requestToken = token || config.token!;\n const tokenType = token ? 'oauthToken' : 'token';\n\n const gitlabOptions: any = {\n host: config.baseUrl,\n };\n\n gitlabOptions[tokenType] = requestToken;\n return new Gitlab(gitlabOptions);\n}\n\nexport function convertDate(\n inputDate: string | undefined,\n defaultDate: string,\n) {\n try {\n return inputDate\n ? new Date(inputDate).toISOString()\n : new Date(defaultDate).toISOString();\n } catch (error) {\n throw new InputError(`Error converting input date - ${error}`);\n }\n}\n\nexport async function getTopLevelParentGroup(\n client: InstanceType<typeof Gitlab>,\n groupId: number,\n): Promise<GroupSchema> {\n try {\n const topParentGroup = await client.Groups.show(groupId);\n if (topParentGroup.parent_id) {\n return getTopLevelParentGroup(client, topParentGroup.parent_id as number);\n }\n return topParentGroup as GroupSchema;\n } catch (error: any) {\n throw new InputError(\n `Error finding top-level parent group ID: ${error.message}`,\n );\n }\n}\n\nexport async function checkEpicScope(\n client: InstanceType<typeof Gitlab>,\n projectId: number,\n epicId: number,\n) {\n try {\n // If project exists, get the top level group id\n const project = await client.Projects.show(projectId);\n if (!project) {\n throw new InputError(\n `Project with id ${projectId} not found. Check your GitLab instance.`,\n );\n }\n const topParentGroup = await getTopLevelParentGroup(\n client,\n project.namespace.id,\n );\n if (!topParentGroup) {\n throw new InputError(`Couldn't find a suitable top-level parent group.`);\n }\n // Get the epic\n const epic = (await client.Epics.all(topParentGroup.id)).find(\n (x: any) => x.id === epicId,\n );\n if (!epic) {\n throw new InputError(\n `Epic with id ${epicId} not found in the top-level parent group ${topParentGroup.name}.`,\n );\n }\n\n const epicGroup = await client.Groups.show(epic.group_id as number);\n const projectNamespace: string = project.path_with_namespace as string;\n return projectNamespace.startsWith(epicGroup.full_path as string);\n } catch (error: any) {\n throw new InputError(`Could not find epic scope: ${error.message}`);\n }\n}\n\nfunction computeSha256(file: SerializedFile): string {\n const hash = createHash('sha256');\n hash.update(file.content);\n return hash.digest('hex');\n}\n\nexport async 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"],"names":["InputError","Gitlab","createHash","path"],"mappings":";;;;;;;;;;;AA+BO,MAAM,aAAA,GAAgB,CAAC,OAAA,KAA4B;AACxD,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAA,QAAA,EAAW,OAAO,CAAA,CAAE,CAAA;AAAA,EACvC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK,KAAK,CAAA;AAAA,KAChE;AAAA,EACF;AACA,EAAA,OAAO,MAAA,CAAO,IAAA;AAChB;AAEO,MAAM,QAAA,GAAW,CACtB,MAAA,EACA,YAAA,KAC4D;AAC5D,EAAA,MAAM,IAAA,GAAO,aAAA,CAAc,MAAA,CAAO,OAAO,CAAA;AACzC,EAAA,MAAM,iBAAA,GAAoB,YAAA,CAAa,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA;AAEzD,EAAA,IAAI,CAAC,iBAAA,EAAmB;AACtB,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,kDAAkD,IAAI,CAAA,uCAAA;AAAA,KACxD;AAAA,EACF;AAEA,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,KAAA,IAAS,iBAAA,CAAkB,MAAA,CAAO,KAAA;AAEvD,EAAA,OAAO,EAAE,OAAc,iBAAA,EAAqC;AAC9D;AAQO,MAAM,YAAA,GAAe,CAC1B,OAAA,EACA,YAAA,K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QAAA,EACA,MAAA,EACA,KACA,MAAA,EACA,WAAA,EACA,sBAKa,MAAA,EACqC;AAClD,EAAA,IAAI,wBAAwB,MAAA,EAAQ;AAClC,IAAA,MAAM,QAAA,GAAWC,sBAAK,IAAA,CAAK,QAAA,CAAS,cAAc,EAAA,EAAI,QAAA,CAAS,KAAK,IAAI,CAAA;AAExE,IAAA,IAAI,aAAa,IAAA,CAAK,CAAA,UAAA,KAAc,UAAA,CAAW,IAAA,KAAS,QAAQ,CAAA,EAAG;AACjE,MAAA,IAAI;AACF,QAAA,MAAM,UAAA,GAAa,MAAM,GAAA,CAAI,eAAA,CAAgB,IAAA;AAAA,UAC3C,MAAA,CAAO,MAAA;AAAA,UACP,QAAA;AAAA,UACA,MAAA,CAAO;AAAA,SACT;AACA,QAAA,IAAI,aAAA,CAAc,QAAA,CAAS,IAAI,CAAA,KAAM,WAAW,cAAA,EAAgB;AAC9D,UAAA,OAAO,MAAA;AAAA,QACT;AAAA,MACF,SAAS,KAAA,EAAO;AACd,QAAA,MAAA,CAAO,IAAA;AAAA,UACL,2DAA2D,QAAQ,CAAA;AAAA,SACrE;AAAA,MACF;AACA,MAAA,OAAO,QAAA;AAAA,IACT;AACA,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,mBAAA;AACT;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"util.cjs.js","sources":["../src/util.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { InputError } from '@backstage/errors';\nimport {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { Gitlab, GroupSchema, RepositoryTreeSchema } from '@gitbeaker/rest';\nimport { z } from 'zod/v3';\nimport commonGitlabConfig from './commonGitlabConfig';\n\nimport { SerializedFile } from '@backstage/plugin-scaffolder-node';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\n\nexport const parseRepoHost = (repoUrl: string): string => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n return parsed.host;\n};\n\nexport const getToken = (\n config: z.infer<typeof commonGitlabConfig>,\n integrations: ScmIntegrationRegistry,\n requireScmUserCredentials = false,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(config.repoUrl);\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (requireScmUserCredentials && !config.token) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const token = config.token || integrationConfig.config.token!;\n\n return { token: token, integrationConfig: integrationConfig };\n};\n\nexport type RepoSpec = {\n repo: string;\n host: string;\n owner?: string;\n};\n\nexport const parseRepoUrl = (\n repoUrl: string,\n integrations: ScmIntegrationRegistry,\n): RepoSpec => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n const host = parsed.host;\n const owner = parsed.searchParams.get('owner') ?? undefined;\n const repo: string = parsed.searchParams.get('repo')!;\n\n const type = integrations.byHost(host)?.type;\n\n if (!type) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n return { host, owner, repo };\n};\n\nexport function getClient(props: {\n host: string;\n token?: string;\n integrations: ScmIntegrationRegistry;\n requireScmUserCredentials?: boolean;\n}): InstanceType<typeof Gitlab> {\n const { host, token, integrations, requireScmUserCredentials } = props;\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (requireScmUserCredentials && !token) {\n throw new InputError(\n `No user credentials provided for host ${host}, but scaffolder.requireScmUserCredentials is enabled`,\n );\n }\n\n const { config } = integrationConfig;\n\n if (!config.token && !token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const requestToken = token || config.token!;\n const tokenType = token ? 'oauthToken' : 'token';\n\n const gitlabOptions: any = {\n host: config.baseUrl,\n };\n\n gitlabOptions[tokenType] = requestToken;\n return new Gitlab(gitlabOptions);\n}\n\nexport function convertDate(\n inputDate: string | undefined,\n defaultDate: string,\n) {\n try {\n return inputDate\n ? new Date(inputDate).toISOString()\n : new Date(defaultDate).toISOString();\n } catch (error) {\n throw new InputError(`Error converting input date - ${error}`);\n }\n}\n\nexport async function getTopLevelParentGroup(\n client: InstanceType<typeof Gitlab>,\n groupId: number,\n): Promise<GroupSchema> {\n try {\n const topParentGroup = await client.Groups.show(groupId);\n if (topParentGroup.parent_id) {\n return getTopLevelParentGroup(client, topParentGroup.parent_id as number);\n }\n return topParentGroup as GroupSchema;\n } catch (error: any) {\n throw new InputError(\n `Error finding top-level parent group ID: ${error.message}`,\n );\n }\n}\n\nexport async function checkEpicScope(\n client: InstanceType<typeof Gitlab>,\n projectId: number,\n epicId: number,\n) {\n try {\n // If project exists, get the top level group id\n const project = await client.Projects.show(projectId);\n if (!project) {\n throw new InputError(\n `Project with id ${projectId} not found. Check your GitLab instance.`,\n );\n }\n const topParentGroup = await getTopLevelParentGroup(\n client,\n project.namespace.id,\n );\n if (!topParentGroup) {\n throw new InputError(`Couldn't find a suitable top-level parent group.`);\n }\n // Get the epic\n const epic = (await client.Epics.all(topParentGroup.id)).find(\n (x: any) => x.id === epicId,\n );\n if (!epic) {\n throw new InputError(\n `Epic with id ${epicId} not found in the top-level parent group ${topParentGroup.name}.`,\n );\n }\n\n const epicGroup = await client.Groups.show(epic.group_id as number);\n const projectNamespace: string = project.path_with_namespace as string;\n return projectNamespace.startsWith(epicGroup.full_path as string);\n } catch (error: any) {\n throw new InputError(`Could not find epic scope: ${error.message}`);\n }\n}\n\nfunction computeSha256(file: SerializedFile): string {\n const hash = createHash('sha256');\n hash.update(file.content);\n return hash.digest('hex');\n}\n\nexport async 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"],"names":["InputError","Gitlab","createHash","path"],"mappings":";;;;;;;;;;;AA+BO,MAAM,aAAA,GAAgB,CAAC,OAAA,KAA4B;AACxD,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAI,GAAA,CAAI,CAAA,QAAA,EAAW,OAAO,CAAA,CAAE,CAAA;AAAA,EACvC,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,IAAIA,iBAAA;AAAA,MACR,CAAA,0CAAA,EAA6C,OAAO,CAAA,EAAA,EAAK,KAAK,CAAA;AAAA,KAChE;AAAA,EACF;AACA,EAAA,OAAO,M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AA,GAAa,MAAM,GAAA,CAAI,eAAA,CAAgB,IAAA;AAAA,UAC3C,MAAA,CAAO,MAAA;AAAA,UACP,QAAA;AAAA,UACA,MAAA,CAAO;AAAA,SACT;AACA,QAAA,IAAI,aAAA,CAAc,QAAA,CAAS,IAAI,CAAA,KAAM,WAAW,cAAA,EAAgB;AAC9D,UAAA,OAAO,MAAA;AAAA,QACT;AAAA,MACF,SAAS,KAAA,EAAO;AACd,QAAA,MAAA,CAAO,IAAA;AAAA,UACL,2DAA2D,QAAQ,CAAA;AAAA,SACrE;AAAA,MACF;AACA,MAAA,OAAO,QAAA;AAAA,IACT;AACA,IAAA,OAAO,QAAA;AAAA,EACT;AACA,EAAA,OAAO,mBAAA;AACT;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-backend-module-gitlab",
|
|
3
|
-
"version": "0.11.
|
|
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",
|
|
56
|
+
"@backstage/backend-plugin-api": "1.10.1-next.0",
|
|
57
57
|
"@backstage/config": "1.3.8",
|
|
58
58
|
"@backstage/errors": "1.3.1",
|
|
59
|
-
"@backstage/integration": "2.1.0",
|
|
60
|
-
"@backstage/plugin-scaffolder-node": "0.13.7-next.
|
|
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.
|
|
69
|
+
"@backstage/backend-test-utils": "1.11.7-next.0",
|
|
70
70
|
"@backstage/cli": "0.36.6-next.0",
|
|
71
|
-
"@backstage/plugin-scaffolder-node-test-utils": "0.3.15-next.
|
|
71
|
+
"@backstage/plugin-scaffolder-node-test-utils": "0.3.15-next.1"
|
|
72
72
|
}
|
|
73
73
|
}
|