@backstage/plugin-scaffolder-backend-module-gitlab 0.9.2-next.1 → 0.9.2-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/actions/gitlab.cjs.js +106 -235
- package/dist/actions/gitlab.cjs.js.map +1 -1
- package/dist/actions/gitlabGroupEnsureExists.cjs.js +24 -20
- package/dist/actions/gitlabGroupEnsureExists.cjs.js.map +1 -1
- package/dist/actions/gitlabIssueCreate.cjs.js +75 -52
- package/dist/actions/gitlabIssueCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabIssueEdit.cjs.js +86 -68
- package/dist/actions/gitlabIssueEdit.cjs.js.map +1 -1
- package/dist/actions/gitlabPipelineTrigger.cjs.js +26 -21
- package/dist/actions/gitlabPipelineTrigger.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js +18 -13
- package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js +27 -15
- package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectMigrate.cjs.js +21 -46
- package/dist/actions/gitlabProjectMigrate.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectVariableCreate.cjs.js +32 -20
- package/dist/actions/gitlabProjectVariableCreate.cjs.js.map +1 -1
- package/dist/actions/gitlabRepoPush.cjs.js +31 -56
- package/dist/actions/gitlabRepoPush.cjs.js.map +1 -1
- package/dist/commonGitlabConfig.cjs.js +1 -4
- package/dist/commonGitlabConfig.cjs.js.map +1 -1
- package/dist/index.d.ts +94 -85
- package/package.json +5 -5
|
@@ -4,7 +4,6 @@ var errors = require('@backstage/errors');
|
|
|
4
4
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
5
|
var rest = require('@gitbeaker/rest');
|
|
6
6
|
var luxon = require('luxon');
|
|
7
|
-
var zod = require('zod');
|
|
8
7
|
var util = require('../util.cjs.js');
|
|
9
8
|
var gitlabProjectAccessTokenCreate_examples = require('./gitlabProjectAccessTokenCreate.examples.cjs.js');
|
|
10
9
|
|
|
@@ -14,28 +13,34 @@ const createGitlabProjectAccessTokenAction = (options) => {
|
|
|
14
13
|
id: "gitlab:projectAccessToken:create",
|
|
15
14
|
examples: gitlabProjectAccessTokenCreate_examples.examples,
|
|
16
15
|
schema: {
|
|
17
|
-
input:
|
|
18
|
-
projectId:
|
|
16
|
+
input: {
|
|
17
|
+
projectId: (z) => z.union([z.number(), z.string()], {
|
|
19
18
|
description: "Project ID/Name(slug) of the Gitlab Project"
|
|
20
19
|
}),
|
|
21
|
-
token:
|
|
20
|
+
token: (z) => z.string({
|
|
22
21
|
description: "The token to use for authorization to GitLab"
|
|
23
22
|
}).optional(),
|
|
24
|
-
name:
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
name: (z) => z.string({
|
|
24
|
+
description: "Name of Access Key"
|
|
25
|
+
}).optional(),
|
|
26
|
+
repoUrl: (z) => z.string({
|
|
27
|
+
description: "URL to gitlab instance"
|
|
28
|
+
}),
|
|
29
|
+
accessLevel: (z) => z.number({
|
|
27
30
|
description: "Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)"
|
|
28
31
|
}).optional(),
|
|
29
|
-
scopes:
|
|
32
|
+
scopes: (z) => z.string({
|
|
30
33
|
description: "Scopes for a project access token"
|
|
31
34
|
}).array().optional(),
|
|
32
|
-
expiresAt:
|
|
35
|
+
expiresAt: (z) => z.string({
|
|
33
36
|
description: "Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days."
|
|
34
37
|
}).optional()
|
|
35
|
-
}
|
|
36
|
-
output:
|
|
37
|
-
access_token:
|
|
38
|
-
|
|
38
|
+
},
|
|
39
|
+
output: {
|
|
40
|
+
access_token: (z) => z.string({
|
|
41
|
+
description: "Access Token"
|
|
42
|
+
})
|
|
43
|
+
}
|
|
39
44
|
},
|
|
40
45
|
async handler(ctx) {
|
|
41
46
|
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlabProjectAccessTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectAccessTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { AccessTokenScopes, Gitlab } from '@gitbeaker/rest';\nimport { DateTime } from 'luxon';\nimport {
|
|
1
|
+
{"version":3,"file":"gitlabProjectAccessTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectAccessTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { AccessTokenScopes, Gitlab } from '@gitbeaker/rest';\nimport { DateTime } from 'luxon';\nimport { getToken } from '../util';\nimport { examples } from './gitlabProjectAccessTokenCreate.examples';\n\n/**\n * Creates a `gitlab:projectAccessToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\n\nexport const createGitlabProjectAccessTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectAccessToken:create',\n examples,\n schema: {\n input: {\n projectId: z =>\n z.union([z.number(), z.string()], {\n description: 'Project ID/Name(slug) of the Gitlab Project',\n }),\n token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n name: z =>\n z\n .string({\n description: 'Name of Access Key',\n })\n .optional(),\n repoUrl: z =>\n z.string({\n description: 'URL to gitlab instance',\n }),\n accessLevel: z =>\n z\n .number({\n description:\n 'Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)',\n })\n .optional(),\n scopes: z =>\n z\n .string({\n description: 'Scopes for a project access token',\n })\n .array()\n .optional(),\n expiresAt: z =>\n z\n .string({\n description:\n 'Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days.',\n })\n .optional(),\n },\n output: {\n access_token: z =>\n z.string({\n description: 'Access Token',\n }),\n },\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const {\n projectId,\n name = 'tokenname',\n accessLevel = 40,\n scopes = ['read_repository'],\n expiresAt,\n } = ctx.input;\n\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n if (!integrationConfig.config.token && token) {\n throw new InputError(\n `No token available for host ${integrationConfig.config.baseUrl}`,\n );\n }\n\n let api;\n\n if (!ctx.input.token) {\n api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n } else {\n api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n oauthToken: token,\n });\n }\n\n const projectAccessToken = await ctx.checkpoint({\n key: `project.access.token.${projectId}.${name}`,\n fn: async () => {\n const response = await api.ProjectAccessTokens.create(\n projectId,\n name,\n scopes as AccessTokenScopes[],\n expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!,\n {\n accessLevel,\n },\n );\n return response.token;\n },\n });\n\n if (!projectAccessToken) {\n throw new Error('Could not create project access token');\n }\n\n ctx.output('access_token', projectAccessToken);\n },\n });\n};\n"],"names":["createTemplateAction","examples","getToken","InputError","Gitlab","DateTime"],"mappings":";;;;;;;;;AA+Ba,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kCAAA;AAAA,cACJC,gDAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,SAAA,EAAW,CACT,CAAA,KAAA,CAAA,CAAE,KAAM,CAAA,CAAC,CAAE,CAAA,MAAA,EAAU,EAAA,CAAA,CAAE,MAAO,EAAC,CAAG,EAAA;AAAA,UAChC,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,KAAA,EAAO,CACL,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,IAAA,EAAM,CACJ,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,EACA,QAAS,EAAA;AAAA,QACd,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,WAAA,EAAa,CACX,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WACE,EAAA;AAAA,SACH,EACA,QAAS,EAAA;AAAA,QACd,MAAA,EAAQ,CACN,CAAA,KAAA,CAAA,CACG,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,CAA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AA,UAC/B,UAAY,EAAA;AAAA,SACb,CAAA;AAAA;AAGH,MAAM,MAAA,kBAAA,GAAqB,MAAM,GAAA,CAAI,UAAW,CAAA;AAAA,QAC9C,GAAK,EAAA,CAAA,qBAAA,EAAwB,SAAS,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QAC9C,IAAI,YAAY;AACd,UAAM,MAAA,QAAA,GAAW,MAAM,GAAA,CAAI,mBAAoB,CAAA,MAAA;AAAA,YAC7C,SAAA;AAAA,YACA,IAAA;AAAA,YACA,MAAA;AAAA,YACA,SAAA,IAAaC,cAAS,CAAA,GAAA,EAAM,CAAA,IAAA,CAAK,EAAE,IAAM,EAAA,GAAA,EAAK,CAAA,CAAE,SAAU,EAAA;AAAA,YAC1D;AAAA,cACE;AAAA;AACF,WACF;AACA,UAAA,OAAO,QAAS,CAAA,KAAA;AAAA;AAClB,OACD,CAAA;AAED,MAAA,IAAI,CAAC,kBAAoB,EAAA;AACvB,QAAM,MAAA,IAAI,MAAM,uCAAuC,CAAA;AAAA;AAGzD,MAAI,GAAA,CAAA,MAAA,CAAO,gBAAgB,kBAAkB,CAAA;AAAA;AAC/C,GACD,CAAA;AACH;;;;"}
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
var errors = require('@backstage/errors');
|
|
4
4
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
5
5
|
var rest = require('@gitbeaker/rest');
|
|
6
|
-
var zod = require('zod');
|
|
7
|
-
var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
|
|
8
6
|
var util = require('../util.cjs.js');
|
|
9
7
|
var gitlabProjectDeployTokenCreate_examples = require('./gitlabProjectDeployTokenCreate.examples.cjs.js');
|
|
10
8
|
|
|
@@ -14,20 +12,34 @@ const createGitlabProjectDeployTokenAction = (options) => {
|
|
|
14
12
|
id: "gitlab:projectDeployToken:create",
|
|
15
13
|
examples: gitlabProjectDeployTokenCreate_examples.examples,
|
|
16
14
|
schema: {
|
|
17
|
-
input:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
input: {
|
|
16
|
+
repoUrl: (z) => z.string({
|
|
17
|
+
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`
|
|
18
|
+
}),
|
|
19
|
+
token: (z) => z.string({
|
|
20
|
+
description: "The token to use for authorization to GitLab"
|
|
21
|
+
}).optional(),
|
|
22
|
+
projectId: (z) => z.union([z.number(), z.string()], {
|
|
23
|
+
description: "Project ID"
|
|
24
|
+
}),
|
|
25
|
+
name: (z) => z.string({
|
|
26
|
+
description: "Deploy Token Name"
|
|
27
|
+
}),
|
|
28
|
+
username: (z) => z.string({
|
|
29
|
+
description: "Deploy Token Username"
|
|
30
|
+
}).optional(),
|
|
31
|
+
scopes: (z) => z.array(z.string(), {
|
|
32
|
+
description: "Scopes"
|
|
25
33
|
})
|
|
26
|
-
|
|
27
|
-
output:
|
|
28
|
-
deploy_token:
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
},
|
|
35
|
+
output: {
|
|
36
|
+
deploy_token: (z) => z.string({
|
|
37
|
+
description: "Deploy Token"
|
|
38
|
+
}),
|
|
39
|
+
user: (z) => z.string({
|
|
40
|
+
description: "User"
|
|
41
|
+
})
|
|
42
|
+
}
|
|
31
43
|
},
|
|
32
44
|
async handler(ctx) {
|
|
33
45
|
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlabProjectDeployTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectDeployTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { DeployTokenScope, Gitlab } from '@gitbeaker/rest';\nimport {
|
|
1
|
+
{"version":3,"file":"gitlabProjectDeployTokenCreate.cjs.js","sources":["../../src/actions/gitlabProjectDeployTokenCreate.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { DeployTokenScope, Gitlab } from '@gitbeaker/rest';\nimport { getToken } from '../util';\nimport { examples } from './gitlabProjectDeployTokenCreate.examples';\n\n/**\n * Creates a `gitlab:projectDeployToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectDeployTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectDeployToken:create',\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 token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n projectId: z =>\n z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z =>\n z.string({\n description: 'Deploy Token Name',\n }),\n username: z =>\n z\n .string({\n description: 'Deploy Token Username',\n })\n .optional(),\n scopes: z =>\n z.array(z.string(), {\n description: 'Scopes',\n }),\n },\n output: {\n deploy_token: z =>\n z.string({\n description: 'Deploy Token',\n }),\n user: z =>\n z.string({\n description: 'User',\n }),\n },\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, username, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n if (scopes.length === 0) {\n throw new InputError(\n `Could not create token for project \"${ctx.input.projectId}\": scopes cannot be empty.`,\n );\n }\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n const { deployToken, deployUsername } = await ctx.checkpoint({\n key: `create.deploy.token.${projectId}.${name}`,\n fn: async () => {\n const res = await api.DeployTokens.create(\n name,\n scopes as DeployTokenScope[],\n {\n projectId,\n username,\n },\n );\n\n if (!res.hasOwnProperty('token')) {\n throw new InputError(`No deploy_token given from gitlab instance`);\n }\n\n return {\n deployToken: res.token as string,\n deployUsername: res.username,\n };\n },\n });\n\n ctx.output('deploy_token', deployToken);\n ctx.output('user', deployUsername);\n },\n });\n};\n"],"names":["createTemplateAction","examples","getToken","InputError","Gitlab"],"mappings":";;;;;;;;AA6Ba,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kCAAA;AAAA,cACJC,gDAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,sJAAA;AAAA,SACd,CAAA;AAAA,QACH,KAAA,EAAO,CACL,CAAA,KAAA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QAAA,MAAM,IAAIC,iBAAA;AAAA,UACR,CAAA,oCAAA,EAAuC,GAAI,CAAA,KAAA,CAAM,SAAS,CAAA,0BAAA;AAAA,SAC5D;AAAA;AAGF,MAAM,MAAA,GAAA,GAAM,IAAIC,WAAO,CAAA;AAAA,QACrB,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,QAC/B;AAAA,OACD,CAAA;AAED,MAAA,MAAM,EAAE,WAAa,EAAA,cAAA,EAAmB,GAAA,MAAM,IAAI,UAAW,CAAA;AAAA,QAC3D,GAAK,EAAA,CAAA,oBAAA,EAAuB,SAAS,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA;AAAA,QAC7C,IAAI,YAAY;AACd,UAAM,MAAA,GAAA,GAAM,MAAM,GAAA,CAAI,YAAa,CAAA,MAAA;AAAA,YACjC,IAAA;AAAA,YACA,MAAA;AAAA,YACA;AAAA,cACE,SAAA;AAAA,cACA;AAAA;AACF,WACF;AAEA,UAAA,IAAI,CAAC,GAAA,CAAI,cAAe,CAAA,OAAO,CAAG,EAAA;AAChC,YAAM,MAAA,IAAID,kBAAW,CAA4C,0CAAA,CAAA,CAAA;AAAA;AAGnE,UAAO,OAAA;AAAA,YACL,aAAa,GAAI,CAAA,KAAA;AAAA,YACjB,gBAAgB,GAAI,CAAA;AAAA,WACtB;AAAA;AACF,OACD,CAAA;AAED,MAAI,GAAA,CAAA,MAAA,CAAO,gBAAgB,WAAW,CAAA;AACtC,MAAI,GAAA,CAAA,MAAA,CAAO,QAAQ,cAAc,CAAA;AAAA;AACnC,GACD,CAAA;AACH;;;;"}
|
|
@@ -12,54 +12,29 @@ const createGitlabProjectMigrateAction = (options) => {
|
|
|
12
12
|
examples: gitlabRepoPush_examples.examples,
|
|
13
13
|
schema: {
|
|
14
14
|
input: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: "string",
|
|
31
|
-
title: "Target Project Location",
|
|
32
|
-
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`
|
|
33
|
-
},
|
|
34
|
-
sourceAccessToken: {
|
|
35
|
-
type: "string",
|
|
36
|
-
title: "Source Group Access Token",
|
|
37
|
-
description: `The token to use for authorization to the source GitLab'`
|
|
38
|
-
},
|
|
39
|
-
sourceFullPath: {
|
|
40
|
-
type: "string",
|
|
41
|
-
title: "Group Full Path",
|
|
42
|
-
description: "Full path to the project in the source Gitlab instance"
|
|
43
|
-
},
|
|
44
|
-
sourceUrl: {
|
|
45
|
-
type: "string",
|
|
46
|
-
title: "Source URL Location",
|
|
47
|
-
description: `Accepts the format 'https://gitlab.com/'`
|
|
48
|
-
}
|
|
49
|
-
}
|
|
15
|
+
destinationAccessToken: (z) => z.string({
|
|
16
|
+
description: `The token to use for authorization to the target GitLab'`
|
|
17
|
+
}),
|
|
18
|
+
destinationUrl: (z) => z.string({
|
|
19
|
+
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`
|
|
20
|
+
}),
|
|
21
|
+
sourceAccessToken: (z) => z.string({
|
|
22
|
+
description: `The token to use for authorization to the source GitLab'`
|
|
23
|
+
}),
|
|
24
|
+
sourceFullPath: (z) => z.string({
|
|
25
|
+
description: "Full path to the project in the source Gitlab instance"
|
|
26
|
+
}),
|
|
27
|
+
sourceUrl: (z) => z.string({
|
|
28
|
+
description: `Accepts the format 'https://gitlab.com/'`
|
|
29
|
+
})
|
|
50
30
|
},
|
|
51
31
|
output: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
migrationId: {
|
|
59
|
-
title: "Id of the migration that imports the project",
|
|
60
|
-
type: "number"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
32
|
+
importedRepoUrl: (z) => z.string({
|
|
33
|
+
description: "URL to the newly imported repo"
|
|
34
|
+
}),
|
|
35
|
+
migrationId: (z) => z.number({
|
|
36
|
+
description: "Id of the migration that imports the project"
|
|
37
|
+
})
|
|
63
38
|
}
|
|
64
39
|
},
|
|
65
40
|
async handler(ctx) {
|
|
@@ -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
|
|
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 id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n destinationAccessToken: z =>\n z.string({\n description: `The token to use for authorization to the target GitLab'`,\n }),\n destinationUrl: 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 sourceAccessToken: z =>\n z.string({\n description: `The token to use for authorization to the source GitLab'`,\n }),\n sourceFullPath: z =>\n z.string({\n description:\n 'Full path to the project in the source Gitlab instance',\n }),\n sourceUrl: z =>\n z.string({\n description: `Accepts the format 'https://gitlab.com/'`,\n }),\n },\n output: {\n importedRepoUrl: z =>\n z.string({\n description: 'URL to the newly imported repo',\n }),\n migrationId: z =>\n z.number({\n description: 'Id of the migration that imports the project',\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 migrationId = await ctx.checkpoint({\n key: `create.migration.${sourceUrl}`,\n fn: async () => {\n const migrationStatus = await api.Migrations.create(\n sourceConfig,\n migrationEntity,\n );\n return migrationStatus.id;\n },\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,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,sBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,sBAAA,EAAwB,CACtB,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,wDAAA;AAAA,SACd,CAAA;AAAA,QACH,cAAA,EAAgB,CACd,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,sJAAA;AAAA,SACd,CAAA;AAAA,QACH,iBAAA,EAAmB,CACjB,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,wDAAA;AAAA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AA;AAAA,QACL,YAAc,EAAA;AAAA,OAChB;AAEA,MAAI,IAAA;AACF,QAAM,MAAA,WAAA,GAAc,MAAM,GAAA,CAAI,UAAW,CAAA;AAAA,UACvC,GAAA,EAAK,oBAAoB,SAAS,CAAA,CAAA;AAAA,UAClC,IAAI,YAAY;AACd,YAAM,MAAA,eAAA,GAAkB,MAAM,GAAA,CAAI,UAAW,CAAA,MAAA;AAAA,cAC3C,YAAA;AAAA,cACA;AAAA,aACF;AACA,YAAA,OAAO,eAAgB,CAAA,EAAA;AAAA;AACzB,SACD,CAAA;AAED,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;;;;"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
|
-
var zod = require('zod');
|
|
5
|
-
var commonGitlabConfig = require('../commonGitlabConfig.cjs.js');
|
|
6
4
|
var util = require('../util.cjs.js');
|
|
7
5
|
var gitlabProjectVariableCreate_examples = require('./gitlabProjectVariableCreate.examples.cjs.js');
|
|
8
6
|
|
|
@@ -12,24 +10,38 @@ const createGitlabProjectVariableAction = (options) => {
|
|
|
12
10
|
id: "gitlab:projectVariable:create",
|
|
13
11
|
examples: gitlabProjectVariableCreate_examples.examples,
|
|
14
12
|
schema: {
|
|
15
|
-
input:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
input: {
|
|
14
|
+
repoUrl: (z) => z.string({
|
|
15
|
+
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`
|
|
16
|
+
}),
|
|
17
|
+
token: (z) => z.string({
|
|
18
|
+
description: "The token to use for authorization to GitLab"
|
|
19
|
+
}).optional(),
|
|
20
|
+
projectId: (z) => z.union([z.number(), z.string()], {
|
|
21
|
+
description: "Project ID"
|
|
22
|
+
}),
|
|
23
|
+
key: (z) => z.string({
|
|
24
|
+
description: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed"
|
|
25
|
+
}).regex(/^[A-Za-z0-9_]{1,255}$/),
|
|
26
|
+
value: (z) => z.string({
|
|
27
|
+
description: "The value of a variable"
|
|
28
|
+
}),
|
|
29
|
+
variableType: (z) => z.string({
|
|
30
|
+
description: "Variable Type (env_var or file)"
|
|
31
|
+
}),
|
|
32
|
+
variableProtected: (z) => z.boolean({
|
|
33
|
+
description: "Whether the variable is protected"
|
|
34
|
+
}).default(false).optional(),
|
|
35
|
+
masked: (z) => z.boolean({
|
|
36
|
+
description: "Whether the variable is masked"
|
|
37
|
+
}).default(false).optional(),
|
|
38
|
+
raw: (z) => z.boolean({
|
|
39
|
+
description: "Whether the variable is expandable"
|
|
40
|
+
}).default(false).optional(),
|
|
41
|
+
environmentScope: (z) => z.string({
|
|
42
|
+
description: "The environment_scope of the variable"
|
|
43
|
+
}).default("*").optional()
|
|
44
|
+
}
|
|
33
45
|
},
|
|
34
46
|
async handler(ctx) {
|
|
35
47
|
const {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlabProjectVariableCreate.cjs.js","sources":["../../src/actions/gitlabProjectVariableCreate.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 { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { VariableType } from '@gitbeaker/rest';\nimport {
|
|
1
|
+
{"version":3,"file":"gitlabProjectVariableCreate.cjs.js","sources":["../../src/actions/gitlabProjectVariableCreate.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 { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { VariableType } from '@gitbeaker/rest';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabProjectVariableCreate.examples';\n\n/**\n * Creates a `gitlab:projectVariable:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectVariableAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectVariable:create',\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 token: z =>\n z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n projectId: z =>\n z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: z =>\n z\n .string({\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n })\n .regex(/^[A-Za-z0-9_]{1,255}$/),\n value: z =>\n z.string({\n description: 'The value of a variable',\n }),\n variableType: z =>\n z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z =>\n z\n .boolean({\n description: 'Whether the variable is protected',\n })\n .default(false)\n .optional(),\n masked: z =>\n z\n .boolean({\n description: 'Whether the variable is masked',\n })\n .default(false)\n .optional(),\n raw: z =>\n z\n .boolean({\n description: 'Whether the variable is expandable',\n })\n .default(false)\n .optional(),\n environmentScope: z =>\n z\n .string({\n description: 'The environment_scope of the variable',\n })\n .default('*')\n .optional(),\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n projectId,\n key,\n value,\n variableType,\n variableProtected = false,\n masked = false,\n raw = false,\n environmentScope = '*',\n token,\n } = ctx.input;\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n\n const api = getClient({ host, integrations, token });\n\n await ctx.checkpoint({\n key: `create.project.variables.${projectId}.${key}.${value}`,\n fn: async () => {\n await api.ProjectVariables.create(projectId, key, value, {\n variableType: variableType as VariableType,\n protected: variableProtected,\n masked,\n raw,\n environmentScope,\n });\n },\n });\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","getClient"],"mappings":";;;;;;AA4Ba,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,+BAAA;AAAA,cACJC,6CAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,Q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,MAAO,CAAA;AAAA,UACN,WAAa,EAAA;AAAA,SACd,CAAA,CACA,OAAQ,CAAA,GAAG,EACX,QAAS;AAAA;AAChB,KACF;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAM,MAAA;AAAA,QACJ,OAAA;AAAA,QACA,SAAA;AAAA,QACA,GAAA;AAAA,QACA,KAAA;AAAA,QACA,YAAA;AAAA,QACA,iBAAoB,GAAA,KAAA;AAAA,QACpB,MAAS,GAAA,KAAA;AAAA,QACT,GAAM,GAAA,KAAA;AAAA,QACN,gBAAmB,GAAA,GAAA;AAAA,QACnB;AAAA,UACE,GAAI,CAAA,KAAA;AAER,MAAA,MAAM,EAAE,IAAA,EAAS,GAAAC,iBAAA,CAAa,SAAS,YAAY,CAAA;AAEnD,MAAA,MAAM,MAAMC,cAAU,CAAA,EAAE,IAAM,EAAA,YAAA,EAAc,OAAO,CAAA;AAEnD,MAAA,MAAM,IAAI,UAAW,CAAA;AAAA,QACnB,KAAK,CAA4B,yBAAA,EAAA,SAAS,CAAI,CAAA,EAAA,GAAG,IAAI,KAAK,CAAA,CAAA;AAAA,QAC1D,IAAI,YAAY;AACd,UAAA,MAAM,GAAI,CAAA,gBAAA,CAAiB,MAAO,CAAA,SAAA,EAAW,KAAK,KAAO,EAAA;AAAA,YACvD,YAAA;AAAA,YACA,SAAW,EAAA,iBAAA;AAAA,YACX,MAAA;AAAA,YACA,GAAA;AAAA,YACA;AAAA,WACD,CAAA;AAAA;AACH,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
4
3
|
var path = require('path');
|
|
5
4
|
var errors = require('@backstage/errors');
|
|
6
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
|
|
7
7
|
var helpers = require('./helpers.cjs.js');
|
|
8
8
|
var gitlabRepoPush_examples = require('./gitlabRepoPush.examples.cjs.js');
|
|
9
9
|
|
|
@@ -18,63 +18,38 @@ const createGitlabRepoPushAction = (options) => {
|
|
|
18
18
|
examples: gitlabRepoPush_examples.examples,
|
|
19
19
|
schema: {
|
|
20
20
|
input: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
description: "Subdirectory of working directory to copy changes from"
|
|
43
|
-
},
|
|
44
|
-
targetPath: {
|
|
45
|
-
type: "string",
|
|
46
|
-
title: "Repository Subdirectory",
|
|
47
|
-
description: "Subdirectory of repository to apply changes to"
|
|
48
|
-
},
|
|
49
|
-
token: {
|
|
50
|
-
title: "Authentication Token",
|
|
51
|
-
type: "string",
|
|
52
|
-
description: "The token to use for authorization to GitLab"
|
|
53
|
-
},
|
|
54
|
-
commitAction: {
|
|
55
|
-
title: "Commit action",
|
|
56
|
-
type: "string",
|
|
57
|
-
enum: ["create", "update", "delete"],
|
|
58
|
-
description: "The action to be used for git commit. Defaults to create, but can be set to update or delete"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
21
|
+
repoUrl: (z) => z.string({
|
|
22
|
+
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`
|
|
23
|
+
}),
|
|
24
|
+
branchName: (z) => z.string({
|
|
25
|
+
description: "The branch name for the commit"
|
|
26
|
+
}),
|
|
27
|
+
commitMessage: (z) => z.string({
|
|
28
|
+
description: `The commit message`
|
|
29
|
+
}),
|
|
30
|
+
sourcePath: (z) => z.string({
|
|
31
|
+
description: "Subdirectory of working directory to copy changes from"
|
|
32
|
+
}).optional(),
|
|
33
|
+
targetPath: (z) => z.string({
|
|
34
|
+
description: "Subdirectory of repository to apply changes to"
|
|
35
|
+
}).optional(),
|
|
36
|
+
token: (z) => z.string({
|
|
37
|
+
description: "The token to use for authorization to GitLab"
|
|
38
|
+
}).optional(),
|
|
39
|
+
commitAction: (z) => z.enum(["create", "update", "delete"], {
|
|
40
|
+
description: "The action to be used for git commit. Defaults to create, but can be set to update or delete"
|
|
41
|
+
}).optional()
|
|
61
42
|
},
|
|
62
43
|
output: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
commitHash: {
|
|
74
|
-
title: "The git commit hash of the commit",
|
|
75
|
-
type: "string"
|
|
76
|
-
}
|
|
77
|
-
}
|
|
44
|
+
projectid: (z) => z.string({
|
|
45
|
+
description: "Gitlab Project id/Name(slug)"
|
|
46
|
+
}),
|
|
47
|
+
projectPath: (z) => z.string({
|
|
48
|
+
description: "Gitlab Project path"
|
|
49
|
+
}),
|
|
50
|
+
commitHash: (z) => z.string({
|
|
51
|
+
description: "The git commit hash of the commit"
|
|
52
|
+
})
|
|
78
53
|
}
|
|
79
54
|
},
|
|
80
55
|
async handler(ctx) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlabRepoPush.cjs.js","sources":["../../src/actions/gitlabRepoPush.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport { CommitAction } from '@gitbeaker/rest';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { resolveSafeChildPath } from '@backstage/backend-plugin-api';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\n\n/**\n * Create a new action that commits into a gitlab repository.\n *\n * @public\n */\nexport const createGitlabRepoPushAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n branchName: string;\n commitMessage: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update';\n }>({\n id: 'gitlab:repo:push',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName', 'commitMessage'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The branch name for the commit',\n },\n commitMessage: {\n type: 'string',\n title: 'Commit Message',\n description: `The commit message`,\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description:\n 'Subdirectory of working directory to copy changes from',\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete'],\n description:\n 'The action to be used for git commit. Defaults to create, but can be set to update or delete',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n commitHash: {\n title: 'The git commit hash of the commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n branchName,\n repoUrl,\n targetPath,\n sourcePath,\n token,\n commitAction,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n const actions: CommitAction[] = fileContents.map(file => ({\n action: commitAction ?? 'create',\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n const branchExists = await ctx.checkpoint({\n key: `branch.exists.${repoID}.${branchName}`,\n fn: async () => {\n try {\n await api.Branches.show(repoID, branchName);\n return true;\n } catch (e: any) {\n if (e.cause?.response?.status !== 404) {\n throw new InputError(\n `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n return false;\n },\n });\n\n if (!branchExists) {\n // create a branch using the default branch as ref\n try {\n const projects = await api.Projects.show(repoID);\n const { default_branch: defaultBranch } = projects;\n await api.Branches.create(repoID, branchName, String(defaultBranch));\n } catch (e) {\n throw new InputError(\n `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n try {\n const commitId = await ctx.checkpoint({\n key: `commit.create.${repoID}.${branchName}`,\n fn: async () => {\n const commit = 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","path","InputError","getErrorMessage"],"mappings":";;;;;;;;;;;;;AAkCa,MAAA,0BAAA,GAA6B,CAAC,OAErC,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAQJ,CAAA;AAAA,IACD,EAAI,EAAA,kBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,QAAU,EAAA,CAAC,SAAW,EAAA,YAAA,EAAc,eAAe,CAAA;AAAA,QACnD,IAAM,EAAA,QAAA;AAAA,QACN,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,qBAAA;AAAA,YACP,WAAa,EAAA,CAAA,sJAAA;AAAA,WACf;AAAA,UACA,UAAY,EAAA;AAAA,YACV,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,oBAAA;AAAA,YACP,WAAa,EAAA;AAAA,WACf;AAAA,UACA,aAAe,EAAA;AAAA,YACb,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,gBAAA;AAAA,YACP,WAAa,EAAA,CAAA,kBAAA;AAAA,WACf;AAAA,UACA,UAAY,EAAA;AAAA,YACV,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,sBAAA;AAAA,YACP,WACE,EAAA;AAAA,WACJ;AAAA,UACA,UAAY,EAAA;AAAA,YACV,IAAM,EAAA,QAAA;AAAA,YACN,KAAO,EAAA,y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AAA,MAAM,IAAID,iBAAA;AAAA,UACR,CAAA,0BAAA,EAA6B,UAAU,CAAwF,qFAAA,EAAAC,uBAAA;AAAA,YAC7H;AAAA,WACD,CAAA;AAAA,SACH;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"gitlabRepoPush.cjs.js","sources":["../../src/actions/gitlabRepoPush.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from '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';\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'], {\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 },\n output: {\n projectid: z =>\n z.string({\n description: 'Gitlab Project id/Name(slug)',\n }),\n projectPath: z =>\n z.string({\n description: 'Gitlab Project path',\n }),\n commitHash: z =>\n z.string({\n description: 'The git commit hash of the commit',\n }),\n },\n },\n async handler(ctx) {\n const {\n branchName,\n repoUrl,\n targetPath,\n sourcePath,\n token,\n commitAction,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n const actions: CommitAction[] = fileContents.map(file => ({\n action: commitAction ?? 'create',\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n const branchExists = await ctx.checkpoint({\n key: `branch.exists.${repoID}.${branchName}`,\n fn: async () => {\n try {\n await api.Branches.show(repoID, branchName);\n return true;\n } catch (e: any) {\n if (e.cause?.response?.status !== 404) {\n throw new InputError(\n `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n return false;\n },\n });\n\n if (!branchExists) {\n // create a branch using the default branch as ref\n try {\n const projects = await api.Projects.show(repoID);\n const { default_branch: defaultBranch } = projects;\n await api.Branches.create(repoID, branchName, String(defaultBranch));\n } catch (e) {\n throw new InputError(\n `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n try {\n const commitId = await ctx.checkpoint({\n key: `commit.create.${repoID}.${branchName}`,\n fn: async () => {\n const commit = 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","path","InputError","getErrorMessage"],"mappings":";;;;;;;;;;;;;AAkCa,MAAA,0BAAA,GAA6B,CAAC,OAErC,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAAqB,CAAA;AAAA,IAC1B,EAAI,EAAA,kBAAA;AAAA,cACJC,gCAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,OAAA,EAAS,CACP,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,sJAAA;AAAA,SACd,CAAA;AAAA,QACH,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACH,aAAA,EAAe,CACb,CAAA,KAAA,CAAA,CAAE,MAAO,CAAA;AAAA,UACP,WAAa,EAAA,CAAA,kBAAA;AAAA,SACd,CAAA;AAAA,QACH,UAAA,EAAY,CACV,CAAA,KAAA,CAAA,CACG,MAA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AAU,CAA0F,uFAAA,EAAAC,uBAAA;AAAA,cAC/H;AAAA,aACD,CAAA;AAAA,WACH;AAAA;AAEF,QAAA,MAAM,IAAID,iBAAA;AAAA,UACR,CAAA,0BAAA,EAA6B,UAAU,CAAwF,qFAAA,EAAAC,uBAAA;AAAA,YAC7H;AAAA,WACD,CAAA;AAAA,SACH;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var zod = require('zod');
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
zod.z.object({
|
|
8
6
|
repoUrl: zod.z.string({ description: "Repository Location" }),
|
|
9
7
|
token: zod.z.string({ description: "The token to use for authorization to GitLab" }).optional()
|
|
10
8
|
});
|
|
@@ -28,5 +26,4 @@ var IssueStateEvent = /* @__PURE__ */ ((IssueStateEvent2) => {
|
|
|
28
26
|
exports.IssueStateEvent = IssueStateEvent;
|
|
29
27
|
exports.IssueType = IssueType;
|
|
30
28
|
exports.commonGitlabConfigExample = commonGitlabConfigExample;
|
|
31
|
-
exports.default = commonGitlabConfig;
|
|
32
29
|
//# sourceMappingURL=commonGitlabConfig.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonGitlabConfig.cjs.js","sources":["../src/commonGitlabConfig.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 { z } from 'zod';\n\nconst commonGitlabConfig = z.object({\n repoUrl: z.string({ description: 'Repository Location' }),\n token: z\n .string({ description: 'The token to use for authorization to GitLab' })\n .optional(),\n});\n\nexport default commonGitlabConfig;\n\nexport const commonGitlabConfigExample = {\n repoUrl: 'gitlab.com?owner=namespace-or-owner&repo=project-name',\n token: '${{ secrets.USER_OAUTH_TOKEN }}',\n};\n\n/**\n * Gitlab issue types as specified by gitlab api\n *\n * @public\n */\nexport enum IssueType {\n ISSUE = 'issue',\n INCIDENT = 'incident',\n TEST = 'test_case',\n TASK = 'task',\n}\n\n/**\n * Gitlab issue state events for modifications\n *\n * @public\n */\nexport enum IssueStateEvent {\n CLOSE = 'close',\n REOPEN = 'reopen',\n}\n"],"names":["z","IssueType","IssueStateEvent"],"mappings":"
|
|
1
|
+
{"version":3,"file":"commonGitlabConfig.cjs.js","sources":["../src/commonGitlabConfig.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 { z } from 'zod';\n\nconst commonGitlabConfig = z.object({\n repoUrl: z.string({ description: 'Repository Location' }),\n token: z\n .string({ description: 'The token to use for authorization to GitLab' })\n .optional(),\n});\n\nexport default commonGitlabConfig;\n\nexport const commonGitlabConfigExample = {\n repoUrl: 'gitlab.com?owner=namespace-or-owner&repo=project-name',\n token: '${{ secrets.USER_OAUTH_TOKEN }}',\n};\n\n/**\n * Gitlab issue types as specified by gitlab api\n *\n * @public\n */\nexport enum IssueType {\n ISSUE = 'issue',\n INCIDENT = 'incident',\n TEST = 'test_case',\n TASK = 'task',\n}\n\n/**\n * Gitlab issue state events for modifications\n *\n * @public\n */\nexport enum IssueStateEvent {\n CLOSE = 'close',\n REOPEN = 'reopen',\n}\n"],"names":["z","IssueType","IssueStateEvent"],"mappings":";;;;AAkB2BA,MAAE,MAAO,CAAA;AAAA,EAClC,SAASA,KAAE,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,uBAAuB,CAAA;AAAA,EACxD,KAAA,EAAOA,MACJ,MAAO,CAAA,EAAE,aAAa,8CAA+C,EAAC,EACtE,QAAS;AACd,CAAC;AAIM,MAAM,yBAA4B,GAAA;AAAA,EACvC,OAAS,EAAA,uDAAA;AAAA,EACT,KAAO,EAAA;AACT;AAOY,IAAA,SAAA,qBAAAC,UAAL,KAAA;AACL,EAAAA,WAAA,OAAQ,CAAA,GAAA,OAAA;AACR,EAAAA,WAAA,UAAW,CAAA,GAAA,UAAA;AACX,EAAAA,WAAA,MAAO,CAAA,GAAA,WAAA;AACP,EAAAA,WAAA,MAAO,CAAA,GAAA,MAAA;AAJG,EAAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;AAYA,IAAA,eAAA,qBAAAC,gBAAL,KAAA;AACL,EAAAA,iBAAA,OAAQ,CAAA,GAAA,OAAA;AACR,EAAAA,iBAAA,QAAS,CAAA,GAAA,QAAA;AAFC,EAAAA,OAAAA,gBAAAA;AAAA,CAAA,EAAA,eAAA,IAAA,EAAA;;;;;;"}
|