@backstage/plugin-scaffolder-backend-module-gitlab 0.8.1-next.2 → 0.8.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
+ ## 0.8.2-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/plugin-scaffolder-node@0.8.1-next.0
9
+ - @backstage/backend-plugin-api@1.2.1
10
+ - @backstage/config@1.3.2
11
+ - @backstage/errors@1.2.7
12
+ - @backstage/integration@1.16.2
13
+
14
+ ## 0.8.1
15
+
16
+ ### Patch Changes
17
+
18
+ - 0df33ea: fix: Creating a repository in a user namespace would always lead to an error
19
+ - 984b283: Made "gitlab:pipeline:trigger" action idempotent
20
+ - 225c733: Made gitlab:repo:push action idempotent.
21
+ - a08cb20: Remove usages of `@backstage/backend-common`
22
+ - ac58f84: Made gitlab:issue:edit action idempotent.
23
+ - f6b51a8: Made "gitlab:projectDeployToken:create" action idempotent
24
+ - a75e18f: Change the if statement in the catch block to match what the new version of Gitbeaker will return
25
+ - 36af946: Made "gitlab:projectVariable:create" action idempotent
26
+ - 1cea434: Made "gitlab:projectAccessToken:create" action idempotent
27
+ - 4f8b5b6: Allow signing git commits using configured private PGP key in scaffolder
28
+ - 83ae330: Made "gitlab:group:migrate" action idempotent
29
+ - Updated dependencies
30
+ - @backstage/integration@1.16.2
31
+ - @backstage/plugin-scaffolder-node@0.8.0
32
+ - @backstage/backend-plugin-api@1.2.1
33
+ - @backstage/config@1.3.2
34
+ - @backstage/errors@1.2.7
35
+
3
36
  ## 0.8.1-next.2
4
37
 
5
38
  ### Patch Changes
@@ -30,33 +30,49 @@ const createTriggerGitlabPipelineAction = (options) => {
30
30
  output: pipelineOutputProperties
31
31
  },
32
32
  async handler(ctx) {
33
- let pipelineTokenResponse = null;
33
+ let pipelineTriggerToken = void 0;
34
+ let pipelineTriggerId = void 0;
34
35
  const { repoUrl, projectId, tokenDescription, token, branch, variables } = commonGitlabConfig.default.merge(pipelineInputProperties).parse(ctx.input);
35
36
  const { host } = util.parseRepoUrl(repoUrl, integrations);
36
37
  const api = util.getClient({ host, integrations, token });
37
38
  try {
38
- pipelineTokenResponse = await api.PipelineTriggerTokens.create(
39
- projectId,
40
- tokenDescription
41
- );
42
- if (!pipelineTokenResponse.token) {
43
- ctx.logger.error("Failed to create pipeline token.");
39
+ ({ pipelineTriggerToken, pipelineTriggerId } = await ctx.checkpoint({
40
+ key: `create.pipeline.token.${projectId}`,
41
+ fn: async () => {
42
+ const res = await api.PipelineTriggerTokens.create(
43
+ projectId,
44
+ tokenDescription
45
+ );
46
+ return {
47
+ pipelineTriggerToken: res.token,
48
+ pipelineTriggerId: res.id
49
+ };
50
+ }
51
+ }));
52
+ if (!pipelineTriggerToken) {
53
+ ctx.logger.error(
54
+ `Failed to create pipeline token for project ${projectId}.`
55
+ );
44
56
  return;
45
57
  }
46
58
  ctx.logger.info(
47
- `Pipeline token id ${pipelineTokenResponse.id} created.`
59
+ `Pipeline token id ${pipelineTriggerId} created for project ${projectId}.`
48
60
  );
49
61
  const pipelineTriggerResponse = await api.PipelineTriggerTokens.trigger(
50
62
  projectId,
51
63
  branch,
52
- pipelineTokenResponse.token,
64
+ pipelineTriggerToken,
53
65
  { variables }
54
66
  );
55
67
  if (!pipelineTriggerResponse.id) {
56
- ctx.logger.error("Failed to trigger pipeline.");
68
+ ctx.logger.error(
69
+ `Failed to trigger pipeline for project ${projectId}.`
70
+ );
57
71
  return;
58
72
  }
59
- ctx.logger.info(`Pipeline id ${pipelineTriggerResponse.id} triggered.`);
73
+ ctx.logger.info(
74
+ `Pipeline id ${pipelineTriggerResponse.id} for project ${projectId} triggered.`
75
+ );
60
76
  ctx.output("pipelineUrl", pipelineTriggerResponse.web_url);
61
77
  } catch (error) {
62
78
  if (error instanceof zod.z.ZodError) {
@@ -68,18 +84,25 @@ const createTriggerGitlabPipelineAction = (options) => {
68
84
  `Failed to trigger Pipeline: ${helpers.getErrorMessage(error)}`
69
85
  );
70
86
  } finally {
71
- if (pipelineTokenResponse && pipelineTokenResponse.id) {
87
+ if (pipelineTriggerId) {
72
88
  try {
73
- await api.PipelineTriggerTokens.remove(
74
- projectId,
75
- pipelineTokenResponse.id
76
- );
89
+ await ctx.checkpoint({
90
+ key: `create.delete.token.${projectId}`,
91
+ fn: async () => {
92
+ if (pipelineTriggerId) {
93
+ await api.PipelineTriggerTokens.remove(
94
+ projectId,
95
+ pipelineTriggerId
96
+ );
97
+ }
98
+ }
99
+ });
77
100
  ctx.logger.info(
78
- `Deleted pipeline token ${pipelineTokenResponse.id}.`
101
+ `Deleted pipeline with token id ${pipelineTriggerId}.`
79
102
  );
80
103
  } catch (error) {
81
104
  ctx.logger.error(
82
- `Failed to delete pipeline token id ${pipelineTokenResponse.id}.`
105
+ `Failed to delete pipeline with token id ${pipelineTriggerId}.`
83
106
  );
84
107
  }
85
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabPipelineTrigger.cjs.js","sources":["../../src/actions/gitlabPipelineTrigger.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport {\n ExpandedPipelineSchema,\n PipelineTriggerTokenSchema,\n} from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabPipelineTrigger.examples';\nimport { getErrorMessage } from './helpers';\n\nconst pipelineInputProperties = z.object({\n projectId: z.number().describe('Project Id'),\n tokenDescription: z.string().describe('Pipeline token description'),\n branch: z.string().describe('Project branch'),\n variables: z\n .record(z.string(), z.string())\n .optional()\n .describe(\n 'A object/record of key-valued strings containing the pipeline variables.',\n ),\n});\n\nconst pipelineOutputProperties = z.object({\n pipelineUrl: z.string({ description: 'Pipeline Url' }),\n});\n\n/**\n * Creates a `gitlab:pipeline:trigger` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createTriggerGitlabPipelineAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:pipeline:trigger',\n description: 'Triggers a GitLab Pipeline.',\n examples,\n schema: {\n input: commonGitlabConfig.merge(pipelineInputProperties),\n output: pipelineOutputProperties,\n },\n async handler(ctx) {\n let pipelineTokenResponse: PipelineTriggerTokenSchema | null = null;\n\n const { repoUrl, projectId, tokenDescription, token, branch, variables } =\n commonGitlabConfig.merge(pipelineInputProperties).parse(ctx.input);\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n try {\n // Create a pipeline token\n pipelineTokenResponse = (await api.PipelineTriggerTokens.create(\n projectId,\n tokenDescription,\n )) as PipelineTriggerTokenSchema;\n\n if (!pipelineTokenResponse.token) {\n ctx.logger.error('Failed to create pipeline token.');\n return;\n }\n ctx.logger.info(\n `Pipeline token id ${pipelineTokenResponse.id} created.`,\n );\n\n // Use the pipeline token to trigger the pipeline in the project\n const pipelineTriggerResponse =\n (await api.PipelineTriggerTokens.trigger(\n projectId,\n branch,\n pipelineTokenResponse.token,\n { variables },\n )) as ExpandedPipelineSchema;\n\n if (!pipelineTriggerResponse.id) {\n ctx.logger.error('Failed to trigger pipeline.');\n return;\n }\n\n ctx.logger.info(`Pipeline id ${pipelineTriggerResponse.id} triggered.`);\n\n ctx.output('pipelineUrl', pipelineTriggerResponse.web_url);\n } catch (error: any) {\n if (error instanceof z.ZodError) {\n // Handling Zod validation errors\n throw new InputError(`Validation error: ${error.message}`, {\n validationErrors: error.errors,\n });\n }\n // Handling other errors\n throw new InputError(\n `Failed to trigger Pipeline: ${getErrorMessage(error)}`,\n );\n } finally {\n // Delete the pipeline token if it was created\n if (pipelineTokenResponse && pipelineTokenResponse.id) {\n try {\n await api.PipelineTriggerTokens.remove(\n projectId,\n pipelineTokenResponse.id,\n );\n ctx.logger.info(\n `Deleted pipeline token ${pipelineTokenResponse.id}.`,\n );\n } catch (error: any) {\n ctx.logger.error(\n `Failed to delete pipeline token id ${pipelineTokenResponse.id}.`,\n );\n }\n }\n }\n },\n });\n};\n"],"names":["z","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","InputError","getErrorMessage"],"mappings":";;;;;;;;;;AA6BA,MAAM,uBAAA,GAA0BA,MAAE,MAAO,CAAA;AAAA,EACvC,SAAW,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,YAAY,CAAA;AAAA,EAC3C,gBAAkB,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,4BAA4B,CAAA;AAAA,EAClE,MAAQ,EAAAA,KAAA,CAAE,MAAO,EAAA,CAAE,SAAS,gBAAgB,CAAA;AAAA,EAC5C,SAAA,EAAWA,KACR,CAAA,MAAA,CAAOA,KAAE,CAAA,MAAA,EAAU,EAAAA,KAAA,CAAE,MAAO,EAAC,CAC7B,CAAA,QAAA,EACA,CAAA,QAAA;AAAA,IACC;AAAA;AAEN,CAAC,CAAA;AAED,MAAM,wBAAA,GAA2BA,MAAE,MAAO,CAAA;AAAA,EACxC,aAAaA,KAAE,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,gBAAgB;AACvD,CAAC,CAAA;AAQY,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,c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AA;AAC/B,UAAI,GAAA,CAAA,MAAA,CAAO,MAAM,6BAA6B,CAAA;AAC9C,UAAA;AAAA;AAGF,QAAA,GAAA,CAAI,MAAO,CAAA,IAAA,CAAK,CAAe,YAAA,EAAA,uBAAA,CAAwB,EAAE,CAAa,WAAA,CAAA,CAAA;AAEtE,QAAI,GAAA,CAAA,MAAA,CAAO,aAAe,EAAA,uBAAA,CAAwB,OAAO,CAAA;AAAA,eAClD,KAAY,EAAA;AACnB,QAAI,IAAA,KAAA,YAAiBL,MAAE,QAAU,EAAA;AAE/B,UAAA,MAAM,IAAIM,iBAAA,CAAW,CAAqB,kBAAA,EAAA,KAAA,CAAM,OAAO,CAAI,CAAA,EAAA;AAAA,YACzD,kBAAkB,KAAM,CAAA;AAAA,WACzB,CAAA;AAAA;AAGH,QAAA,MAAM,IAAIA,iBAAA;AAAA,UACR,CAAA,4BAAA,EAA+BC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SACvD;AAAA,OACA,SAAA;AAEA,QAAI,IAAA,qBAAA,IAAyB,sBAAsB,EAAI,EAAA;AACrD,UAAI,IAAA;AACF,YAAA,MAAM,IAAI,qBAAsB,CAAA,MAAA;AAAA,cAC9B,SAAA;AAAA,cACA,qBAAsB,CAAA;AAAA,aACxB;AACA,YAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,cACT,CAAA,uBAAA,EAA0B,sBAAsB,EAAE,CAAA,CAAA;AAAA,aACpD;AAAA,mBACO,KAAY,EAAA;AACnB,YAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,cACT,CAAA,mCAAA,EAAsC,sBAAsB,EAAE,CAAA,CAAA;AAAA,aAChE;AAAA;AACF;AACF;AACF;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabPipelineTrigger.cjs.js","sources":["../../src/actions/gitlabPipelineTrigger.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport {\n ExpandedPipelineSchema,\n PipelineTriggerTokenSchema,\n} from '@gitbeaker/rest';\nimport { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getClient, parseRepoUrl } from '../util';\nimport { examples } from './gitlabPipelineTrigger.examples';\nimport { getErrorMessage } from './helpers';\n\nconst pipelineInputProperties = z.object({\n projectId: z.number().describe('Project Id'),\n tokenDescription: z.string().describe('Pipeline token description'),\n branch: z.string().describe('Project branch'),\n variables: z\n .record(z.string(), z.string())\n .optional()\n .describe(\n 'A object/record of key-valued strings containing the pipeline variables.',\n ),\n});\n\nconst pipelineOutputProperties = z.object({\n pipelineUrl: z.string({ description: 'Pipeline Url' }),\n});\n\n/**\n * Creates a `gitlab:pipeline:trigger` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createTriggerGitlabPipelineAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:pipeline:trigger',\n description: 'Triggers a GitLab Pipeline.',\n examples,\n schema: {\n input: commonGitlabConfig.merge(pipelineInputProperties),\n output: pipelineOutputProperties,\n },\n async handler(ctx) {\n let pipelineTriggerToken: string | undefined = undefined;\n let pipelineTriggerId: number | undefined = undefined;\n\n const { repoUrl, projectId, tokenDescription, token, branch, variables } =\n commonGitlabConfig.merge(pipelineInputProperties).parse(ctx.input);\n\n const { host } = parseRepoUrl(repoUrl, integrations);\n const api = getClient({ host, integrations, token });\n\n try {\n ({ pipelineTriggerToken, pipelineTriggerId } = await ctx.checkpoint({\n key: `create.pipeline.token.${projectId}`,\n fn: async () => {\n const res = (await api.PipelineTriggerTokens.create(\n projectId,\n tokenDescription,\n )) as PipelineTriggerTokenSchema;\n return {\n pipelineTriggerToken: res.token,\n pipelineTriggerId: res.id,\n };\n },\n }));\n\n if (!pipelineTriggerToken) {\n ctx.logger.error(\n `Failed to create pipeline token for project ${projectId}.`,\n );\n return;\n }\n ctx.logger.info(\n `Pipeline token id ${pipelineTriggerId} created for project ${projectId}.`,\n );\n\n // Use the pipeline token to trigger the pipeline in the project\n const pipelineTriggerResponse =\n (await api.PipelineTriggerTokens.trigger(\n projectId,\n branch,\n pipelineTriggerToken,\n { variables },\n )) as ExpandedPipelineSchema;\n\n if (!pipelineTriggerResponse.id) {\n ctx.logger.error(\n `Failed to trigger pipeline for project ${projectId}.`,\n );\n return;\n }\n\n ctx.logger.info(\n `Pipeline id ${pipelineTriggerResponse.id} for project ${projectId} triggered.`,\n );\n\n ctx.output('pipelineUrl', pipelineTriggerResponse.web_url);\n } catch (error: any) {\n if (error instanceof z.ZodError) {\n // Handling Zod validation errors\n throw new InputError(`Validation error: ${error.message}`, {\n validationErrors: error.errors,\n });\n }\n // Handling other errors\n throw new InputError(\n `Failed to trigger Pipeline: ${getErrorMessage(error)}`,\n );\n } finally {\n // Delete the pipeline token if it was created\n if (pipelineTriggerId) {\n try {\n await ctx.checkpoint({\n key: `create.delete.token.${projectId}`,\n fn: async () => {\n if (pipelineTriggerId) {\n // to make the current version of TypeScript happy\n await api.PipelineTriggerTokens.remove(\n projectId,\n pipelineTriggerId,\n );\n }\n },\n });\n ctx.logger.info(\n `Deleted pipeline with token id ${pipelineTriggerId}.`,\n );\n } catch (error: any) {\n ctx.logger.error(\n `Failed to delete pipeline with token id ${pipelineTriggerId}.`,\n );\n }\n }\n }\n },\n });\n};\n"],"names":["z","createTemplateAction","examples","commonGitlabConfig","parseRepoUrl","getClient","InputError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AAA,EAAA,uBAAA,CAAwB,EAAE,CAAA,aAAA,EAAgB,SAAS,CAAA,WAAA;AAAA,SACpE;AAEA,QAAI,GAAA,CAAA,MAAA,CAAO,aAAe,EAAA,uBAAA,CAAwB,OAAO,CAAA;AAAA,eAClD,KAAY,EAAA;AACnB,QAAI,IAAA,KAAA,YAAiBL,MAAE,QAAU,EAAA;AAE/B,UAAA,MAAM,IAAIM,iBAAA,CAAW,CAAqB,kBAAA,EAAA,KAAA,CAAM,OAAO,CAAI,CAAA,EAAA;AAAA,YACzD,kBAAkB,KAAM,CAAA;AAAA,WACzB,CAAA;AAAA;AAGH,QAAA,MAAM,IAAIA,iBAAA;AAAA,UACR,CAAA,4BAAA,EAA+BC,uBAAgB,CAAA,KAAK,CAAC,CAAA;AAAA,SACvD;AAAA,OACA,SAAA;AAEA,QAAA,IAAI,iBAAmB,EAAA;AACrB,UAAI,IAAA;AACF,YAAA,MAAM,IAAI,UAAW,CAAA;AAAA,cACnB,GAAA,EAAK,uBAAuB,SAAS,CAAA,CAAA;AAAA,cACrC,IAAI,YAAY;AACd,gBAAA,IAAI,iBAAmB,EAAA;AAErB,kBAAA,MAAM,IAAI,qBAAsB,CAAA,MAAA;AAAA,oBAC9B,SAAA;AAAA,oBACA;AAAA,mBACF;AAAA;AACF;AACF,aACD,CAAA;AACD,YAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,cACT,kCAAkC,iBAAiB,CAAA,CAAA;AAAA,aACrD;AAAA,mBACO,KAAY,EAAA;AACnB,YAAA,GAAA,CAAI,MAAO,CAAA,KAAA;AAAA,cACT,2CAA2C,iBAAiB,CAAA,CAAA;AAAA,aAC9D;AAAA;AACF;AACF;AACF;AACF,GACD,CAAA;AACH;;;;"}
@@ -64,19 +64,25 @@ const createGitlabProjectAccessTokenAction = (options) => {
64
64
  oauthToken: token
65
65
  });
66
66
  }
67
- const response = await api.ProjectAccessTokens.create(
68
- projectId,
69
- name,
70
- scopes,
71
- expiresAt || luxon.DateTime.now().plus({ days: 365 }).toISODate(),
72
- {
73
- accessLevel
67
+ const projectAccessToken = await ctx.checkpoint({
68
+ key: `project.access.token.${projectId}.${name}`,
69
+ fn: async () => {
70
+ const response = await api.ProjectAccessTokens.create(
71
+ projectId,
72
+ name,
73
+ scopes,
74
+ expiresAt || luxon.DateTime.now().plus({ days: 365 }).toISODate(),
75
+ {
76
+ accessLevel
77
+ }
78
+ );
79
+ return response.token;
74
80
  }
75
- );
76
- if (!response.token) {
81
+ });
82
+ if (!projectAccessToken) {
77
83
  throw new Error("Could not create project access token");
78
84
  }
79
- ctx.output("access_token", response.token);
85
+ ctx.output("access_token", projectAccessToken);
80
86
  }
81
87
  });
82
88
  };
@@ -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 { z } from 'zod';\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: z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID/Name(slug) of the Gitlab Project',\n }),\n token: z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n name: z.string({ description: 'Name of Access Key' }).optional(),\n repoUrl: z.string({ description: 'URL to gitlab instance' }),\n accessLevel: 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 .string({\n description: 'Scopes for a project access token',\n })\n .array()\n .optional(),\n expiresAt: 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: z.object({\n access_token: z.string({ description: 'Access Token' }),\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 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\n if (!response.token) {\n throw new Error('Could not create project access token');\n }\n\n ctx.output('access_token', response.token);\n },\n });\n};\n"],"names":["createTemplateAction","examples","z","getToken","InputError","Gitlab","DateTime"],"mappings":";;;;;;;;;;AAgCa,MAAA,oCAAA,GAAuC,CAAC,OAE/C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA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GACD,CAAA;AACH;;;;"}
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 { z } from 'zod';\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: z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID/Name(slug) of the Gitlab Project',\n }),\n token: z\n .string({\n description: 'The token to use for authorization to GitLab',\n })\n .optional(),\n name: z.string({ description: 'Name of Access Key' }).optional(),\n repoUrl: z.string({ description: 'URL to gitlab instance' }),\n accessLevel: 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 .string({\n description: 'Scopes for a project access token',\n })\n .array()\n .optional(),\n expiresAt: 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: z.object({\n access_token: z.string({ description: 'Access Token' }),\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","z","getToken","InputError","Gitlab","DateTime"],"mappings":";;;;;;;;;;AAgCa,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,KAAA,EAAOC,MAAE,MAAO,CAAA;AAAA,QACd,SAAA,EAAWA,KAAE,CAAA,KAAA,CAAM,CAACA,KAAA,CAAE,QAAU,EAAAA,KAAA,CAAE,MAAO,EAAC,CAAG,EAAA;AAAA,UAC3C,WAAa,EAAA;AAAA,SACd,CAAA;AAAA,QACD,KAAA,E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4BAAA,EAA+B,iBAAkB,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,SACjE;AAAA;AAGF,MAAI,IAAA,GAAA;AAEJ,MAAI,IAAA,CAAC,GAAI,CAAA,KAAA,CAAM,KAAO,EAAA;AACpB,QAAA,GAAA,GAAM,IAAIC,WAAO,CAAA;AAAA,UACf,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,UAC/B;AAAA,SACD,CAAA;AAAA,OACI,MAAA;AACL,QAAA,GAAA,GAAM,IAAIA,WAAO,CAAA;AAAA,UACf,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,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;;;;"}
@@ -42,19 +42,28 @@ const createGitlabProjectDeployTokenAction = (options) => {
42
42
  host: integrationConfig.config.baseUrl,
43
43
  token
44
44
  });
45
- const deployToken = await api.DeployTokens.create(
46
- name,
47
- scopes,
48
- {
49
- projectId,
50
- username
45
+ const { deployToken, deployUsername } = await ctx.checkpoint({
46
+ key: `create.deploy.token.${projectId}.${name}`,
47
+ fn: async () => {
48
+ const res = await api.DeployTokens.create(
49
+ name,
50
+ scopes,
51
+ {
52
+ projectId,
53
+ username
54
+ }
55
+ );
56
+ if (!res.hasOwnProperty("token")) {
57
+ throw new errors.InputError(`No deploy_token given from gitlab instance`);
58
+ }
59
+ return {
60
+ deployToken: res.token,
61
+ deployUsername: res.username
62
+ };
51
63
  }
52
- );
53
- if (!deployToken.hasOwnProperty("token")) {
54
- throw new errors.InputError(`No deploy_token given from gitlab instance`);
55
- }
56
- ctx.output("deploy_token", deployToken.token);
57
- ctx.output("user", deployToken.username);
64
+ });
65
+ ctx.output("deploy_token", deployToken);
66
+ ctx.output("user", deployUsername);
58
67
  }
59
68
  });
60
69
  };
@@ -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 { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\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: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }),\n username: z\n .string({ description: 'Deploy Token Username' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }),\n }),\n ),\n output: z.object({\n deploy_token: z.string({ description: 'Deploy Token' }),\n user: z.string({ description: 'User' }),\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 = await api.DeployTokens.create(\n name,\n scopes as DeployTokenScope[],\n {\n projectId,\n username,\n },\n );\n\n if (!deployToken.hasOwnProperty('token')) {\n throw new InputError(`No deploy_token given from gitlab instance`);\n }\n\n ctx.output('deploy_token', deployToken.token as string);\n ctx.output('user', deployToken.username);\n },\n });\n};\n"],"names":["createTemplateAction","examples","commonGitlabConfig","z","getToken","InputError","Gitlab"],"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,OAAOC,0BAAmB,CAAA,KAAA;AAAA,QACxBC,MAAE,MAAO,CAAA;AAAA,UACP,SAAA,EAAW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,OAAA;AAAA,QAC/B;AAAA,OACD,CAAA;AAED,MAAM,MAAA,WAAA,GAAc,MAAM,GAAA,CAAI,YAAa,CAAA,MAAA;AAAA,QACzC,IAAA;AAAA,QACA,MAAA;AAAA,QACA;AAAA,UACE,SAAA;AAAA,UACA;AAAA;AACF,OACF;AAEA,MAAA,IAAI,CAAC,WAAA,CAAY,cAAe,CAAA,OAAO,CAAG,EAAA;AACxC,QAAM,MAAA,IAAID,kBAAW,CAA4C,0CAAA,CAAA,CAAA;AAAA;AAGnE,MAAI,GAAA,CAAA,MAAA,CAAO,cAAgB,EAAA,WAAA,CAAY,KAAe,CAAA;AACtD,MAAI,GAAA,CAAA,MAAA,CAAO,MAAQ,EAAA,WAAA,CAAY,QAAQ,CAAA;AAAA;AACzC,GACD,CAAA;AACH;;;;"}
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 { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\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: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }),\n username: z\n .string({ description: 'Deploy Token Username' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }),\n }),\n ),\n output: z.object({\n deploy_token: z.string({ description: 'Deploy Token' }),\n user: z.string({ description: 'User' }),\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","commonGitlabConfig","z","getToken","InputError","Gitlab"],"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,OAAOC,0BAAmB,CAAA,KAAA;AAAA,QACxBC,MAAE,MA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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;;;;"}
@@ -98,10 +98,16 @@ const createGitlabProjectMigrateAction = (options) => {
98
98
  access_token: sourceAccessToken
99
99
  };
100
100
  try {
101
- const { id: migrationId } = await api.Migrations.create(
102
- sourceConfig,
103
- migrationEntity
104
- );
101
+ const migrationId = await ctx.checkpoint({
102
+ key: `create.migration.${sourceUrl}`,
103
+ fn: async () => {
104
+ const migrationStatus = await api.Migrations.create(
105
+ sourceConfig,
106
+ migrationEntity
107
+ );
108
+ return migrationStatus.id;
109
+ }
110
+ });
105
111
  ctx.output(
106
112
  "importedRepoUrl",
107
113
  `${destinationHost}/${destinationNamespace}/${destinationSlug}`
@@ -1 +1 @@
1
- {"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n migrationId: {\n title: 'Id of the migration that imports the project',\n type: 'number',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n const { id: migrationId } = await api.Migrations.create(\n sourceConfig,\n migrationEntity,\n );\n\n ctx.output(\n 'importedRepoUrl',\n `${destinationHost}/${destinationNamespace}/${destinationSlug}`,\n );\n ctx.output('migrationId', migrationId);\n } catch (e: any) {\n throw new InputError(\n `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.\\nError: ${e}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","createGitlabApi"],"mappings":";;;;;;;AA+Ba,MAAA,gCAAA,GAAmC,CAAC,OAE3C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAMJ,CAAA;AAAA,IACD,EAAI,EAAA,sBAAA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F;AACF,GACD,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n migrationId: {\n title: 'Id of the migration that imports the project',\n type: 'number',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n const 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,G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Ae,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;;;;"}
@@ -46,12 +46,17 @@ const createGitlabProjectVariableAction = (options) => {
46
46
  } = ctx.input;
47
47
  const { host } = util.parseRepoUrl(repoUrl, integrations);
48
48
  const api = util.getClient({ host, integrations, token });
49
- await api.ProjectVariables.create(projectId, key, value, {
50
- variableType,
51
- protected: variableProtected,
52
- masked,
53
- raw,
54
- environmentScope
49
+ await ctx.checkpoint({
50
+ key: `create.project.variables.${projectId}.${key}.${value}`,
51
+ fn: async () => {
52
+ await api.ProjectVariables.create(projectId, key, value, {
53
+ variableType,
54
+ protected: variableProtected,
55
+ masked,
56
+ raw,
57
+ environmentScope
58
+ });
59
+ }
55
60
  });
56
61
  }
57
62
  });
@@ -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 { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\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: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: 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.string({ description: 'The value of a variable' }),\n variableType: z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z\n .boolean({ description: 'Whether the variable is protected' })\n .default(false)\n .optional(),\n masked: z\n .boolean({ description: 'Whether the variable is masked' })\n .default(false)\n .optional(),\n raw: z\n .boolean({ description: 'Whether the variable is expandable' })\n .default(false)\n .optional(),\n environmentScope: z\n .string({ description: 'The environment_scope of the variable' })\n .default('*')\n .optional(),\n }),\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 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"],"names":["createTemplateAction","examples","commonGitlabConfig","z","parseRepoUrl","getClient"],"mappings":";;;;;;;;AA8Ba,MAAA,iCAAA,GAAoC,CAAC,OAE5C,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,EAAA,OAAOA,yCAAqB,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ACA,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,GAAI,CAAA,gBAAA,CAAiB,MAAO,CAAA,SAAA,EAAW,KAAK,KAAO,EAAA;AAAA,QACvD,YAAA;AAAA,QACA,SAAW,EAAA,iBAAA;AAAA,QACX,MAAA;AAAA,QACA,GAAA;AAAA,QACA;AAAA,OACD,CAAA;AAAA;AACH,GACD,CAAA;AACH;;;;"}
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 { z } from 'zod';\nimport commonGitlabConfig from '../commonGitlabConfig';\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: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: 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.string({ description: 'The value of a variable' }),\n variableType: z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z\n .boolean({ description: 'Whether the variable is protected' })\n .default(false)\n .optional(),\n masked: z\n .boolean({ description: 'Whether the variable is masked' })\n .default(false)\n .optional(),\n raw: z\n .boolean({ description: 'Whether the variable is expandable' })\n .default(false)\n .optional(),\n environmentScope: z\n .string({ description: 'The environment_scope of the variable' })\n .default('*')\n .optional(),\n }),\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","commonGitlabConfig","z","parseRepoUrl","getClient"],"mappings":";;;;;;;;AA8Ba,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,M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A;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;;;;"}
@@ -109,19 +109,24 @@ const createGitlabRepoPushAction = (options) => {
109
109
  content: file.content.toString("base64"),
110
110
  execute_filemode: file.executable
111
111
  }));
112
- let branchExists = false;
113
- try {
114
- await api.Branches.show(repoID, branchName);
115
- branchExists = true;
116
- } catch (e) {
117
- if (e.cause?.response?.status !== 404) {
118
- throw new errors.InputError(
119
- `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${helpers.getErrorMessage(
120
- e
121
- )}`
122
- );
112
+ const branchExists = await ctx.checkpoint({
113
+ key: `branch.exists.${repoID}.${branchName}`,
114
+ fn: async () => {
115
+ try {
116
+ await api.Branches.show(repoID, branchName);
117
+ return true;
118
+ } catch (e) {
119
+ if (e.cause?.response?.status !== 404) {
120
+ throw new errors.InputError(
121
+ `Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${helpers.getErrorMessage(
122
+ e
123
+ )}`
124
+ );
125
+ }
126
+ }
127
+ return false;
123
128
  }
124
- }
129
+ });
125
130
  if (!branchExists) {
126
131
  try {
127
132
  const projects = await api.Projects.show(repoID);
@@ -136,15 +141,21 @@ const createGitlabRepoPushAction = (options) => {
136
141
  }
137
142
  }
138
143
  try {
139
- const commit = await api.Commits.create(
140
- repoID,
141
- branchName,
142
- ctx.input.commitMessage,
143
- actions
144
- );
144
+ const commitId = await ctx.checkpoint({
145
+ key: `commit.create.${repoID}.${branchName}`,
146
+ fn: async () => {
147
+ const commit = await api.Commits.create(
148
+ repoID,
149
+ branchName,
150
+ ctx.input.commitMessage,
151
+ actions
152
+ );
153
+ return commit.id;
154
+ }
155
+ });
145
156
  ctx.output("projectid", repoID);
146
157
  ctx.output("projectPath", repoID);
147
- ctx.output("commitHash", commit.id);
158
+ ctx.output("commitHash", commitId);
148
159
  } catch (e) {
149
160
  throw new errors.InputError(
150
161
  `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${helpers.getErrorMessage(
@@ -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.',\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 let branchExists = false;\n try {\n await api.Branches.show(repoID, branchName);\n branchExists = 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\n if (!branchExists) {\n // create a branch using the default branch as ref\n try {\n const projects = await api.Projects.show(repoID);\n const { default_branch: defaultBranch } = projects;\n await api.Branches.create(repoID, branchName, String(defaultBranch));\n } catch (e) {\n throw new InputError(\n `The branch '${branchName}' was not found and creation failed with error. Please make sure that branch already exists or Backstage has permissions to create one. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n\n try {\n const commit = await api.Commits.create(\n repoID,\n branchName,\n ctx.input.commitMessage,\n actions,\n );\n ctx.output('projectid', repoID);\n ctx.output('projectPath', repoID);\n ctx.output('commitHash', commit.id);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${getErrorMessage(\n e,\n )}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","path","InputError","getErrorMessage"],"mappings":";;;;;;;;;;;;;AAkCa,MAAA,0BAAA,GAA6B,CAAC,OAErC,KAAA;AACJ,EAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AAEzB,EAAA,OAAOA,yCAQJ,CAAA;AAAA,IAC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AA,CAAA,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA,CAAO,YAAc,EAAA,MAAA,CAAO,EAAE,CAAA;AAAA,eAC3B,CAAG,EAAA;AACV,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
+ {"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.',\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 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,IA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,YAAY;AACd,YAAM,MAAA,MAAA,GAAS,MAAM,GAAA,CAAI,OAAQ,CAAA,MAAA;AAAA,cAC/B,MAAA;AAAA,cACA,UAAA;AAAA,cACA,IAAI,KAAM,CAAA,aAAA;AAAA,cACV;AAAA,aACF;AACA,YAAA,OAAO,MAAO,CAAA,EAAA;AAAA;AAChB,SACD,CAAA;AAED,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA,CAAO,cAAc,QAAQ,CAAA;AAAA,eAC1B,CAAG,EAAA;AACV,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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-gitlab",
3
- "version": "0.8.1-next.2",
3
+ "version": "0.8.2-next.0",
4
4
  "backstage": {
5
5
  "role": "backend-plugin-module",
6
6
  "pluginId": "scaffolder",
@@ -46,11 +46,11 @@
46
46
  "test": "backstage-cli package test"
47
47
  },
48
48
  "dependencies": {
49
- "@backstage/backend-plugin-api": "1.2.1-next.1",
49
+ "@backstage/backend-plugin-api": "1.2.1",
50
50
  "@backstage/config": "1.3.2",
51
51
  "@backstage/errors": "1.2.7",
52
- "@backstage/integration": "1.16.2-next.0",
53
- "@backstage/plugin-scaffolder-node": "0.8.0-next.2",
52
+ "@backstage/integration": "1.16.2",
53
+ "@backstage/plugin-scaffolder-node": "0.8.1-next.0",
54
54
  "@gitbeaker/rest": "^41.2.0",
55
55
  "luxon": "^3.0.0",
56
56
  "winston": "^3.2.1",
@@ -58,9 +58,9 @@
58
58
  "zod": "^3.22.4"
59
59
  },
60
60
  "devDependencies": {
61
- "@backstage/backend-test-utils": "1.3.1-next.2",
62
- "@backstage/cli": "0.31.0-next.1",
63
- "@backstage/core-app-api": "1.16.0-next.0",
64
- "@backstage/plugin-scaffolder-node-test-utils": "0.2.0-next.2"
61
+ "@backstage/backend-test-utils": "1.3.2-next.0",
62
+ "@backstage/cli": "0.32.0-next.0",
63
+ "@backstage/core-app-api": "1.16.0",
64
+ "@backstage/plugin-scaffolder-node-test-utils": "0.2.1-next.0"
65
65
  }
66
66
  }