@backstage/plugin-scaffolder-backend-module-gitlab 0.5.1-next.0 → 0.6.0-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.
Files changed (52) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/actions/gitlab.cjs.js +374 -0
  3. package/dist/actions/gitlab.cjs.js.map +1 -0
  4. package/dist/actions/gitlab.examples.cjs.js +155 -0
  5. package/dist/actions/gitlab.examples.cjs.js.map +1 -0
  6. package/dist/actions/gitlabGroupEnsureExists.cjs.js +68 -0
  7. package/dist/actions/gitlabGroupEnsureExists.cjs.js.map +1 -0
  8. package/dist/actions/gitlabGroupEnsureExists.examples.cjs.js +78 -0
  9. package/dist/actions/gitlabGroupEnsureExists.examples.cjs.js.map +1 -0
  10. package/dist/actions/gitlabIssueCreate.cjs.js +136 -0
  11. package/dist/actions/gitlabIssueCreate.cjs.js.map +1 -0
  12. package/dist/actions/gitlabIssueCreate.examples.cjs.js +235 -0
  13. package/dist/actions/gitlabIssueCreate.examples.cjs.js.map +1 -0
  14. package/dist/actions/gitlabIssueEdit.cjs.js +163 -0
  15. package/dist/actions/gitlabIssueEdit.cjs.js.map +1 -0
  16. package/dist/actions/gitlabIssueEdit.examples.cjs.js +250 -0
  17. package/dist/actions/gitlabIssueEdit.examples.cjs.js.map +1 -0
  18. package/dist/actions/gitlabMergeRequest.cjs.js +231 -0
  19. package/dist/actions/gitlabMergeRequest.cjs.js.map +1 -0
  20. package/dist/actions/gitlabMergeRequest.examples.cjs.js +134 -0
  21. package/dist/actions/gitlabMergeRequest.examples.cjs.js.map +1 -0
  22. package/dist/actions/gitlabPipelineTrigger.cjs.js +89 -0
  23. package/dist/actions/gitlabPipelineTrigger.cjs.js.map +1 -0
  24. package/dist/actions/gitlabPipelineTrigger.examples.cjs.js +94 -0
  25. package/dist/actions/gitlabPipelineTrigger.examples.cjs.js.map +1 -0
  26. package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js +85 -0
  27. package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js.map +1 -0
  28. package/dist/actions/gitlabProjectAccessTokenCreate.examples.cjs.js +250 -0
  29. package/dist/actions/gitlabProjectAccessTokenCreate.examples.cjs.js.map +1 -0
  30. package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js +58 -0
  31. package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js.map +1 -0
  32. package/dist/actions/gitlabProjectDeployTokenCreate.examples.cjs.js +100 -0
  33. package/dist/actions/gitlabProjectDeployTokenCreate.examples.cjs.js.map +1 -0
  34. package/dist/actions/gitlabProjectVariableCreate.cjs.js +61 -0
  35. package/dist/actions/gitlabProjectVariableCreate.cjs.js.map +1 -0
  36. package/dist/actions/gitlabProjectVariableCreate.examples.cjs.js +151 -0
  37. package/dist/actions/gitlabProjectVariableCreate.examples.cjs.js.map +1 -0
  38. package/dist/actions/gitlabRepoPush.cjs.js +154 -0
  39. package/dist/actions/gitlabRepoPush.cjs.js.map +1 -0
  40. package/dist/actions/gitlabRepoPush.examples.cjs.js +67 -0
  41. package/dist/actions/gitlabRepoPush.examples.cjs.js.map +1 -0
  42. package/dist/actions/helpers.cjs.js +28 -0
  43. package/dist/actions/helpers.cjs.js.map +1 -0
  44. package/dist/commonGitlabConfig.cjs.js +32 -0
  45. package/dist/commonGitlabConfig.cjs.js.map +1 -0
  46. package/dist/index.cjs.js +28 -2929
  47. package/dist/index.cjs.js.map +1 -1
  48. package/dist/module.cjs.js +47 -0
  49. package/dist/module.cjs.js.map +1 -0
  50. package/dist/util.cjs.js +129 -0
  51. package/dist/util.cjs.js.map +1 -0
  52. package/package.json +10 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
+ ## 0.6.0-next.2
4
+
5
+ ### Minor Changes
6
+
7
+ - 73f2ccf: declare correct type (number) for publish:gitlab output.projectId
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/integration@1.15.1-next.1
13
+ - @backstage/plugin-scaffolder-node@0.5.0-next.2
14
+ - @backstage/backend-plugin-api@1.0.1-next.1
15
+ - @backstage/config@1.2.0
16
+ - @backstage/errors@1.2.4
17
+
18
+ ## 0.5.1-next.1
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+ - @backstage/integration@1.15.1-next.0
24
+ - @backstage/backend-plugin-api@1.0.1-next.0
25
+ - @backstage/config@1.2.0
26
+ - @backstage/errors@1.2.4
27
+ - @backstage/plugin-scaffolder-node@0.5.0-next.1
28
+
3
29
  ## 0.5.1-next.0
4
30
 
5
31
  ### Patch Changes
@@ -0,0 +1,374 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@backstage/errors');
4
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
+ var node = require('@gitbeaker/node');
6
+ var gitlab_examples = require('./gitlab.examples.cjs.js');
7
+
8
+ function createPublishGitlabAction(options) {
9
+ const { integrations, config } = options;
10
+ return pluginScaffolderNode.createTemplateAction({
11
+ id: "publish:gitlab",
12
+ description: "Initializes a git repository of the content in the workspace, and publishes it to GitLab.",
13
+ examples: gitlab_examples.examples,
14
+ schema: {
15
+ input: {
16
+ type: "object",
17
+ required: ["repoUrl"],
18
+ properties: {
19
+ repoUrl: {
20
+ title: "Repository Location",
21
+ type: "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
+ repoVisibility: {
25
+ title: "Repository Visibility",
26
+ description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,
27
+ type: "string",
28
+ enum: ["private", "public", "internal"]
29
+ },
30
+ defaultBranch: {
31
+ title: "Default Branch",
32
+ type: "string",
33
+ description: `Sets the default branch on the repository. The default value is 'master'`
34
+ },
35
+ gitCommitMessage: {
36
+ title: "Git Commit Message",
37
+ type: "string",
38
+ description: `Sets the commit message on the repository. The default value is 'initial commit'`
39
+ },
40
+ gitAuthorName: {
41
+ title: "Default Author Name",
42
+ type: "string",
43
+ description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
44
+ },
45
+ gitAuthorEmail: {
46
+ title: "Default Author Email",
47
+ type: "string",
48
+ description: `Sets the default author email for the commit.`
49
+ },
50
+ sourcePath: {
51
+ title: "Source Path",
52
+ description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
53
+ type: "string"
54
+ },
55
+ token: {
56
+ title: "Authentication Token",
57
+ type: "string",
58
+ description: "The token to use for authorization to GitLab"
59
+ },
60
+ setUserAsOwner: {
61
+ title: "Set User As Owner",
62
+ type: "boolean",
63
+ description: "Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host"
64
+ },
65
+ topics: {
66
+ title: "Topic labels",
67
+ description: "Topic labels to apply on the repository. (deprecated, use settings.topics instead)",
68
+ type: "array",
69
+ items: {
70
+ type: "string"
71
+ }
72
+ },
73
+ settings: {
74
+ title: "Project settings",
75
+ description: "Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes",
76
+ type: "object",
77
+ properties: {
78
+ path: {
79
+ title: "Project path",
80
+ description: "Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).",
81
+ type: "string"
82
+ },
83
+ auto_devops_enabled: {
84
+ title: "Auto DevOps enabled",
85
+ description: "Enable Auto DevOps for this project",
86
+ type: "boolean"
87
+ },
88
+ ci_config_path: {
89
+ title: "CI config path",
90
+ description: "Custom CI config path for this project",
91
+ type: "string"
92
+ },
93
+ description: {
94
+ title: "Project description",
95
+ description: "Short project description",
96
+ type: "string"
97
+ },
98
+ merge_method: {
99
+ title: "Merge Method to use",
100
+ description: "Merge Methods (merge, rebase_merge, ff)",
101
+ type: "string",
102
+ enum: ["merge", "rebase_merge", "ff"]
103
+ },
104
+ squash_option: {
105
+ title: "Squash option",
106
+ description: "Set squash option for the project (never, always, default_on, default_off)",
107
+ type: "string",
108
+ enum: ["default_off", "default_on", "never", "always"]
109
+ },
110
+ topics: {
111
+ title: "Topic labels",
112
+ description: "Topic labels to apply on the repository",
113
+ type: "array",
114
+ items: {
115
+ type: "string"
116
+ }
117
+ },
118
+ visibility: {
119
+ title: "Project visibility",
120
+ description: "The visibility of the project. Can be private, internal, or public. The default value is private.",
121
+ type: "string",
122
+ enum: ["private", "public", "internal"]
123
+ }
124
+ }
125
+ },
126
+ branches: {
127
+ title: "Project branches settings",
128
+ type: "array",
129
+ items: {
130
+ type: "object",
131
+ required: ["name"],
132
+ properties: {
133
+ name: {
134
+ title: "Branch name",
135
+ type: "string"
136
+ },
137
+ protect: {
138
+ title: "Should branch be protected",
139
+ description: `Will mark branch as protected. The default value is 'false'`,
140
+ type: "boolean"
141
+ },
142
+ create: {
143
+ title: "Should branch be created",
144
+ description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,
145
+ type: "boolean"
146
+ },
147
+ ref: {
148
+ title: "Branch reference",
149
+ description: `Branch reference to create branch from. The default value is 'master'`,
150
+ type: "string"
151
+ }
152
+ }
153
+ }
154
+ },
155
+ projectVariables: {
156
+ title: "Project variables",
157
+ description: "Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable",
158
+ type: "array",
159
+ items: {
160
+ type: "object",
161
+ required: ["key", "value"],
162
+ properties: {
163
+ key: {
164
+ title: "Variable key",
165
+ description: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed",
166
+ type: "string"
167
+ },
168
+ value: {
169
+ title: "Variable value",
170
+ description: "The value of a variable",
171
+ type: "string"
172
+ },
173
+ description: {
174
+ title: "Variable description",
175
+ description: `The description of the variable. The default value is 'null'`,
176
+ type: "string"
177
+ },
178
+ variable_type: {
179
+ title: "Variable type",
180
+ description: `The type of a variable. The default value is 'env_var'`,
181
+ type: "string",
182
+ enum: ["env_var", "file"]
183
+ },
184
+ protected: {
185
+ title: "Variable protection",
186
+ description: `Whether the variable is protected. The default value is 'false'`,
187
+ type: "boolean"
188
+ },
189
+ raw: {
190
+ title: "Variable raw",
191
+ description: `Whether the variable is in raw format. The default value is 'false'`,
192
+ type: "boolean"
193
+ },
194
+ environment_scope: {
195
+ title: "Variable environment scope",
196
+ description: `The environment_scope of the variable. The default value is '*'`,
197
+ type: "string"
198
+ }
199
+ }
200
+ }
201
+ }
202
+ }
203
+ },
204
+ output: {
205
+ type: "object",
206
+ properties: {
207
+ remoteUrl: {
208
+ title: "A URL to the repository with the provider",
209
+ type: "string"
210
+ },
211
+ repoContentsUrl: {
212
+ title: "A URL to the root of the repository",
213
+ type: "string"
214
+ },
215
+ projectId: {
216
+ title: "The ID of the project",
217
+ type: "number"
218
+ },
219
+ commitHash: {
220
+ title: "The git commit hash of the initial commit",
221
+ type: "string"
222
+ }
223
+ }
224
+ }
225
+ },
226
+ async handler(ctx) {
227
+ const {
228
+ repoUrl,
229
+ repoVisibility = "private",
230
+ defaultBranch = "master",
231
+ gitCommitMessage = "initial commit",
232
+ gitAuthorName,
233
+ gitAuthorEmail,
234
+ setUserAsOwner = false,
235
+ topics = [],
236
+ settings = {},
237
+ branches = [],
238
+ projectVariables = []
239
+ } = ctx.input;
240
+ const { owner, repo, host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
241
+ if (!owner) {
242
+ throw new errors.InputError(
243
+ `No owner provided for host: ${host}, and repo ${repo}`
244
+ );
245
+ }
246
+ const integrationConfig = integrations.gitlab.byHost(host);
247
+ if (!integrationConfig) {
248
+ throw new errors.InputError(
249
+ `No matching integration configuration for host ${host}, please check your integrations config`
250
+ );
251
+ }
252
+ if (!integrationConfig.config.token && !ctx.input.token) {
253
+ throw new errors.InputError(`No token available for host ${host}`);
254
+ }
255
+ const token = ctx.input.token || integrationConfig.config.token;
256
+ const tokenType = ctx.input.token ? "oauthToken" : "token";
257
+ const client = new node.Gitlab({
258
+ host: integrationConfig.config.baseUrl,
259
+ [tokenType]: token
260
+ });
261
+ let targetNamespaceId;
262
+ try {
263
+ const namespaceResponse = await client.Namespaces.show(owner);
264
+ targetNamespaceId = namespaceResponse.id;
265
+ } catch (e) {
266
+ if (e.response && e.response.statusCode === 404) {
267
+ throw new errors.InputError(
268
+ `The namespace ${owner} is not found or the user doesn't have permissions to access it`
269
+ );
270
+ }
271
+ throw e;
272
+ }
273
+ const { id: userId } = await client.Users.current();
274
+ if (!targetNamespaceId) {
275
+ targetNamespaceId = userId;
276
+ }
277
+ const { id: projectId, http_url_to_repo } = await client.Projects.create({
278
+ namespace_id: targetNamespaceId,
279
+ name: repo,
280
+ visibility: repoVisibility,
281
+ ...topics.length ? { topics } : {},
282
+ ...Object.keys(settings).length ? { ...settings } : {}
283
+ });
284
+ if (setUserAsOwner && integrationConfig.config.token) {
285
+ const adminClient = new node.Gitlab({
286
+ host: integrationConfig.config.baseUrl,
287
+ token: integrationConfig.config.token
288
+ });
289
+ await adminClient.ProjectMembers.add(projectId, userId, 50);
290
+ }
291
+ const remoteUrl = http_url_to_repo.replace(/\.git$/, "");
292
+ const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;
293
+ const gitAuthorInfo = {
294
+ name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
295
+ email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
296
+ };
297
+ const commitResult = await pluginScaffolderNode.initRepoAndPush({
298
+ dir: pluginScaffolderNode.getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
299
+ remoteUrl: http_url_to_repo,
300
+ defaultBranch,
301
+ auth: {
302
+ username: "oauth2",
303
+ password: token
304
+ },
305
+ logger: ctx.logger,
306
+ commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
307
+ gitAuthorInfo
308
+ });
309
+ if (branches) {
310
+ for (const branch of branches) {
311
+ const {
312
+ name,
313
+ protect = false,
314
+ create = false,
315
+ ref = "master"
316
+ } = branch;
317
+ if (create) {
318
+ try {
319
+ await client.Branches.create(projectId, name, ref);
320
+ } catch (e) {
321
+ throw new errors.InputError(
322
+ `Branch creation failed for ${name}. ${printGitlabError(e)}`
323
+ );
324
+ }
325
+ ctx.logger.info(
326
+ `Branch ${name} created for ${projectId} with ref ${ref}`
327
+ );
328
+ }
329
+ if (protect) {
330
+ try {
331
+ await client.ProtectedBranches.protect(projectId, name);
332
+ } catch (e) {
333
+ throw new errors.InputError(
334
+ `Branch protection failed for ${name}. ${printGitlabError(e)}`
335
+ );
336
+ }
337
+ ctx.logger.info(`Branch ${name} protected for ${projectId}`);
338
+ }
339
+ }
340
+ }
341
+ if (projectVariables) {
342
+ for (const variable of projectVariables) {
343
+ const variableWithDefaults = Object.assign(variable, {
344
+ variable_type: variable.variable_type ?? "env_var",
345
+ protected: variable.protected ?? false,
346
+ masked: variable.masked ?? false,
347
+ raw: variable.raw ?? false,
348
+ environment_scope: variable.environment_scope ?? "*"
349
+ });
350
+ try {
351
+ await client.ProjectVariables.create(
352
+ projectId,
353
+ variableWithDefaults
354
+ );
355
+ } catch (e) {
356
+ throw new errors.InputError(
357
+ `Environment variable creation failed for ${variableWithDefaults.key}. ${printGitlabError(e)}`
358
+ );
359
+ }
360
+ }
361
+ }
362
+ ctx.output("commitHash", commitResult?.commitHash);
363
+ ctx.output("remoteUrl", remoteUrl);
364
+ ctx.output("repoContentsUrl", repoContentsUrl);
365
+ ctx.output("projectId", projectId);
366
+ }
367
+ });
368
+ }
369
+ function printGitlabError(error) {
370
+ return JSON.stringify({ code: error.code, message: error.description });
371
+ }
372
+
373
+ exports.createPublishGitlabAction = createPublishGitlabAction;
374
+ //# sourceMappingURL=gitlab.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitlab.cjs.js","sources":["../../src/actions/gitlab.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 { Gitlab } from '@gitbeaker/node';\nimport {\n initRepoAndPush,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport { examples } from './gitlab.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitLab.\n *\n * @public\n */\nexport function createPublishGitlabAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n defaultBranch?: string;\n /** @deprecated in favour of settings.visibility field */\n repoVisibility?: 'private' | 'internal' | 'public';\n sourcePath?: string;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n setUserAsOwner?: boolean;\n /** @deprecated in favour of settings.topics field */\n topics?: string[];\n settings?: {\n path?: string;\n auto_devops_enabled?: boolean;\n ci_config_path?: string;\n description?: string;\n merge_method?: 'merge' | 'rebase_merge' | 'ff';\n squash_option?: 'default_off' | 'default_on' | 'never' | 'always';\n topics?: string[];\n visibility?: 'private' | 'internal' | 'public';\n };\n branches?: Array<{\n name: string;\n protect?: boolean;\n create?: boolean;\n ref?: string;\n }>;\n projectVariables?: Array<{\n key: string;\n value: string;\n description?: string;\n variable_type?: string;\n protected?: boolean;\n masked?: boolean;\n raw?: boolean;\n environment_scope?: string;\n }>;\n }>({\n id: 'publish:gitlab',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to GitLab.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: '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 repoVisibility: {\n title: 'Repository Visibility',\n description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'master'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',\n type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n setUserAsOwner: {\n title: 'Set User As Owner',\n type: 'boolean',\n description:\n 'Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host',\n },\n topics: {\n title: 'Topic labels',\n description:\n 'Topic labels to apply on the repository. (deprecated, use settings.topics instead)',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n settings: {\n title: 'Project settings',\n description:\n 'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes',\n type: 'object',\n properties: {\n path: {\n title: 'Project path',\n description:\n 'Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).',\n type: 'string',\n },\n auto_devops_enabled: {\n title: 'Auto DevOps enabled',\n description: 'Enable Auto DevOps for this project',\n type: 'boolean',\n },\n ci_config_path: {\n title: 'CI config path',\n description: 'Custom CI config path for this project',\n type: 'string',\n },\n description: {\n title: 'Project description',\n description: 'Short project description',\n type: 'string',\n },\n merge_method: {\n title: 'Merge Method to use',\n description: 'Merge Methods (merge, rebase_merge, ff)',\n type: 'string',\n enum: ['merge', 'rebase_merge', 'ff'],\n },\n squash_option: {\n title: 'Squash option',\n description:\n 'Set squash option for the project (never, always, default_on, default_off)',\n type: 'string',\n enum: ['default_off', 'default_on', 'never', 'always'],\n },\n topics: {\n title: 'Topic labels',\n description: 'Topic labels to apply on the repository',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n visibility: {\n title: 'Project visibility',\n description:\n 'The visibility of the project. Can be private, internal, or public. The default value is private.',\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n },\n },\n branches: {\n title: 'Project branches settings',\n type: 'array',\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: {\n title: 'Branch name',\n type: 'string',\n },\n protect: {\n title: 'Should branch be protected',\n description: `Will mark branch as protected. The default value is 'false'`,\n type: 'boolean',\n },\n create: {\n title: 'Should branch be created',\n description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,\n type: 'boolean',\n },\n ref: {\n title: 'Branch reference',\n description: `Branch reference to create branch from. The default value is 'master'`,\n type: 'string',\n },\n },\n },\n },\n projectVariables: {\n title: 'Project variables',\n description:\n 'Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable',\n type: 'array',\n items: {\n type: 'object',\n required: ['key', 'value'],\n properties: {\n key: {\n title: 'Variable key',\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 type: 'string',\n },\n value: {\n title: 'Variable value',\n description: 'The value of a variable',\n type: 'string',\n },\n description: {\n title: 'Variable description',\n description: `The description of the variable. The default value is 'null'`,\n type: 'string',\n },\n variable_type: {\n title: 'Variable type',\n description: `The type of a variable. The default value is 'env_var'`,\n type: 'string',\n enum: ['env_var', 'file'],\n },\n protected: {\n title: 'Variable protection',\n description: `Whether the variable is protected. The default value is 'false'`,\n type: 'boolean',\n },\n raw: {\n title: 'Variable raw',\n description: `Whether the variable is in raw format. The default value is 'false'`,\n type: 'boolean',\n },\n environment_scope: {\n title: 'Variable environment scope',\n description: `The environment_scope of the variable. The default value is '*'`,\n type: 'string',\n },\n },\n },\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n projectId: {\n title: 'The ID of the project',\n type: 'number',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n repoVisibility = 'private',\n defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n setUserAsOwner = false,\n topics = [],\n settings = {},\n branches = [],\n projectVariables = [],\n } = ctx.input;\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\n\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!integrationConfig.config.token && !ctx.input.token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = ctx.input.token || integrationConfig.config.token!;\n const tokenType = ctx.input.token ? 'oauthToken' : 'token';\n\n const client = new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n\n let targetNamespaceId;\n\n try {\n const namespaceResponse = (await client.Namespaces.show(owner)) as {\n id: number;\n };\n\n targetNamespaceId = namespaceResponse.id;\n } catch (e) {\n if (e.response && e.response.statusCode === 404) {\n throw new InputError(\n `The namespace ${owner} is not found or the user doesn't have permissions to access it`,\n );\n }\n throw e;\n }\n\n const { id: userId } = (await client.Users.current()) as {\n id: number;\n };\n\n if (!targetNamespaceId) {\n targetNamespaceId = userId;\n }\n\n const { id: projectId, http_url_to_repo } = await client.Projects.create({\n namespace_id: targetNamespaceId,\n name: repo,\n visibility: repoVisibility,\n ...(topics.length ? { topics } : {}),\n ...(Object.keys(settings).length ? { ...settings } : {}),\n });\n\n // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab\n // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to\n // create the repository, but not to push the default protected branch (e.g. master).\n // In order to set the user as owner of the newly created repository we need to check that the\n // GitLab integration configuration for the matching host contains a token and use\n // such token to bootstrap a new privileged client.\n if (setUserAsOwner && integrationConfig.config.token) {\n const adminClient = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: integrationConfig.config.token,\n });\n\n await adminClient.ProjectMembers.add(projectId, userId, 50);\n }\n\n const remoteUrl = (http_url_to_repo as string).replace(/\\.git$/, '');\n const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl: http_url_to_repo as string,\n defaultBranch,\n auth: {\n username: 'oauth2',\n password: token,\n },\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n });\n\n if (branches) {\n for (const branch of branches) {\n const {\n name,\n protect = false,\n create = false,\n ref = 'master',\n } = branch;\n\n if (create) {\n try {\n await client.Branches.create(projectId, name, ref);\n } catch (e) {\n throw new InputError(\n `Branch creation failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(\n `Branch ${name} created for ${projectId} with ref ${ref}`,\n );\n }\n\n if (protect) {\n try {\n await client.ProtectedBranches.protect(projectId, name);\n } catch (e) {\n throw new InputError(\n `Branch protection failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(`Branch ${name} protected for ${projectId}`);\n }\n }\n }\n\n if (projectVariables) {\n for (const variable of projectVariables) {\n const variableWithDefaults = Object.assign(variable, {\n variable_type: variable.variable_type ?? 'env_var',\n protected: variable.protected ?? false,\n masked: variable.masked ?? false,\n raw: variable.raw ?? false,\n environment_scope: variable.environment_scope ?? '*',\n });\n\n try {\n await client.ProjectVariables.create(\n projectId,\n variableWithDefaults,\n );\n } catch (e) {\n throw new InputError(\n `Environment variable creation failed for ${\n variableWithDefaults.key\n }. ${printGitlabError(e)}`,\n );\n }\n }\n }\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('projectId', projectId);\n },\n });\n}\n\nfunction printGitlabError(error: any): string {\n return JSON.stringify({ code: error.code, message: error.description });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","Gitlab","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AAkCO,SAAS,0BAA0B,OAGvC,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA,CAAA;AAEjC,EAAA,OAAOA,yCAuCJ,CAAA;AAAA,IACD,EAAI,EAAA,gBAAA;AAAA,IACJ,WACE,EAAA,2FAAA;AAAA,cACFC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QAAA;AAAA,QACN,QAAA,EAAU,CAAC,SAAS,CAAA;AAAA,QACpB,UAAY,EAAA;AAAA,UACV,OAAS,EAAA;AAAA,YACP,KAAO,EAAA,qBAAA;AAAA,YACP,IAAM,EAAA,QAAA;AAAA,YACN,WAAa,EAAA,CAAA,sJAAA,CAAA;AAAA,WACf;AAAA,UACA,cAAgB,EAAA;AAAA,YACd,KAAO,EAAA,uBAAA;AAAA,YACP,WAAa,EAAA,CAAA,oHAAA,CAAA;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AM,IAAM,EAAA,OAAA,EAAS,KAAM,CAAA,WAAA,EAAa,CAAA,CAAA;AACxE;;;;"}
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+
3
+ var yaml = require('yaml');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
6
+
7
+ var yaml__default = /*#__PURE__*/_interopDefaultCompat(yaml);
8
+
9
+ const examples = [
10
+ {
11
+ description: "Initializes a git repository with the content in the workspace, and publishes it to GitLab with the default configuration.",
12
+ example: yaml__default.default.stringify({
13
+ steps: [
14
+ {
15
+ id: "publish",
16
+ action: "publish:gitlab",
17
+ name: "Publish to GitLab",
18
+ input: {
19
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name"
20
+ }
21
+ }
22
+ ]
23
+ })
24
+ },
25
+ {
26
+ description: "Add a description.",
27
+ example: yaml__default.default.stringify({
28
+ steps: [
29
+ {
30
+ id: "publish",
31
+ action: "publish:gitlab",
32
+ name: "Publish to GitLab",
33
+ input: {
34
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
35
+ description: "Initialize a git repository"
36
+ }
37
+ }
38
+ ]
39
+ })
40
+ },
41
+ {
42
+ description: "Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.",
43
+ example: yaml__default.default.stringify({
44
+ steps: [
45
+ {
46
+ id: "publish",
47
+ action: "publish:gitlab",
48
+ name: "Publish to GitLab",
49
+ input: {
50
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
51
+ description: "Initialize a git repository",
52
+ gitCommitMessage: "Started a project."
53
+ }
54
+ }
55
+ ]
56
+ })
57
+ },
58
+ {
59
+ description: "Initializes a GitLab repository with aditional settings.",
60
+ example: yaml__default.default.stringify({
61
+ steps: [
62
+ {
63
+ id: "publish",
64
+ action: "publish:gitlab",
65
+ name: "Publish to GitLab",
66
+ input: {
67
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
68
+ settings: {
69
+ ci_config_path: ".gitlab-ci.yml",
70
+ visibility: "public"
71
+ }
72
+ }
73
+ }
74
+ ]
75
+ })
76
+ },
77
+ {
78
+ description: "Initializes a GitLab repository with fast forward merge and always squash settings.",
79
+ example: yaml__default.default.stringify({
80
+ steps: [
81
+ {
82
+ id: "publish",
83
+ action: "publish:gitlab",
84
+ name: "Publish to GitLab",
85
+ input: {
86
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
87
+ settings: {
88
+ merge_method: "ff",
89
+ squash_option: "always"
90
+ }
91
+ }
92
+ }
93
+ ]
94
+ })
95
+ },
96
+ {
97
+ description: "Initializes a GitLab repository with branch settings.",
98
+ example: yaml__default.default.stringify({
99
+ steps: [
100
+ {
101
+ id: "publish",
102
+ action: "publish:gitlab",
103
+ name: "Publish to GitLab",
104
+ input: {
105
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
106
+ branches: [
107
+ {
108
+ name: "dev",
109
+ create: true,
110
+ protect: true,
111
+ ref: "master"
112
+ },
113
+ {
114
+ name: "master",
115
+ protect: true
116
+ }
117
+ ]
118
+ }
119
+ }
120
+ ]
121
+ })
122
+ },
123
+ {
124
+ description: "Initializes a GitLab repository with environment variables.",
125
+ example: yaml__default.default.stringify({
126
+ steps: [
127
+ {
128
+ id: "publish",
129
+ action: "publish:gitlab",
130
+ name: "Publish to GitLab",
131
+ input: {
132
+ repoUrl: "gitlab.com?repo=project_name&owner=group_name",
133
+ projectVariables: [
134
+ {
135
+ key: "key1",
136
+ value: "value1",
137
+ protected: true,
138
+ masked: false
139
+ },
140
+ {
141
+ key: "key2",
142
+ value: "value2",
143
+ protected: true,
144
+ masked: false
145
+ }
146
+ ]
147
+ }
148
+ }
149
+ ]
150
+ })
151
+ }
152
+ ];
153
+
154
+ exports.examples = examples;
155
+ //# sourceMappingURL=gitlab.examples.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitlab.examples.cjs.js","sources":["../../src/actions/gitlab.examples.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Initializes a git repository with the content in the workspace, and publishes it to GitLab with the default configuration.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n },\n },\n ],\n }),\n },\n {\n description: 'Add a description.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n gitCommitMessage: 'Started a project.',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with aditional settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n ci_config_path: '.gitlab-ci.yml',\n visibility: 'public',\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with fast forward merge and always squash settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n merge_method: 'ff',\n squash_option: 'always',\n },\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with branch settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n branches: [\n {\n name: 'dev',\n create: true,\n protect: true,\n ref: 'master',\n },\n {\n name: 'master',\n protect: true,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with environment variables.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n projectVariables: [\n {\n key: 'key1',\n value: 'value1',\n protected: true,\n masked: false,\n },\n {\n key: 'key2',\n value: 'value2',\n protected: true,\n masked: false,\n },\n ],\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,4HAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,WACX;AAAA,SACF;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,oBAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,I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