@backstage/plugin-scaffolder-backend-module-gitlab 0.5.1-next.1 → 0.6.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 +34 -0
- package/README.md +1 -1
- package/dist/actions/gitlab.cjs.js +374 -0
- package/dist/actions/gitlab.cjs.js.map +1 -0
- package/dist/actions/gitlab.examples.cjs.js +155 -0
- package/dist/actions/gitlab.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabGroupEnsureExists.cjs.js +68 -0
- package/dist/actions/gitlabGroupEnsureExists.cjs.js.map +1 -0
- package/dist/actions/gitlabGroupEnsureExists.examples.cjs.js +78 -0
- package/dist/actions/gitlabGroupEnsureExists.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabIssueCreate.cjs.js +136 -0
- package/dist/actions/gitlabIssueCreate.cjs.js.map +1 -0
- package/dist/actions/gitlabIssueCreate.examples.cjs.js +235 -0
- package/dist/actions/gitlabIssueCreate.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabIssueEdit.cjs.js +163 -0
- package/dist/actions/gitlabIssueEdit.cjs.js.map +1 -0
- package/dist/actions/gitlabIssueEdit.examples.cjs.js +250 -0
- package/dist/actions/gitlabIssueEdit.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabMergeRequest.cjs.js +281 -0
- package/dist/actions/gitlabMergeRequest.cjs.js.map +1 -0
- package/dist/actions/gitlabMergeRequest.examples.cjs.js +134 -0
- package/dist/actions/gitlabMergeRequest.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabPipelineTrigger.cjs.js +89 -0
- package/dist/actions/gitlabPipelineTrigger.cjs.js.map +1 -0
- package/dist/actions/gitlabPipelineTrigger.examples.cjs.js +94 -0
- package/dist/actions/gitlabPipelineTrigger.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js +85 -0
- package/dist/actions/gitlabProjectAccessTokenCreate.cjs.js.map +1 -0
- package/dist/actions/gitlabProjectAccessTokenCreate.examples.cjs.js +250 -0
- package/dist/actions/gitlabProjectAccessTokenCreate.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js +58 -0
- package/dist/actions/gitlabProjectDeployTokenCreate.cjs.js.map +1 -0
- package/dist/actions/gitlabProjectDeployTokenCreate.examples.cjs.js +100 -0
- package/dist/actions/gitlabProjectDeployTokenCreate.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabProjectVariableCreate.cjs.js +61 -0
- package/dist/actions/gitlabProjectVariableCreate.cjs.js.map +1 -0
- package/dist/actions/gitlabProjectVariableCreate.examples.cjs.js +151 -0
- package/dist/actions/gitlabProjectVariableCreate.examples.cjs.js.map +1 -0
- package/dist/actions/gitlabRepoPush.cjs.js +154 -0
- package/dist/actions/gitlabRepoPush.cjs.js.map +1 -0
- package/dist/actions/gitlabRepoPush.examples.cjs.js +67 -0
- package/dist/actions/gitlabRepoPush.examples.cjs.js.map +1 -0
- package/dist/actions/helpers.cjs.js +28 -0
- package/dist/actions/helpers.cjs.js.map +1 -0
- package/dist/commonGitlabConfig.cjs.js +32 -0
- package/dist/commonGitlabConfig.cjs.js.map +1 -0
- package/dist/index.cjs.js +28 -2929
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/module.cjs.js +47 -0
- package/dist/module.cjs.js.map +1 -0
- package/dist/util.cjs.js +129 -0
- package/dist/util.cjs.js.map +1 -0
- package/package.json +11 -10
package/dist/index.cjs.js
CHANGED
|
@@ -2,2933 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
description: "Add a description.",
|
|
40
|
-
example: yaml__default.default.stringify({
|
|
41
|
-
steps: [
|
|
42
|
-
{
|
|
43
|
-
id: "publish",
|
|
44
|
-
action: "publish:gitlab",
|
|
45
|
-
name: "Publish to GitLab",
|
|
46
|
-
input: {
|
|
47
|
-
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
48
|
-
description: "Initialize a git repository"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
})
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
description: "Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.",
|
|
56
|
-
example: yaml__default.default.stringify({
|
|
57
|
-
steps: [
|
|
58
|
-
{
|
|
59
|
-
id: "publish",
|
|
60
|
-
action: "publish:gitlab",
|
|
61
|
-
name: "Publish to GitLab",
|
|
62
|
-
input: {
|
|
63
|
-
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
64
|
-
description: "Initialize a git repository",
|
|
65
|
-
gitCommitMessage: "Started a project."
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
})
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
description: "Initializes a GitLab repository with aditional settings.",
|
|
73
|
-
example: yaml__default.default.stringify({
|
|
74
|
-
steps: [
|
|
75
|
-
{
|
|
76
|
-
id: "publish",
|
|
77
|
-
action: "publish:gitlab",
|
|
78
|
-
name: "Publish to GitLab",
|
|
79
|
-
input: {
|
|
80
|
-
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
81
|
-
settings: {
|
|
82
|
-
ci_config_path: ".gitlab-ci.yml",
|
|
83
|
-
visibility: "public"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
})
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
description: "Initializes a GitLab repository with fast forward merge and always squash settings.",
|
|
92
|
-
example: yaml__default.default.stringify({
|
|
93
|
-
steps: [
|
|
94
|
-
{
|
|
95
|
-
id: "publish",
|
|
96
|
-
action: "publish:gitlab",
|
|
97
|
-
name: "Publish to GitLab",
|
|
98
|
-
input: {
|
|
99
|
-
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
100
|
-
settings: {
|
|
101
|
-
merge_method: "ff",
|
|
102
|
-
squash_option: "always"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
})
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
description: "Initializes a GitLab repository with branch settings.",
|
|
111
|
-
example: yaml__default.default.stringify({
|
|
112
|
-
steps: [
|
|
113
|
-
{
|
|
114
|
-
id: "publish",
|
|
115
|
-
action: "publish:gitlab",
|
|
116
|
-
name: "Publish to GitLab",
|
|
117
|
-
input: {
|
|
118
|
-
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
119
|
-
branches: [
|
|
120
|
-
{
|
|
121
|
-
name: "dev",
|
|
122
|
-
create: true,
|
|
123
|
-
protect: true,
|
|
124
|
-
ref: "master"
|
|
125
|
-
},
|
|
126
|
-
{
|
|
127
|
-
name: "master",
|
|
128
|
-
protect: true
|
|
129
|
-
}
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
]
|
|
134
|
-
})
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
description: "Initializes a GitLab repository with environment variables.",
|
|
138
|
-
example: yaml__default.default.stringify({
|
|
139
|
-
steps: [
|
|
140
|
-
{
|
|
141
|
-
id: "publish",
|
|
142
|
-
action: "publish:gitlab",
|
|
143
|
-
name: "Publish to GitLab",
|
|
144
|
-
input: {
|
|
145
|
-
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
146
|
-
projectVariables: [
|
|
147
|
-
{
|
|
148
|
-
key: "key1",
|
|
149
|
-
value: "value1",
|
|
150
|
-
protected: true,
|
|
151
|
-
masked: false
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
key: "key2",
|
|
155
|
-
value: "value2",
|
|
156
|
-
protected: true,
|
|
157
|
-
masked: false
|
|
158
|
-
}
|
|
159
|
-
]
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
]
|
|
163
|
-
})
|
|
164
|
-
}
|
|
165
|
-
];
|
|
166
|
-
|
|
167
|
-
function createPublishGitlabAction(options) {
|
|
168
|
-
const { integrations, config } = options;
|
|
169
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
170
|
-
id: "publish:gitlab",
|
|
171
|
-
description: "Initializes a git repository of the content in the workspace, and publishes it to GitLab.",
|
|
172
|
-
examples: examples$9,
|
|
173
|
-
schema: {
|
|
174
|
-
input: {
|
|
175
|
-
type: "object",
|
|
176
|
-
required: ["repoUrl"],
|
|
177
|
-
properties: {
|
|
178
|
-
repoUrl: {
|
|
179
|
-
title: "Repository Location",
|
|
180
|
-
type: "string",
|
|
181
|
-
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`
|
|
182
|
-
},
|
|
183
|
-
repoVisibility: {
|
|
184
|
-
title: "Repository Visibility",
|
|
185
|
-
description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,
|
|
186
|
-
type: "string",
|
|
187
|
-
enum: ["private", "public", "internal"]
|
|
188
|
-
},
|
|
189
|
-
defaultBranch: {
|
|
190
|
-
title: "Default Branch",
|
|
191
|
-
type: "string",
|
|
192
|
-
description: `Sets the default branch on the repository. The default value is 'master'`
|
|
193
|
-
},
|
|
194
|
-
gitCommitMessage: {
|
|
195
|
-
title: "Git Commit Message",
|
|
196
|
-
type: "string",
|
|
197
|
-
description: `Sets the commit message on the repository. The default value is 'initial commit'`
|
|
198
|
-
},
|
|
199
|
-
gitAuthorName: {
|
|
200
|
-
title: "Default Author Name",
|
|
201
|
-
type: "string",
|
|
202
|
-
description: `Sets the default author name for the commit. The default value is 'Scaffolder'`
|
|
203
|
-
},
|
|
204
|
-
gitAuthorEmail: {
|
|
205
|
-
title: "Default Author Email",
|
|
206
|
-
type: "string",
|
|
207
|
-
description: `Sets the default author email for the commit.`
|
|
208
|
-
},
|
|
209
|
-
sourcePath: {
|
|
210
|
-
title: "Source Path",
|
|
211
|
-
description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
|
|
212
|
-
type: "string"
|
|
213
|
-
},
|
|
214
|
-
token: {
|
|
215
|
-
title: "Authentication Token",
|
|
216
|
-
type: "string",
|
|
217
|
-
description: "The token to use for authorization to GitLab"
|
|
218
|
-
},
|
|
219
|
-
setUserAsOwner: {
|
|
220
|
-
title: "Set User As Owner",
|
|
221
|
-
type: "boolean",
|
|
222
|
-
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"
|
|
223
|
-
},
|
|
224
|
-
topics: {
|
|
225
|
-
title: "Topic labels",
|
|
226
|
-
description: "Topic labels to apply on the repository. (deprecated, use settings.topics instead)",
|
|
227
|
-
type: "array",
|
|
228
|
-
items: {
|
|
229
|
-
type: "string"
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
settings: {
|
|
233
|
-
title: "Project settings",
|
|
234
|
-
description: "Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes",
|
|
235
|
-
type: "object",
|
|
236
|
-
properties: {
|
|
237
|
-
path: {
|
|
238
|
-
title: "Project path",
|
|
239
|
-
description: "Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).",
|
|
240
|
-
type: "string"
|
|
241
|
-
},
|
|
242
|
-
auto_devops_enabled: {
|
|
243
|
-
title: "Auto DevOps enabled",
|
|
244
|
-
description: "Enable Auto DevOps for this project",
|
|
245
|
-
type: "boolean"
|
|
246
|
-
},
|
|
247
|
-
ci_config_path: {
|
|
248
|
-
title: "CI config path",
|
|
249
|
-
description: "Custom CI config path for this project",
|
|
250
|
-
type: "string"
|
|
251
|
-
},
|
|
252
|
-
description: {
|
|
253
|
-
title: "Project description",
|
|
254
|
-
description: "Short project description",
|
|
255
|
-
type: "string"
|
|
256
|
-
},
|
|
257
|
-
merge_method: {
|
|
258
|
-
title: "Merge Method to use",
|
|
259
|
-
description: "Merge Methods (merge, rebase_merge, ff)",
|
|
260
|
-
type: "string",
|
|
261
|
-
enum: ["merge", "rebase_merge", "ff"]
|
|
262
|
-
},
|
|
263
|
-
squash_option: {
|
|
264
|
-
title: "Squash option",
|
|
265
|
-
description: "Set squash option for the project (never, always, default_on, default_off)",
|
|
266
|
-
type: "string",
|
|
267
|
-
enum: ["default_off", "default_on", "never", "always"]
|
|
268
|
-
},
|
|
269
|
-
topics: {
|
|
270
|
-
title: "Topic labels",
|
|
271
|
-
description: "Topic labels to apply on the repository",
|
|
272
|
-
type: "array",
|
|
273
|
-
items: {
|
|
274
|
-
type: "string"
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
visibility: {
|
|
278
|
-
title: "Project visibility",
|
|
279
|
-
description: "The visibility of the project. Can be private, internal, or public. The default value is private.",
|
|
280
|
-
type: "string",
|
|
281
|
-
enum: ["private", "public", "internal"]
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
branches: {
|
|
286
|
-
title: "Project branches settings",
|
|
287
|
-
type: "array",
|
|
288
|
-
items: {
|
|
289
|
-
type: "object",
|
|
290
|
-
required: ["name"],
|
|
291
|
-
properties: {
|
|
292
|
-
name: {
|
|
293
|
-
title: "Branch name",
|
|
294
|
-
type: "string"
|
|
295
|
-
},
|
|
296
|
-
protect: {
|
|
297
|
-
title: "Should branch be protected",
|
|
298
|
-
description: `Will mark branch as protected. The default value is 'false'`,
|
|
299
|
-
type: "boolean"
|
|
300
|
-
},
|
|
301
|
-
create: {
|
|
302
|
-
title: "Should branch be created",
|
|
303
|
-
description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,
|
|
304
|
-
type: "boolean"
|
|
305
|
-
},
|
|
306
|
-
ref: {
|
|
307
|
-
title: "Branch reference",
|
|
308
|
-
description: `Branch reference to create branch from. The default value is 'master'`,
|
|
309
|
-
type: "string"
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
projectVariables: {
|
|
315
|
-
title: "Project variables",
|
|
316
|
-
description: "Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable",
|
|
317
|
-
type: "array",
|
|
318
|
-
items: {
|
|
319
|
-
type: "object",
|
|
320
|
-
required: ["key", "value"],
|
|
321
|
-
properties: {
|
|
322
|
-
key: {
|
|
323
|
-
title: "Variable key",
|
|
324
|
-
description: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed",
|
|
325
|
-
type: "string"
|
|
326
|
-
},
|
|
327
|
-
value: {
|
|
328
|
-
title: "Variable value",
|
|
329
|
-
description: "The value of a variable",
|
|
330
|
-
type: "string"
|
|
331
|
-
},
|
|
332
|
-
description: {
|
|
333
|
-
title: "Variable description",
|
|
334
|
-
description: `The description of the variable. The default value is 'null'`,
|
|
335
|
-
type: "string"
|
|
336
|
-
},
|
|
337
|
-
variable_type: {
|
|
338
|
-
title: "Variable type",
|
|
339
|
-
description: `The type of a variable. The default value is 'env_var'`,
|
|
340
|
-
type: "string",
|
|
341
|
-
enum: ["env_var", "file"]
|
|
342
|
-
},
|
|
343
|
-
protected: {
|
|
344
|
-
title: "Variable protection",
|
|
345
|
-
description: `Whether the variable is protected. The default value is 'false'`,
|
|
346
|
-
type: "boolean"
|
|
347
|
-
},
|
|
348
|
-
raw: {
|
|
349
|
-
title: "Variable raw",
|
|
350
|
-
description: `Whether the variable is in raw format. The default value is 'false'`,
|
|
351
|
-
type: "boolean"
|
|
352
|
-
},
|
|
353
|
-
environment_scope: {
|
|
354
|
-
title: "Variable environment scope",
|
|
355
|
-
description: `The environment_scope of the variable. The default value is '*'`,
|
|
356
|
-
type: "string"
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
},
|
|
363
|
-
output: {
|
|
364
|
-
type: "object",
|
|
365
|
-
properties: {
|
|
366
|
-
remoteUrl: {
|
|
367
|
-
title: "A URL to the repository with the provider",
|
|
368
|
-
type: "string"
|
|
369
|
-
},
|
|
370
|
-
repoContentsUrl: {
|
|
371
|
-
title: "A URL to the root of the repository",
|
|
372
|
-
type: "string"
|
|
373
|
-
},
|
|
374
|
-
projectId: {
|
|
375
|
-
title: "The ID of the project",
|
|
376
|
-
type: "string"
|
|
377
|
-
},
|
|
378
|
-
commitHash: {
|
|
379
|
-
title: "The git commit hash of the initial commit",
|
|
380
|
-
type: "string"
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
async handler(ctx) {
|
|
386
|
-
const {
|
|
387
|
-
repoUrl,
|
|
388
|
-
repoVisibility = "private",
|
|
389
|
-
defaultBranch = "master",
|
|
390
|
-
gitCommitMessage = "initial commit",
|
|
391
|
-
gitAuthorName,
|
|
392
|
-
gitAuthorEmail,
|
|
393
|
-
setUserAsOwner = false,
|
|
394
|
-
topics = [],
|
|
395
|
-
settings = {},
|
|
396
|
-
branches = [],
|
|
397
|
-
projectVariables = []
|
|
398
|
-
} = ctx.input;
|
|
399
|
-
const { owner, repo, host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
400
|
-
if (!owner) {
|
|
401
|
-
throw new errors.InputError(
|
|
402
|
-
`No owner provided for host: ${host}, and repo ${repo}`
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
const integrationConfig = integrations.gitlab.byHost(host);
|
|
406
|
-
if (!integrationConfig) {
|
|
407
|
-
throw new errors.InputError(
|
|
408
|
-
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
if (!integrationConfig.config.token && !ctx.input.token) {
|
|
412
|
-
throw new errors.InputError(`No token available for host ${host}`);
|
|
413
|
-
}
|
|
414
|
-
const token = ctx.input.token || integrationConfig.config.token;
|
|
415
|
-
const tokenType = ctx.input.token ? "oauthToken" : "token";
|
|
416
|
-
const client = new node.Gitlab({
|
|
417
|
-
host: integrationConfig.config.baseUrl,
|
|
418
|
-
[tokenType]: token
|
|
419
|
-
});
|
|
420
|
-
let targetNamespaceId;
|
|
421
|
-
try {
|
|
422
|
-
const namespaceResponse = await client.Namespaces.show(owner);
|
|
423
|
-
targetNamespaceId = namespaceResponse.id;
|
|
424
|
-
} catch (e) {
|
|
425
|
-
if (e.response && e.response.statusCode === 404) {
|
|
426
|
-
throw new errors.InputError(
|
|
427
|
-
`The namespace ${owner} is not found or the user doesn't have permissions to access it`
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
throw e;
|
|
431
|
-
}
|
|
432
|
-
const { id: userId } = await client.Users.current();
|
|
433
|
-
if (!targetNamespaceId) {
|
|
434
|
-
targetNamespaceId = userId;
|
|
435
|
-
}
|
|
436
|
-
const { id: projectId, http_url_to_repo } = await client.Projects.create({
|
|
437
|
-
namespace_id: targetNamespaceId,
|
|
438
|
-
name: repo,
|
|
439
|
-
visibility: repoVisibility,
|
|
440
|
-
...topics.length ? { topics } : {},
|
|
441
|
-
...Object.keys(settings).length ? { ...settings } : {}
|
|
442
|
-
});
|
|
443
|
-
if (setUserAsOwner && integrationConfig.config.token) {
|
|
444
|
-
const adminClient = new node.Gitlab({
|
|
445
|
-
host: integrationConfig.config.baseUrl,
|
|
446
|
-
token: integrationConfig.config.token
|
|
447
|
-
});
|
|
448
|
-
await adminClient.ProjectMembers.add(projectId, userId, 50);
|
|
449
|
-
}
|
|
450
|
-
const remoteUrl = http_url_to_repo.replace(/\.git$/, "");
|
|
451
|
-
const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;
|
|
452
|
-
const gitAuthorInfo = {
|
|
453
|
-
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
454
|
-
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
455
|
-
};
|
|
456
|
-
const commitResult = await pluginScaffolderNode.initRepoAndPush({
|
|
457
|
-
dir: pluginScaffolderNode.getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),
|
|
458
|
-
remoteUrl: http_url_to_repo,
|
|
459
|
-
defaultBranch,
|
|
460
|
-
auth: {
|
|
461
|
-
username: "oauth2",
|
|
462
|
-
password: token
|
|
463
|
-
},
|
|
464
|
-
logger: ctx.logger,
|
|
465
|
-
commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
|
|
466
|
-
gitAuthorInfo
|
|
467
|
-
});
|
|
468
|
-
if (branches) {
|
|
469
|
-
for (const branch of branches) {
|
|
470
|
-
const {
|
|
471
|
-
name,
|
|
472
|
-
protect = false,
|
|
473
|
-
create = false,
|
|
474
|
-
ref = "master"
|
|
475
|
-
} = branch;
|
|
476
|
-
if (create) {
|
|
477
|
-
try {
|
|
478
|
-
await client.Branches.create(projectId, name, ref);
|
|
479
|
-
} catch (e) {
|
|
480
|
-
throw new errors.InputError(
|
|
481
|
-
`Branch creation failed for ${name}. ${printGitlabError(e)}`
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
ctx.logger.info(
|
|
485
|
-
`Branch ${name} created for ${projectId} with ref ${ref}`
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
if (protect) {
|
|
489
|
-
try {
|
|
490
|
-
await client.ProtectedBranches.protect(projectId, name);
|
|
491
|
-
} catch (e) {
|
|
492
|
-
throw new errors.InputError(
|
|
493
|
-
`Branch protection failed for ${name}. ${printGitlabError(e)}`
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
ctx.logger.info(`Branch ${name} protected for ${projectId}`);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
if (projectVariables) {
|
|
501
|
-
for (const variable of projectVariables) {
|
|
502
|
-
const variableWithDefaults = Object.assign(variable, {
|
|
503
|
-
variable_type: variable.variable_type ?? "env_var",
|
|
504
|
-
protected: variable.protected ?? false,
|
|
505
|
-
masked: variable.masked ?? false,
|
|
506
|
-
raw: variable.raw ?? false,
|
|
507
|
-
environment_scope: variable.environment_scope ?? "*"
|
|
508
|
-
});
|
|
509
|
-
try {
|
|
510
|
-
await client.ProjectVariables.create(
|
|
511
|
-
projectId,
|
|
512
|
-
variableWithDefaults
|
|
513
|
-
);
|
|
514
|
-
} catch (e) {
|
|
515
|
-
throw new errors.InputError(
|
|
516
|
-
`Environment variable creation failed for ${variableWithDefaults.key}. ${printGitlabError(e)}`
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
ctx.output("commitHash", commitResult?.commitHash);
|
|
522
|
-
ctx.output("remoteUrl", remoteUrl);
|
|
523
|
-
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
524
|
-
ctx.output("projectId", projectId);
|
|
525
|
-
}
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
function printGitlabError(error) {
|
|
529
|
-
return JSON.stringify({ code: error.code, message: error.description });
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
const commonGitlabConfig = zod.z.object({
|
|
533
|
-
repoUrl: zod.z.string({ description: "Repository Location" }),
|
|
534
|
-
token: zod.z.string({ description: "The token to use for authorization to GitLab" }).optional()
|
|
535
|
-
});
|
|
536
|
-
const commonGitlabConfigExample = {
|
|
537
|
-
repoUrl: "gitlab.com?owner=namespace-or-owner&repo=project-name",
|
|
538
|
-
token: "${{ secrets.USER_OAUTH_TOKEN }}"
|
|
539
|
-
};
|
|
540
|
-
var IssueType = /* @__PURE__ */ ((IssueType2) => {
|
|
541
|
-
IssueType2["ISSUE"] = "issue";
|
|
542
|
-
IssueType2["INCIDENT"] = "incident";
|
|
543
|
-
IssueType2["TEST"] = "test_case";
|
|
544
|
-
IssueType2["TASK"] = "task";
|
|
545
|
-
return IssueType2;
|
|
546
|
-
})(IssueType || {});
|
|
547
|
-
var IssueStateEvent = /* @__PURE__ */ ((IssueStateEvent2) => {
|
|
548
|
-
IssueStateEvent2["CLOSE"] = "close";
|
|
549
|
-
IssueStateEvent2["REOPEN"] = "reopen";
|
|
550
|
-
return IssueStateEvent2;
|
|
551
|
-
})(IssueStateEvent || {});
|
|
552
|
-
|
|
553
|
-
const parseRepoHost = (repoUrl) => {
|
|
554
|
-
let parsed;
|
|
555
|
-
try {
|
|
556
|
-
parsed = new URL(`https://${repoUrl}`);
|
|
557
|
-
} catch (error) {
|
|
558
|
-
throw new errors.InputError(
|
|
559
|
-
`Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`
|
|
560
|
-
);
|
|
561
|
-
}
|
|
562
|
-
return parsed.host;
|
|
563
|
-
};
|
|
564
|
-
const getToken = (config, integrations) => {
|
|
565
|
-
const host = parseRepoHost(config.repoUrl);
|
|
566
|
-
const integrationConfig = integrations.gitlab.byHost(host);
|
|
567
|
-
if (!integrationConfig) {
|
|
568
|
-
throw new errors.InputError(
|
|
569
|
-
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
570
|
-
);
|
|
571
|
-
}
|
|
572
|
-
const token = config.token || integrationConfig.config.token;
|
|
573
|
-
return { token, integrationConfig };
|
|
574
|
-
};
|
|
575
|
-
const parseRepoUrl = (repoUrl, integrations) => {
|
|
576
|
-
let parsed;
|
|
577
|
-
try {
|
|
578
|
-
parsed = new URL(`https://${repoUrl}`);
|
|
579
|
-
} catch (error) {
|
|
580
|
-
throw new errors.InputError(
|
|
581
|
-
`Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`
|
|
582
|
-
);
|
|
583
|
-
}
|
|
584
|
-
const host = parsed.host;
|
|
585
|
-
const owner = parsed.searchParams.get("owner") ?? void 0;
|
|
586
|
-
const repo = parsed.searchParams.get("repo");
|
|
587
|
-
const type = integrations.byHost(host)?.type;
|
|
588
|
-
if (!type) {
|
|
589
|
-
throw new errors.InputError(
|
|
590
|
-
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
return { host, owner, repo };
|
|
594
|
-
};
|
|
595
|
-
function getClient(props) {
|
|
596
|
-
const { host, token, integrations } = props;
|
|
597
|
-
const integrationConfig = integrations.gitlab.byHost(host);
|
|
598
|
-
if (!integrationConfig) {
|
|
599
|
-
throw new errors.InputError(
|
|
600
|
-
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
const { config } = integrationConfig;
|
|
604
|
-
if (!config.token && !token) {
|
|
605
|
-
throw new errors.InputError(`No token available for host ${host}`);
|
|
606
|
-
}
|
|
607
|
-
const requestToken = token || config.token;
|
|
608
|
-
const tokenType = token ? "oauthToken" : "token";
|
|
609
|
-
const gitlabOptions = {
|
|
610
|
-
host: config.baseUrl
|
|
611
|
-
};
|
|
612
|
-
gitlabOptions[tokenType] = requestToken;
|
|
613
|
-
return new rest.Gitlab(gitlabOptions);
|
|
614
|
-
}
|
|
615
|
-
function convertDate(inputDate, defaultDate) {
|
|
616
|
-
try {
|
|
617
|
-
return inputDate ? new Date(inputDate).toISOString() : new Date(defaultDate).toISOString();
|
|
618
|
-
} catch (error) {
|
|
619
|
-
throw new errors.InputError(`Error converting input date - ${error}`);
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
async function getTopLevelParentGroup(client, groupId) {
|
|
623
|
-
try {
|
|
624
|
-
const topParentGroup = await client.Groups.show(groupId);
|
|
625
|
-
if (topParentGroup.parent_id) {
|
|
626
|
-
return getTopLevelParentGroup(
|
|
627
|
-
client,
|
|
628
|
-
topParentGroup.parent_id
|
|
629
|
-
);
|
|
630
|
-
}
|
|
631
|
-
return topParentGroup;
|
|
632
|
-
} catch (error) {
|
|
633
|
-
throw new errors.InputError(
|
|
634
|
-
`Error finding top-level parent group ID: ${error.message}`
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
async function checkEpicScope(client, projectId, epicId) {
|
|
639
|
-
try {
|
|
640
|
-
const project = await client.Projects.show(projectId);
|
|
641
|
-
if (!project) {
|
|
642
|
-
throw new errors.InputError(
|
|
643
|
-
`Project with id ${projectId} not found. Check your GitLab instance.`
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
const topParentGroup = await getTopLevelParentGroup(
|
|
647
|
-
client,
|
|
648
|
-
project.namespace.id
|
|
649
|
-
);
|
|
650
|
-
if (!topParentGroup) {
|
|
651
|
-
throw new errors.InputError(`Couldn't find a suitable top-level parent group.`);
|
|
652
|
-
}
|
|
653
|
-
const epic = (await client.Epics.all(topParentGroup.id)).find(
|
|
654
|
-
(x) => x.id === epicId
|
|
655
|
-
);
|
|
656
|
-
if (!epic) {
|
|
657
|
-
throw new errors.InputError(
|
|
658
|
-
`Epic with id ${epicId} not found in the top-level parent group ${topParentGroup.name}.`
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
const epicGroup = await client.Groups.show(epic.group_id);
|
|
662
|
-
const projectNamespace = project.path_with_namespace;
|
|
663
|
-
return projectNamespace.startsWith(epicGroup.full_path);
|
|
664
|
-
} catch (error) {
|
|
665
|
-
throw new errors.InputError(`Could not find epic scope: ${error.message}`);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
const examples$8 = [
|
|
670
|
-
{
|
|
671
|
-
description: "Creating a group at the top level",
|
|
672
|
-
example: yaml__default.default.stringify({
|
|
673
|
-
steps: [
|
|
674
|
-
{
|
|
675
|
-
id: "gitlabGroup",
|
|
676
|
-
name: "Group",
|
|
677
|
-
action: "gitlab:group:ensureExists",
|
|
678
|
-
input: {
|
|
679
|
-
repoUrl: "gitlab.com",
|
|
680
|
-
path: ["group1"]
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
]
|
|
684
|
-
})
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
description: "Create a group nested within another group",
|
|
688
|
-
example: yaml__default.default.stringify({
|
|
689
|
-
steps: [
|
|
690
|
-
{
|
|
691
|
-
id: "gitlabGroup",
|
|
692
|
-
name: "Group",
|
|
693
|
-
action: "gitlab:group:ensureExists",
|
|
694
|
-
input: {
|
|
695
|
-
repoUrl: "gitlab.com",
|
|
696
|
-
path: ["group1", "group2"]
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
]
|
|
700
|
-
})
|
|
701
|
-
},
|
|
702
|
-
{
|
|
703
|
-
description: "Create a group nested within multiple other groups",
|
|
704
|
-
example: yaml__default.default.stringify({
|
|
705
|
-
steps: [
|
|
706
|
-
{
|
|
707
|
-
id: "gitlabGroup",
|
|
708
|
-
name: "Group",
|
|
709
|
-
action: "gitlab:group:ensureExists",
|
|
710
|
-
input: {
|
|
711
|
-
repoUrl: "gitlab.com",
|
|
712
|
-
path: ["group1", "group2", "group3"]
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
]
|
|
716
|
-
})
|
|
717
|
-
},
|
|
718
|
-
{
|
|
719
|
-
description: "Create a group in dry run mode",
|
|
720
|
-
example: yaml__default.default.stringify({
|
|
721
|
-
steps: [
|
|
722
|
-
{
|
|
723
|
-
id: "gitlabGroup",
|
|
724
|
-
name: "Group",
|
|
725
|
-
action: "gitlab:group:ensureExists",
|
|
726
|
-
isDryRun: true,
|
|
727
|
-
input: {
|
|
728
|
-
repoUrl: "https://gitlab.com/my-repo",
|
|
729
|
-
path: ["group1", "group2", "group3"]
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
]
|
|
733
|
-
})
|
|
734
|
-
}
|
|
735
|
-
];
|
|
736
|
-
|
|
737
|
-
const createGitlabGroupEnsureExistsAction = (options) => {
|
|
738
|
-
const { integrations } = options;
|
|
739
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
740
|
-
id: "gitlab:group:ensureExists",
|
|
741
|
-
description: "Ensures a Gitlab group exists",
|
|
742
|
-
supportsDryRun: true,
|
|
743
|
-
examples: examples$8,
|
|
744
|
-
schema: {
|
|
745
|
-
input: commonGitlabConfig.merge(
|
|
746
|
-
zod.z.object({
|
|
747
|
-
path: zod.z.array(zod.z.string(), {
|
|
748
|
-
description: "A path of group names that is ensured to exist"
|
|
749
|
-
}).min(1)
|
|
750
|
-
})
|
|
751
|
-
),
|
|
752
|
-
output: zod.z.object({
|
|
753
|
-
groupId: zod.z.number({ description: "The id of the innermost sub-group" }).optional()
|
|
754
|
-
})
|
|
755
|
-
},
|
|
756
|
-
async handler(ctx) {
|
|
757
|
-
if (ctx.isDryRun) {
|
|
758
|
-
ctx.output("groupId", 42);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
const { token, repoUrl, path } = ctx.input;
|
|
762
|
-
const { host } = parseRepoUrl(repoUrl, integrations);
|
|
763
|
-
const api = getClient({ host, integrations, token });
|
|
764
|
-
let currentPath = null;
|
|
765
|
-
let parentId = null;
|
|
766
|
-
for (const pathElement of path) {
|
|
767
|
-
const fullPath = currentPath ? `${currentPath}/${pathElement}` : pathElement;
|
|
768
|
-
const result = await api.Groups.search(
|
|
769
|
-
fullPath
|
|
770
|
-
);
|
|
771
|
-
const subGroup = result.find(
|
|
772
|
-
(searchPathElem) => searchPathElem.full_path === fullPath
|
|
773
|
-
);
|
|
774
|
-
if (!subGroup) {
|
|
775
|
-
ctx.logger.info(`creating missing group ${fullPath}`);
|
|
776
|
-
parentId = (await api.Groups.create(
|
|
777
|
-
pathElement,
|
|
778
|
-
pathElement,
|
|
779
|
-
parentId ? {
|
|
780
|
-
parentId
|
|
781
|
-
} : {}
|
|
782
|
-
))?.id;
|
|
783
|
-
} else {
|
|
784
|
-
parentId = subGroup.id;
|
|
785
|
-
}
|
|
786
|
-
currentPath = fullPath;
|
|
787
|
-
}
|
|
788
|
-
if (parentId !== null) {
|
|
789
|
-
ctx.output("groupId", parentId);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
});
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
const examples$7 = [
|
|
796
|
-
{
|
|
797
|
-
description: "Create a GitLab issue with minimal options",
|
|
798
|
-
example: yaml__default.default.stringify({
|
|
799
|
-
steps: [
|
|
800
|
-
{
|
|
801
|
-
id: "gitlabIssue",
|
|
802
|
-
name: "Issues",
|
|
803
|
-
action: "gitlab:issues:create",
|
|
804
|
-
input: {
|
|
805
|
-
...commonGitlabConfigExample,
|
|
806
|
-
projectId: 12,
|
|
807
|
-
title: "Test Issue",
|
|
808
|
-
description: "This is the description of the issue"
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
]
|
|
812
|
-
})
|
|
813
|
-
},
|
|
814
|
-
{
|
|
815
|
-
description: "Create a GitLab issue with assignees and date options",
|
|
816
|
-
example: yaml__default.default.stringify({
|
|
817
|
-
steps: [
|
|
818
|
-
{
|
|
819
|
-
id: "gitlabIssue",
|
|
820
|
-
name: "Issues",
|
|
821
|
-
action: "gitlab:issues:create",
|
|
822
|
-
input: {
|
|
823
|
-
...commonGitlabConfigExample,
|
|
824
|
-
projectId: 12,
|
|
825
|
-
title: "Test Issue",
|
|
826
|
-
assignees: [18],
|
|
827
|
-
description: "This is the description of the issue",
|
|
828
|
-
createdAt: "2022-09-27T18:00:00.000Z",
|
|
829
|
-
dueDate: "2022-09-28T12:00:00.000Z"
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
]
|
|
833
|
-
})
|
|
834
|
-
},
|
|
835
|
-
{
|
|
836
|
-
description: "Create a GitLab Issue with several options",
|
|
837
|
-
example: yaml__default.default.stringify({
|
|
838
|
-
steps: [
|
|
839
|
-
{
|
|
840
|
-
id: "gitlabIssue",
|
|
841
|
-
name: "Issues",
|
|
842
|
-
action: "gitlab:issues:create",
|
|
843
|
-
input: {
|
|
844
|
-
...commonGitlabConfigExample,
|
|
845
|
-
projectId: 12,
|
|
846
|
-
title: "Test Issue",
|
|
847
|
-
assignees: [18, 15],
|
|
848
|
-
description: "This is the description of the issue",
|
|
849
|
-
confidential: false,
|
|
850
|
-
createdAt: "2022-09-27T18:00:00.000Z",
|
|
851
|
-
dueDate: "2022-09-28T12:00:00.000Z",
|
|
852
|
-
discussionToResolve: "1",
|
|
853
|
-
epicId: 1,
|
|
854
|
-
labels: "phase1:label1,phase2:label2"
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
]
|
|
858
|
-
})
|
|
859
|
-
},
|
|
860
|
-
{
|
|
861
|
-
description: "Create a GitLab issue with token",
|
|
862
|
-
example: yaml__default.default.stringify({
|
|
863
|
-
steps: [
|
|
864
|
-
{
|
|
865
|
-
id: "gitlabIssue",
|
|
866
|
-
name: "Issues",
|
|
867
|
-
action: "gitlab:issues:create",
|
|
868
|
-
input: {
|
|
869
|
-
...commonGitlabConfigExample,
|
|
870
|
-
projectId: 12,
|
|
871
|
-
title: "Test Issue",
|
|
872
|
-
description: "This is the description of the issue",
|
|
873
|
-
token: "sample token"
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
]
|
|
877
|
-
})
|
|
878
|
-
},
|
|
879
|
-
{
|
|
880
|
-
description: "Create a GitLab issue with a specific milestone and weight",
|
|
881
|
-
example: yaml__default.default.stringify({
|
|
882
|
-
steps: [
|
|
883
|
-
{
|
|
884
|
-
id: "gitlabIssue",
|
|
885
|
-
name: "Issues",
|
|
886
|
-
action: "gitlab:issues:create",
|
|
887
|
-
input: {
|
|
888
|
-
...commonGitlabConfigExample,
|
|
889
|
-
projectId: 12,
|
|
890
|
-
title: "Test Issue with Milestone",
|
|
891
|
-
description: "This is the description of the issue",
|
|
892
|
-
milestoneId: 5,
|
|
893
|
-
weight: 3
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
]
|
|
897
|
-
})
|
|
898
|
-
},
|
|
899
|
-
{
|
|
900
|
-
description: "Create a GitLab issue of type INCIDENT",
|
|
901
|
-
example: yaml__default.default.stringify({
|
|
902
|
-
steps: [
|
|
903
|
-
{
|
|
904
|
-
id: "gitlabIssue",
|
|
905
|
-
name: "Issues",
|
|
906
|
-
action: "gitlab:issues:create",
|
|
907
|
-
input: {
|
|
908
|
-
...commonGitlabConfigExample,
|
|
909
|
-
projectId: 12,
|
|
910
|
-
title: "Confidential Test Issue",
|
|
911
|
-
description: "This is the description of the issue",
|
|
912
|
-
issueType: "incident"
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
]
|
|
916
|
-
})
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
description: "Create a GitLab issue of type TEST",
|
|
920
|
-
example: yaml__default.default.stringify({
|
|
921
|
-
steps: [
|
|
922
|
-
{
|
|
923
|
-
id: "gitlabIssue",
|
|
924
|
-
name: "Issues",
|
|
925
|
-
action: "gitlab:issues:create",
|
|
926
|
-
input: {
|
|
927
|
-
...commonGitlabConfigExample,
|
|
928
|
-
projectId: 12,
|
|
929
|
-
title: "Confidential Test Issue",
|
|
930
|
-
description: "This is the description of the issue",
|
|
931
|
-
issueType: "test_case"
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
]
|
|
935
|
-
})
|
|
936
|
-
},
|
|
937
|
-
{
|
|
938
|
-
description: "Create a GitLab issue of type TASK with assignees",
|
|
939
|
-
example: yaml__default.default.stringify({
|
|
940
|
-
steps: [
|
|
941
|
-
{
|
|
942
|
-
id: "gitlabIssue",
|
|
943
|
-
name: "Issues",
|
|
944
|
-
action: "gitlab:issues:create",
|
|
945
|
-
input: {
|
|
946
|
-
...commonGitlabConfigExample,
|
|
947
|
-
projectId: 12,
|
|
948
|
-
title: "Confidential Test Issue",
|
|
949
|
-
description: "This is the description of the issue",
|
|
950
|
-
issueType: "task",
|
|
951
|
-
assignees: [18, 22]
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
]
|
|
955
|
-
})
|
|
956
|
-
},
|
|
957
|
-
{
|
|
958
|
-
description: "Create a GitLab issue of type ISSUE and close it",
|
|
959
|
-
example: yaml__default.default.stringify({
|
|
960
|
-
steps: [
|
|
961
|
-
{
|
|
962
|
-
id: "gitlabIssue",
|
|
963
|
-
name: "Issues",
|
|
964
|
-
action: "gitlab:issues:create",
|
|
965
|
-
input: {
|
|
966
|
-
...commonGitlabConfigExample,
|
|
967
|
-
projectId: 12,
|
|
968
|
-
title: "Confidential Test Issue",
|
|
969
|
-
description: "This is the description of the issue",
|
|
970
|
-
issueType: "issue",
|
|
971
|
-
stateEvent: "close"
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
]
|
|
975
|
-
})
|
|
976
|
-
},
|
|
977
|
-
{
|
|
978
|
-
description: "Create a GitLab issue of type INCIDENT and reopen it",
|
|
979
|
-
example: yaml__default.default.stringify({
|
|
980
|
-
steps: [
|
|
981
|
-
{
|
|
982
|
-
id: "gitlabIssue",
|
|
983
|
-
name: "Issues",
|
|
984
|
-
action: "gitlab:issues:create",
|
|
985
|
-
input: {
|
|
986
|
-
...commonGitlabConfigExample,
|
|
987
|
-
projectId: 12,
|
|
988
|
-
title: "Confidential Test Issue",
|
|
989
|
-
description: "This is the description of the issue",
|
|
990
|
-
issueType: "incident",
|
|
991
|
-
stateEvent: "reopen"
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
]
|
|
995
|
-
})
|
|
996
|
-
},
|
|
997
|
-
{
|
|
998
|
-
description: "Create a GitLab issue to resolve a discussion in a merge request",
|
|
999
|
-
example: yaml__default.default.stringify({
|
|
1000
|
-
steps: [
|
|
1001
|
-
{
|
|
1002
|
-
id: "gitlabIssue",
|
|
1003
|
-
name: "Issues",
|
|
1004
|
-
action: "gitlab:issues:create",
|
|
1005
|
-
input: {
|
|
1006
|
-
...commonGitlabConfigExample,
|
|
1007
|
-
projectId: 12,
|
|
1008
|
-
title: "Test Issue for MR Discussion",
|
|
1009
|
-
description: "This is the description of the issue",
|
|
1010
|
-
mergeRequestToResolveDiscussionsOf: 42,
|
|
1011
|
-
discussionToResolve: "abc123"
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
]
|
|
1015
|
-
})
|
|
1016
|
-
}
|
|
1017
|
-
];
|
|
1018
|
-
|
|
1019
|
-
const issueInputProperties = zod.z.object({
|
|
1020
|
-
projectId: zod.z.number().describe("Project Id"),
|
|
1021
|
-
title: zod.z.string({ description: "Title of the issue" }),
|
|
1022
|
-
assignees: zod.z.array(zod.z.number(), {
|
|
1023
|
-
description: "IDs of the users to assign the issue to."
|
|
1024
|
-
}).optional(),
|
|
1025
|
-
confidential: zod.z.boolean({ description: "Issue Confidentiality" }).optional(),
|
|
1026
|
-
description: zod.z.string().describe("Issue description").max(1048576).optional(),
|
|
1027
|
-
createdAt: zod.z.string().describe("Creation date/time").regex(
|
|
1028
|
-
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
|
|
1029
|
-
"Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
|
|
1030
|
-
).optional(),
|
|
1031
|
-
dueDate: zod.z.string().describe("Due date/time").regex(
|
|
1032
|
-
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
|
|
1033
|
-
"Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
|
|
1034
|
-
).optional(),
|
|
1035
|
-
discussionToResolve: zod.z.string({
|
|
1036
|
-
description: 'Id of a discussion to resolve. Use in combination with "merge_request_to_resolve_discussions_of"'
|
|
1037
|
-
}).optional(),
|
|
1038
|
-
epicId: zod.z.number({ description: "Id of the linked Epic" }).min(0, "Valid values should be equal or greater than zero").optional(),
|
|
1039
|
-
labels: zod.z.string({ description: "Labels to apply" }).optional(),
|
|
1040
|
-
issueType: zod.z.nativeEnum(IssueType, {
|
|
1041
|
-
description: "Type of the issue"
|
|
1042
|
-
}).optional(),
|
|
1043
|
-
mergeRequestToResolveDiscussionsOf: zod.z.number({
|
|
1044
|
-
description: "IID of a merge request in which to resolve all issues"
|
|
1045
|
-
}).optional(),
|
|
1046
|
-
milestoneId: zod.z.number({ description: "Global ID of a milestone to assign the issue" }).optional(),
|
|
1047
|
-
weight: zod.z.number({ description: "The issue weight" }).min(0).refine((value) => {
|
|
1048
|
-
const isValid = value >= 0;
|
|
1049
|
-
if (!isValid) {
|
|
1050
|
-
return {
|
|
1051
|
-
message: "Valid values should be equal or greater than zero"
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
return isValid;
|
|
1055
|
-
}).optional()
|
|
1056
|
-
});
|
|
1057
|
-
const issueOutputProperties = zod.z.object({
|
|
1058
|
-
issueUrl: zod.z.string({ description: "Issue Url" }),
|
|
1059
|
-
issueId: zod.z.number({ description: "Issue Id" }),
|
|
1060
|
-
issueIid: zod.z.number({ description: "Issue Iid" })
|
|
1061
|
-
});
|
|
1062
|
-
const createGitlabIssueAction = (options) => {
|
|
1063
|
-
const { integrations } = options;
|
|
1064
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
1065
|
-
id: "gitlab:issues:create",
|
|
1066
|
-
description: "Creates a Gitlab issue.",
|
|
1067
|
-
examples: examples$7,
|
|
1068
|
-
schema: {
|
|
1069
|
-
input: commonGitlabConfig.merge(issueInputProperties),
|
|
1070
|
-
output: issueOutputProperties
|
|
1071
|
-
},
|
|
1072
|
-
async handler(ctx) {
|
|
1073
|
-
try {
|
|
1074
|
-
const {
|
|
1075
|
-
repoUrl,
|
|
1076
|
-
projectId,
|
|
1077
|
-
title,
|
|
1078
|
-
description = "",
|
|
1079
|
-
confidential = false,
|
|
1080
|
-
assignees = [],
|
|
1081
|
-
createdAt = "",
|
|
1082
|
-
dueDate,
|
|
1083
|
-
discussionToResolve = "",
|
|
1084
|
-
epicId,
|
|
1085
|
-
labels = "",
|
|
1086
|
-
issueType,
|
|
1087
|
-
mergeRequestToResolveDiscussionsOf,
|
|
1088
|
-
milestoneId,
|
|
1089
|
-
weight,
|
|
1090
|
-
token
|
|
1091
|
-
} = commonGitlabConfig.merge(issueInputProperties).parse(ctx.input);
|
|
1092
|
-
const { host } = parseRepoUrl(repoUrl, integrations);
|
|
1093
|
-
const api = getClient({ host, integrations, token });
|
|
1094
|
-
let isEpicScoped = false;
|
|
1095
|
-
if (epicId) {
|
|
1096
|
-
isEpicScoped = await checkEpicScope(api, projectId, epicId);
|
|
1097
|
-
if (isEpicScoped) {
|
|
1098
|
-
ctx.logger.info("Epic is within Project Scope");
|
|
1099
|
-
} else {
|
|
1100
|
-
ctx.logger.warn(
|
|
1101
|
-
"Chosen epic is not within the Project Scope. The issue will be created without an associated epic."
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
const mappedCreatedAt = convertDate(
|
|
1106
|
-
String(createdAt),
|
|
1107
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
1108
|
-
);
|
|
1109
|
-
const mappedDueDate = dueDate ? convertDate(String(dueDate), (/* @__PURE__ */ new Date()).toISOString()) : void 0;
|
|
1110
|
-
const issueOptions = {
|
|
1111
|
-
description,
|
|
1112
|
-
assigneeIds: assignees,
|
|
1113
|
-
confidential,
|
|
1114
|
-
epicId: isEpicScoped ? epicId : void 0,
|
|
1115
|
-
labels,
|
|
1116
|
-
createdAt: mappedCreatedAt,
|
|
1117
|
-
dueDate: mappedDueDate,
|
|
1118
|
-
discussionToResolve,
|
|
1119
|
-
issueType,
|
|
1120
|
-
mergeRequestToResolveDiscussionsOf,
|
|
1121
|
-
milestoneId,
|
|
1122
|
-
weight
|
|
1123
|
-
};
|
|
1124
|
-
const response = await api.Issues.create(
|
|
1125
|
-
projectId,
|
|
1126
|
-
title,
|
|
1127
|
-
issueOptions
|
|
1128
|
-
);
|
|
1129
|
-
ctx.output("issueId", response.id);
|
|
1130
|
-
ctx.output("issueUrl", response.web_url);
|
|
1131
|
-
ctx.output("issueIid", response.iid);
|
|
1132
|
-
} catch (error) {
|
|
1133
|
-
if (error instanceof zod.z.ZodError) {
|
|
1134
|
-
throw new errors.InputError(`Validation error: ${error.message}`, {
|
|
1135
|
-
validationErrors: error.errors
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
throw new errors.InputError(`Failed to create GitLab issue: ${error.message}`);
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
};
|
|
1143
|
-
|
|
1144
|
-
const examples$6 = [
|
|
1145
|
-
{
|
|
1146
|
-
description: "Edit a GitLab issue with minimal options",
|
|
1147
|
-
example: yaml__default.default.stringify({
|
|
1148
|
-
steps: [
|
|
1149
|
-
{
|
|
1150
|
-
id: "gitlabIssue",
|
|
1151
|
-
name: "EditIssues",
|
|
1152
|
-
action: "gitlab:issue:edit",
|
|
1153
|
-
input: {
|
|
1154
|
-
...commonGitlabConfigExample,
|
|
1155
|
-
projectId: 12,
|
|
1156
|
-
title: "Modified Test Issue",
|
|
1157
|
-
description: "This is a modified description of the issue"
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
]
|
|
1161
|
-
})
|
|
1162
|
-
},
|
|
1163
|
-
{
|
|
1164
|
-
description: "Edit a GitLab issue with assignees and date options",
|
|
1165
|
-
example: yaml__default.default.stringify({
|
|
1166
|
-
steps: [
|
|
1167
|
-
{
|
|
1168
|
-
id: "gitlabIssue",
|
|
1169
|
-
name: "EditIssues",
|
|
1170
|
-
action: "gitlab:issue:edit",
|
|
1171
|
-
input: {
|
|
1172
|
-
...commonGitlabConfigExample,
|
|
1173
|
-
projectId: 12,
|
|
1174
|
-
title: "Test Issue",
|
|
1175
|
-
assignees: [18],
|
|
1176
|
-
description: "This is the edited description of the issue",
|
|
1177
|
-
updatedAt: "2024-05-10T18:00:00.000Z",
|
|
1178
|
-
dueDate: "2024-09-28"
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
]
|
|
1182
|
-
})
|
|
1183
|
-
},
|
|
1184
|
-
{
|
|
1185
|
-
description: "Create a GitLab Issue with several options",
|
|
1186
|
-
example: yaml__default.default.stringify({
|
|
1187
|
-
steps: [
|
|
1188
|
-
{
|
|
1189
|
-
id: "gitlabIssue",
|
|
1190
|
-
name: "EditIssues",
|
|
1191
|
-
action: "gitlab:issue:edit",
|
|
1192
|
-
input: {
|
|
1193
|
-
...commonGitlabConfigExample,
|
|
1194
|
-
projectId: 12,
|
|
1195
|
-
title: "Test Edit Issue",
|
|
1196
|
-
assignees: [18, 15],
|
|
1197
|
-
description: "This is the description of the issue",
|
|
1198
|
-
confidential: false,
|
|
1199
|
-
updatedAt: "2024-05-10T18:00:00.000Z",
|
|
1200
|
-
dueDate: "2024-09-28",
|
|
1201
|
-
discussionLocked: true,
|
|
1202
|
-
epicId: 1,
|
|
1203
|
-
labels: "phase1:label1,phase2:label2"
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
]
|
|
1207
|
-
})
|
|
1208
|
-
},
|
|
1209
|
-
{
|
|
1210
|
-
description: "Edit a gitlab issue to change its state to close",
|
|
1211
|
-
example: yaml__default.default.stringify({
|
|
1212
|
-
steps: [
|
|
1213
|
-
{
|
|
1214
|
-
id: "gitlabIssue",
|
|
1215
|
-
name: "EditIssues",
|
|
1216
|
-
action: "gitlab:issue:edit",
|
|
1217
|
-
input: {
|
|
1218
|
-
...commonGitlabConfigExample,
|
|
1219
|
-
projectId: 12,
|
|
1220
|
-
stateEvent: "close"
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
]
|
|
1224
|
-
})
|
|
1225
|
-
},
|
|
1226
|
-
{
|
|
1227
|
-
description: "Edit a gitlab issue to change its state to reopened",
|
|
1228
|
-
example: yaml__default.default.stringify({
|
|
1229
|
-
steps: [
|
|
1230
|
-
{
|
|
1231
|
-
id: "gitlabIssue",
|
|
1232
|
-
name: "EditIssues",
|
|
1233
|
-
action: "gitlab:issue:edit",
|
|
1234
|
-
input: {
|
|
1235
|
-
...commonGitlabConfigExample,
|
|
1236
|
-
projectId: 12,
|
|
1237
|
-
stateEvent: "reopen"
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
]
|
|
1241
|
-
})
|
|
1242
|
-
},
|
|
1243
|
-
{
|
|
1244
|
-
description: "Edit a gitlab issue to assign it to multiple users and set milestone",
|
|
1245
|
-
example: yaml__default.default.stringify({
|
|
1246
|
-
steps: [
|
|
1247
|
-
{
|
|
1248
|
-
id: "gitlabIssue",
|
|
1249
|
-
name: "EditIssues",
|
|
1250
|
-
action: "gitlab:issue:edit",
|
|
1251
|
-
input: {
|
|
1252
|
-
...commonGitlabConfigExample,
|
|
1253
|
-
projectId: 12,
|
|
1254
|
-
title: "Test issue with milestone",
|
|
1255
|
-
assignees: [18, 20],
|
|
1256
|
-
description: "This issue has milestone set",
|
|
1257
|
-
milestoneId: 5
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
]
|
|
1261
|
-
})
|
|
1262
|
-
},
|
|
1263
|
-
{
|
|
1264
|
-
description: "Edit a gitlab issue to add weight and update labels",
|
|
1265
|
-
example: yaml__default.default.stringify({
|
|
1266
|
-
steps: [
|
|
1267
|
-
{
|
|
1268
|
-
id: "gitlabIssue",
|
|
1269
|
-
name: "EditIssues",
|
|
1270
|
-
action: "gitlab:issue:edit",
|
|
1271
|
-
input: {
|
|
1272
|
-
...commonGitlabConfigExample,
|
|
1273
|
-
projectId: 12,
|
|
1274
|
-
title: "Issue with weight and labels",
|
|
1275
|
-
description: "This issue has weight and new labels",
|
|
1276
|
-
weight: 3,
|
|
1277
|
-
labels: "bug,urgent"
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
]
|
|
1281
|
-
})
|
|
1282
|
-
},
|
|
1283
|
-
{
|
|
1284
|
-
description: "Edit a gitlab issue to make it confidential",
|
|
1285
|
-
example: yaml__default.default.stringify({
|
|
1286
|
-
steps: [
|
|
1287
|
-
{
|
|
1288
|
-
id: "gitlabIssue",
|
|
1289
|
-
name: "EditIssues",
|
|
1290
|
-
action: "gitlab:issue:edit",
|
|
1291
|
-
input: {
|
|
1292
|
-
...commonGitlabConfigExample,
|
|
1293
|
-
projectId: 12,
|
|
1294
|
-
title: "Confidential Issue",
|
|
1295
|
-
description: "This issue is confidential",
|
|
1296
|
-
confidential: true
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
]
|
|
1300
|
-
})
|
|
1301
|
-
},
|
|
1302
|
-
{
|
|
1303
|
-
description: "Edit a gitlab issue to lock the discussion",
|
|
1304
|
-
example: yaml__default.default.stringify({
|
|
1305
|
-
steps: [
|
|
1306
|
-
{
|
|
1307
|
-
id: "gitlabIssue",
|
|
1308
|
-
name: "EditIssues",
|
|
1309
|
-
action: "gitlab:issue:edit",
|
|
1310
|
-
input: {
|
|
1311
|
-
...commonGitlabConfigExample,
|
|
1312
|
-
projectId: 12,
|
|
1313
|
-
title: "Locked Discussion Issue",
|
|
1314
|
-
description: "This discussion on this issue is locked",
|
|
1315
|
-
discussionLocked: true
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
]
|
|
1319
|
-
})
|
|
1320
|
-
},
|
|
1321
|
-
{
|
|
1322
|
-
description: "Edit a gitlab issue to remove labels and update milestone",
|
|
1323
|
-
example: yaml__default.default.stringify({
|
|
1324
|
-
steps: [
|
|
1325
|
-
{
|
|
1326
|
-
id: "gitlabIssue",
|
|
1327
|
-
name: "EditIssues",
|
|
1328
|
-
action: "gitlab:issue:edit",
|
|
1329
|
-
input: {
|
|
1330
|
-
...commonGitlabConfigExample,
|
|
1331
|
-
projectId: 12,
|
|
1332
|
-
title: "Issue with labels removed and milestone updated",
|
|
1333
|
-
description: "This issue has labels removed and milestone updated",
|
|
1334
|
-
removeLabels: "phase1:label1",
|
|
1335
|
-
milestoneId: 6
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
]
|
|
1339
|
-
})
|
|
1340
|
-
},
|
|
1341
|
-
{
|
|
1342
|
-
description: "Edit a gitlab issue to remove some labels and new ones",
|
|
1343
|
-
example: yaml__default.default.stringify({
|
|
1344
|
-
steps: [
|
|
1345
|
-
{
|
|
1346
|
-
id: "gitlabIssue",
|
|
1347
|
-
name: "EditIssues",
|
|
1348
|
-
action: "gitlab:issue:edit",
|
|
1349
|
-
input: {
|
|
1350
|
-
...commonGitlabConfigExample,
|
|
1351
|
-
projectId: 12,
|
|
1352
|
-
title: "Issue with labels updated",
|
|
1353
|
-
description: "This issue has labels removed and new ones added",
|
|
1354
|
-
removeLabels: "bug,urgent",
|
|
1355
|
-
labels: "enhancement:documentation"
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
]
|
|
1359
|
-
})
|
|
1360
|
-
},
|
|
1361
|
-
{
|
|
1362
|
-
description: "Edit a gitlab issue to change issue type and add labels",
|
|
1363
|
-
example: yaml__default.default.stringify({
|
|
1364
|
-
steps: [
|
|
1365
|
-
{
|
|
1366
|
-
id: "gitlabIssue",
|
|
1367
|
-
name: "EditIssues",
|
|
1368
|
-
action: "gitlab:issue:edit",
|
|
1369
|
-
input: {
|
|
1370
|
-
...commonGitlabConfigExample,
|
|
1371
|
-
projectId: 12,
|
|
1372
|
-
title: "Issue with type and labels",
|
|
1373
|
-
description: "This issue has been changes and new labels added",
|
|
1374
|
-
labels: "task,high-priority",
|
|
1375
|
-
issueType: "task"
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
]
|
|
1379
|
-
})
|
|
1380
|
-
}
|
|
1381
|
-
];
|
|
1382
|
-
|
|
1383
|
-
const editIssueInputProperties = zod.z.object({
|
|
1384
|
-
projectId: zod.z.number().describe(
|
|
1385
|
-
"The global ID or URL-encoded path of the project owned by the authenticated user."
|
|
1386
|
-
),
|
|
1387
|
-
issueIid: zod.z.number().describe("The internal ID of a project's issue"),
|
|
1388
|
-
addLabels: zod.z.string({
|
|
1389
|
-
description: "Comma-separated label names to add to an issue. If a label does not already exist, this creates a new project label and assigns it to the issue."
|
|
1390
|
-
}).optional(),
|
|
1391
|
-
assignees: zod.z.array(zod.z.number(), {
|
|
1392
|
-
description: "IDs of the users to assign the issue to."
|
|
1393
|
-
}).optional(),
|
|
1394
|
-
confidential: zod.z.boolean({ description: "Updates an issue to be confidential." }).optional(),
|
|
1395
|
-
description: zod.z.string().describe("The description of an issue. Limited to 1,048,576 characters.").max(1048576).optional(),
|
|
1396
|
-
discussionLocked: zod.z.boolean({
|
|
1397
|
-
description: "Flag indicating if the issue\u2019s discussion is locked. If the discussion is locked only project members can add or edit comments."
|
|
1398
|
-
}).optional(),
|
|
1399
|
-
dueDate: zod.z.string().describe(
|
|
1400
|
-
"The due date. Date time string in the format YYYY-MM-DD, for example 2016-03-11."
|
|
1401
|
-
).regex(/^\d{4}-\d{2}-\d{2}$/, "Invalid date format. Use YYYY-MM-DD").optional(),
|
|
1402
|
-
epicId: zod.z.number({
|
|
1403
|
-
description: "ID of the epic to add the issue to. Valid values are greater than or equal to 0."
|
|
1404
|
-
}).min(0, "Valid values should be equal or greater than zero").optional(),
|
|
1405
|
-
issueType: zod.z.nativeEnum(IssueType, {
|
|
1406
|
-
description: "Updates the type of issue. One of issue, incident, test_case or task."
|
|
1407
|
-
}).optional(),
|
|
1408
|
-
labels: zod.z.string({
|
|
1409
|
-
description: "Comma-separated label names for an issue. Set to an empty string to unassign all labels. If a label does not already exist, this creates a new project label and assigns it to the issue."
|
|
1410
|
-
}).optional(),
|
|
1411
|
-
milestoneId: zod.z.number({
|
|
1412
|
-
description: "The global ID of a milestone to assign the issue to. Set to 0 or provide an empty value to unassign a milestone"
|
|
1413
|
-
}).optional(),
|
|
1414
|
-
removeLabels: zod.z.string({
|
|
1415
|
-
description: "Comma-separated label names to remove from an issue."
|
|
1416
|
-
}).optional(),
|
|
1417
|
-
stateEvent: zod.z.nativeEnum(IssueStateEvent, {
|
|
1418
|
-
description: "The state event of an issue. To close the issue, use close, and to reopen it, use reopen."
|
|
1419
|
-
}).optional(),
|
|
1420
|
-
title: zod.z.string().describe("The title of an issue.").optional(),
|
|
1421
|
-
updatedAt: zod.z.string().describe(
|
|
1422
|
-
"When the issue was updated. Date time string, ISO 8601 formatted"
|
|
1423
|
-
).regex(
|
|
1424
|
-
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/,
|
|
1425
|
-
"Invalid date format. Use YYYY-MM-DDTHH:mm:ssZ or YYYY-MM-DDTHH:mm:ss.SSSZ"
|
|
1426
|
-
).optional(),
|
|
1427
|
-
weight: zod.z.number({ description: "The issue weight" }).min(0, "Valid values should be equal or greater than zero").max(10, "Valid values should be equal or less than 10").optional()
|
|
1428
|
-
});
|
|
1429
|
-
const editIssueOutputProperties = zod.z.object({
|
|
1430
|
-
issueUrl: zod.z.string({ description: "Issue WebUrl" }),
|
|
1431
|
-
projectId: zod.z.number({
|
|
1432
|
-
description: "The project id the issue belongs to WebUrl"
|
|
1433
|
-
}),
|
|
1434
|
-
issueId: zod.z.number({ description: "The issues Id" }),
|
|
1435
|
-
issueIid: zod.z.number({
|
|
1436
|
-
description: "The issues internal ID of a project's issue"
|
|
1437
|
-
}),
|
|
1438
|
-
state: zod.z.string({ description: "The state event of an issue" }),
|
|
1439
|
-
title: zod.z.string({ description: "The title of an issue." }),
|
|
1440
|
-
updatedAt: zod.z.string({ description: "The last updated time of the issue." })
|
|
1441
|
-
});
|
|
1442
|
-
const editGitlabIssueAction = (options) => {
|
|
1443
|
-
const { integrations } = options;
|
|
1444
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
1445
|
-
id: "gitlab:issue:edit",
|
|
1446
|
-
description: "Edit a Gitlab issue.",
|
|
1447
|
-
examples: examples$6,
|
|
1448
|
-
schema: {
|
|
1449
|
-
input: commonGitlabConfig.merge(editIssueInputProperties),
|
|
1450
|
-
output: editIssueOutputProperties
|
|
1451
|
-
},
|
|
1452
|
-
async handler(ctx) {
|
|
1453
|
-
try {
|
|
1454
|
-
const {
|
|
1455
|
-
repoUrl,
|
|
1456
|
-
projectId,
|
|
1457
|
-
title,
|
|
1458
|
-
addLabels,
|
|
1459
|
-
removeLabels,
|
|
1460
|
-
issueIid,
|
|
1461
|
-
description,
|
|
1462
|
-
confidential = false,
|
|
1463
|
-
assignees = [],
|
|
1464
|
-
updatedAt = "",
|
|
1465
|
-
dueDate,
|
|
1466
|
-
discussionLocked = false,
|
|
1467
|
-
epicId,
|
|
1468
|
-
labels,
|
|
1469
|
-
issueType,
|
|
1470
|
-
milestoneId,
|
|
1471
|
-
stateEvent,
|
|
1472
|
-
weight,
|
|
1473
|
-
token
|
|
1474
|
-
} = commonGitlabConfig.merge(editIssueInputProperties).parse(ctx.input);
|
|
1475
|
-
const { host } = parseRepoUrl(repoUrl, integrations);
|
|
1476
|
-
const api = getClient({ host, integrations, token });
|
|
1477
|
-
let isEpicScoped = false;
|
|
1478
|
-
if (epicId) {
|
|
1479
|
-
isEpicScoped = await checkEpicScope(api, projectId, epicId);
|
|
1480
|
-
if (isEpicScoped) {
|
|
1481
|
-
ctx.logger.info("Epic is within Project Scope");
|
|
1482
|
-
} else {
|
|
1483
|
-
ctx.logger.warn(
|
|
1484
|
-
"Chosen epic is not within the Project Scope. The issue will be created without an associated epic."
|
|
1485
|
-
);
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
const mappedUpdatedAt = convertDate(
|
|
1489
|
-
String(updatedAt),
|
|
1490
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
1491
|
-
);
|
|
1492
|
-
const editIssueOptions = {
|
|
1493
|
-
addLabels,
|
|
1494
|
-
assigneeIds: assignees,
|
|
1495
|
-
confidential,
|
|
1496
|
-
description,
|
|
1497
|
-
discussionLocked,
|
|
1498
|
-
dueDate,
|
|
1499
|
-
epicId: isEpicScoped ? epicId : void 0,
|
|
1500
|
-
issueType,
|
|
1501
|
-
labels,
|
|
1502
|
-
milestoneId,
|
|
1503
|
-
removeLabels,
|
|
1504
|
-
stateEvent,
|
|
1505
|
-
title,
|
|
1506
|
-
updatedAt: mappedUpdatedAt,
|
|
1507
|
-
weight
|
|
1508
|
-
};
|
|
1509
|
-
const response = await api.Issues.edit(
|
|
1510
|
-
projectId,
|
|
1511
|
-
issueIid,
|
|
1512
|
-
editIssueOptions
|
|
1513
|
-
);
|
|
1514
|
-
ctx.output("issueId", response.id);
|
|
1515
|
-
ctx.output("projectId", response.project_id);
|
|
1516
|
-
ctx.output("issueUrl", response.web_url);
|
|
1517
|
-
ctx.output("issueIid", response.iid);
|
|
1518
|
-
ctx.output("title", response.title);
|
|
1519
|
-
ctx.output("state", response.state);
|
|
1520
|
-
ctx.output("updatedAt", response.updated_at);
|
|
1521
|
-
} catch (error) {
|
|
1522
|
-
if (error instanceof zod.z.ZodError) {
|
|
1523
|
-
throw new errors.InputError(`Validation error: ${error.message}`, {
|
|
1524
|
-
validationErrors: error.errors
|
|
1525
|
-
});
|
|
1526
|
-
}
|
|
1527
|
-
throw new errors.InputError(
|
|
1528
|
-
`Failed to edit/modify GitLab issue: ${error.message}`
|
|
1529
|
-
);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
});
|
|
1533
|
-
};
|
|
1534
|
-
|
|
1535
|
-
function createGitlabApi(options) {
|
|
1536
|
-
const { integrations, token: providedToken, repoUrl } = options;
|
|
1537
|
-
const { host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
1538
|
-
const integrationConfig = integrations.gitlab.byHost(host);
|
|
1539
|
-
if (!integrationConfig) {
|
|
1540
|
-
throw new errors.InputError(
|
|
1541
|
-
`No matching integration configuration for host ${host}, please check your integrations config`
|
|
1542
|
-
);
|
|
1543
|
-
}
|
|
1544
|
-
if (!integrationConfig.config.token && !providedToken) {
|
|
1545
|
-
throw new errors.InputError(`No token available for host ${host}`);
|
|
1546
|
-
}
|
|
1547
|
-
const token = providedToken ?? integrationConfig.config.token;
|
|
1548
|
-
const tokenType = providedToken ? "oauthToken" : "token";
|
|
1549
|
-
return new node.Gitlab({
|
|
1550
|
-
host: integrationConfig.config.baseUrl,
|
|
1551
|
-
[tokenType]: token
|
|
1552
|
-
});
|
|
1553
|
-
}
|
|
1554
|
-
|
|
1555
|
-
const examples$5 = [
|
|
1556
|
-
{
|
|
1557
|
-
description: "Create a merge request with a specific assignee",
|
|
1558
|
-
example: yaml__default.default.stringify({
|
|
1559
|
-
steps: [
|
|
1560
|
-
{
|
|
1561
|
-
id: "createMergeRequest",
|
|
1562
|
-
action: "publish:gitlab:merge-request",
|
|
1563
|
-
name: "Create a Merge Request",
|
|
1564
|
-
input: {
|
|
1565
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
1566
|
-
title: "Create my new MR",
|
|
1567
|
-
description: "This MR is really good",
|
|
1568
|
-
sourcePath: "./path/to/my/changes",
|
|
1569
|
-
branchName: "new-mr",
|
|
1570
|
-
assignee: "my-assignee"
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
]
|
|
1574
|
-
})
|
|
1575
|
-
},
|
|
1576
|
-
{
|
|
1577
|
-
description: "Create a merge request with removal of source branch after merge",
|
|
1578
|
-
example: yaml__default.default.stringify({
|
|
1579
|
-
steps: [
|
|
1580
|
-
{
|
|
1581
|
-
id: "createMergeRequest",
|
|
1582
|
-
action: "publish:gitlab:merge-request",
|
|
1583
|
-
name: "Create a Merge Request",
|
|
1584
|
-
input: {
|
|
1585
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
1586
|
-
title: "Create my new MR",
|
|
1587
|
-
description: "This MR is really good",
|
|
1588
|
-
sourcePath: "./path/to/my/changes",
|
|
1589
|
-
branchName: "new-mr",
|
|
1590
|
-
removeSourceBranch: true
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
]
|
|
1594
|
-
})
|
|
1595
|
-
},
|
|
1596
|
-
{
|
|
1597
|
-
description: "Create a merge request with a target branch",
|
|
1598
|
-
example: yaml__default.default.stringify({
|
|
1599
|
-
steps: [
|
|
1600
|
-
{
|
|
1601
|
-
id: "createMergeRequest",
|
|
1602
|
-
action: "publish:gitlab:merge-request",
|
|
1603
|
-
name: "Create a Merge Request",
|
|
1604
|
-
input: {
|
|
1605
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
1606
|
-
title: "Create my new MR",
|
|
1607
|
-
description: "This MR is really good",
|
|
1608
|
-
sourcePath: "./path/to/my/changes",
|
|
1609
|
-
branchName: "new-mr",
|
|
1610
|
-
targetBranchName: "test",
|
|
1611
|
-
targetPath: "Subdirectory"
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
]
|
|
1615
|
-
})
|
|
1616
|
-
},
|
|
1617
|
-
{
|
|
1618
|
-
description: "Create a merge request with a commit action as create",
|
|
1619
|
-
example: yaml__default.default.stringify({
|
|
1620
|
-
steps: [
|
|
1621
|
-
{
|
|
1622
|
-
id: "createMergeRequest",
|
|
1623
|
-
action: "publish:gitlab:merge-request",
|
|
1624
|
-
name: "Create a Merge Request",
|
|
1625
|
-
input: {
|
|
1626
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
1627
|
-
title: "Create my new MR",
|
|
1628
|
-
branchName: "new-mr",
|
|
1629
|
-
description: "MR description",
|
|
1630
|
-
commitAction: "create",
|
|
1631
|
-
targetPath: "source"
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
]
|
|
1635
|
-
})
|
|
1636
|
-
},
|
|
1637
|
-
{
|
|
1638
|
-
description: "Create a merge request with a commit action as delete",
|
|
1639
|
-
example: yaml__default.default.stringify({
|
|
1640
|
-
steps: [
|
|
1641
|
-
{
|
|
1642
|
-
id: "createMergeRequest",
|
|
1643
|
-
action: "publish:gitlab:merge-request",
|
|
1644
|
-
name: "Create a Merge Request",
|
|
1645
|
-
input: {
|
|
1646
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
1647
|
-
title: "Create my new MR",
|
|
1648
|
-
branchName: "new-mr",
|
|
1649
|
-
description: "MR description",
|
|
1650
|
-
commitAction: "delete",
|
|
1651
|
-
targetPath: "source"
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
]
|
|
1655
|
-
})
|
|
1656
|
-
},
|
|
1657
|
-
{
|
|
1658
|
-
description: "Create a merge request with a commit action as update",
|
|
1659
|
-
example: yaml__default.default.stringify({
|
|
1660
|
-
steps: [
|
|
1661
|
-
{
|
|
1662
|
-
id: "createMergeRequest",
|
|
1663
|
-
action: "publish:gitlab:merge-request",
|
|
1664
|
-
name: "Create a Merge Request",
|
|
1665
|
-
input: {
|
|
1666
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
1667
|
-
title: "Create my new MR",
|
|
1668
|
-
branchName: "new-mr",
|
|
1669
|
-
description: "MR description",
|
|
1670
|
-
commitAction: "update",
|
|
1671
|
-
targetPath: "source"
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
]
|
|
1675
|
-
})
|
|
1676
|
-
}
|
|
1677
|
-
];
|
|
1678
|
-
|
|
1679
|
-
function getFileAction(fileInfo, remoteFiles, defaultCommitAction) {
|
|
1680
|
-
if (!defaultCommitAction || defaultCommitAction === "auto") {
|
|
1681
|
-
const filePath = path__default.default.join(fileInfo.targetPath ?? "", fileInfo.file.path);
|
|
1682
|
-
return remoteFiles && remoteFiles.some((remoteFile) => remoteFile.path === filePath) ? "update" : "create";
|
|
1683
|
-
}
|
|
1684
|
-
return defaultCommitAction;
|
|
1685
|
-
}
|
|
1686
|
-
const createPublishGitlabMergeRequestAction = (options) => {
|
|
1687
|
-
const { integrations } = options;
|
|
1688
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
1689
|
-
id: "publish:gitlab:merge-request",
|
|
1690
|
-
examples: examples$5,
|
|
1691
|
-
schema: {
|
|
1692
|
-
input: {
|
|
1693
|
-
required: ["repoUrl", "branchName"],
|
|
1694
|
-
type: "object",
|
|
1695
|
-
properties: {
|
|
1696
|
-
repoUrl: {
|
|
1697
|
-
type: "string",
|
|
1698
|
-
title: "Repository Location",
|
|
1699
|
-
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`
|
|
1700
|
-
},
|
|
1701
|
-
/** @deprecated projectID is passed as query parameters in the repoUrl */
|
|
1702
|
-
projectid: {
|
|
1703
|
-
type: "string",
|
|
1704
|
-
title: "projectid",
|
|
1705
|
-
description: "Project ID/Name(slug) of the Gitlab Project"
|
|
1706
|
-
},
|
|
1707
|
-
title: {
|
|
1708
|
-
type: "string",
|
|
1709
|
-
title: "Merge Request Name",
|
|
1710
|
-
description: "The name for the merge request"
|
|
1711
|
-
},
|
|
1712
|
-
description: {
|
|
1713
|
-
type: "string",
|
|
1714
|
-
title: "Merge Request Description",
|
|
1715
|
-
description: "The description of the merge request"
|
|
1716
|
-
},
|
|
1717
|
-
branchName: {
|
|
1718
|
-
type: "string",
|
|
1719
|
-
title: "Source Branch Name",
|
|
1720
|
-
description: "The source branch name of the merge request"
|
|
1721
|
-
},
|
|
1722
|
-
targetBranchName: {
|
|
1723
|
-
type: "string",
|
|
1724
|
-
title: "Target Branch Name",
|
|
1725
|
-
description: "The target branch name of the merge request"
|
|
1726
|
-
},
|
|
1727
|
-
sourcePath: {
|
|
1728
|
-
type: "string",
|
|
1729
|
-
title: "Working Subdirectory",
|
|
1730
|
-
description: "Subdirectory of working directory to copy changes from"
|
|
1731
|
-
},
|
|
1732
|
-
targetPath: {
|
|
1733
|
-
type: "string",
|
|
1734
|
-
title: "Repository Subdirectory",
|
|
1735
|
-
description: "Subdirectory of repository to apply changes to"
|
|
1736
|
-
},
|
|
1737
|
-
token: {
|
|
1738
|
-
title: "Authentication Token",
|
|
1739
|
-
type: "string",
|
|
1740
|
-
description: "The token to use for authorization to GitLab"
|
|
1741
|
-
},
|
|
1742
|
-
commitAction: {
|
|
1743
|
-
title: "Commit action",
|
|
1744
|
-
type: "string",
|
|
1745
|
-
enum: ["create", "update", "delete", "auto"],
|
|
1746
|
-
description: 'The action to be used for git commit. Defaults to auto. "auto" is custom action provide by backstage, (automatic assign create or update action) /!\\ Use more api calls /!\\ *'
|
|
1747
|
-
},
|
|
1748
|
-
removeSourceBranch: {
|
|
1749
|
-
title: "Delete source branch",
|
|
1750
|
-
type: "boolean",
|
|
1751
|
-
description: "Option to delete source branch once the MR has been merged. Default: false"
|
|
1752
|
-
},
|
|
1753
|
-
assignee: {
|
|
1754
|
-
title: "Merge Request Assignee",
|
|
1755
|
-
type: "string",
|
|
1756
|
-
description: "User this merge request will be assigned to"
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
},
|
|
1760
|
-
output: {
|
|
1761
|
-
type: "object",
|
|
1762
|
-
properties: {
|
|
1763
|
-
targetBranchName: {
|
|
1764
|
-
title: "Target branch name of the merge request",
|
|
1765
|
-
type: "string"
|
|
1766
|
-
},
|
|
1767
|
-
projectid: {
|
|
1768
|
-
title: "Gitlab Project id/Name(slug)",
|
|
1769
|
-
type: "string"
|
|
1770
|
-
},
|
|
1771
|
-
projectPath: {
|
|
1772
|
-
title: "Gitlab Project path",
|
|
1773
|
-
type: "string"
|
|
1774
|
-
},
|
|
1775
|
-
mergeRequestUrl: {
|
|
1776
|
-
title: "MergeRequest(MR) URL",
|
|
1777
|
-
type: "string",
|
|
1778
|
-
description: "Link to the merge request in GitLab"
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
},
|
|
1783
|
-
async handler(ctx) {
|
|
1784
|
-
const {
|
|
1785
|
-
assignee,
|
|
1786
|
-
branchName,
|
|
1787
|
-
targetBranchName,
|
|
1788
|
-
description,
|
|
1789
|
-
repoUrl,
|
|
1790
|
-
removeSourceBranch,
|
|
1791
|
-
targetPath,
|
|
1792
|
-
sourcePath,
|
|
1793
|
-
title,
|
|
1794
|
-
token
|
|
1795
|
-
} = ctx.input;
|
|
1796
|
-
const { owner, repo, project } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
1797
|
-
const repoID = project ? project : `${owner}/${repo}`;
|
|
1798
|
-
const api = createGitlabApi({
|
|
1799
|
-
integrations,
|
|
1800
|
-
token,
|
|
1801
|
-
repoUrl
|
|
1802
|
-
});
|
|
1803
|
-
let assigneeId = void 0;
|
|
1804
|
-
if (assignee !== void 0) {
|
|
1805
|
-
try {
|
|
1806
|
-
const assigneeUser = await api.Users.username(assignee);
|
|
1807
|
-
assigneeId = assigneeUser[0].id;
|
|
1808
|
-
} catch (e) {
|
|
1809
|
-
ctx.logger.warn(
|
|
1810
|
-
`Failed to find gitlab user id for ${assignee}: ${e}. Proceeding with MR creation without an assignee.`
|
|
1811
|
-
);
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
let fileRoot;
|
|
1815
|
-
if (sourcePath) {
|
|
1816
|
-
fileRoot = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, sourcePath);
|
|
1817
|
-
} else if (targetPath) {
|
|
1818
|
-
fileRoot = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, targetPath);
|
|
1819
|
-
} else {
|
|
1820
|
-
fileRoot = ctx.workspacePath;
|
|
1821
|
-
}
|
|
1822
|
-
const fileContents = await pluginScaffolderNode.serializeDirectoryContents(fileRoot, {
|
|
1823
|
-
gitignore: true
|
|
1824
|
-
});
|
|
1825
|
-
let targetBranch = targetBranchName;
|
|
1826
|
-
if (!targetBranch) {
|
|
1827
|
-
const projects = await api.Projects.show(repoID);
|
|
1828
|
-
const { default_branch: defaultBranch } = projects;
|
|
1829
|
-
targetBranch = defaultBranch;
|
|
1830
|
-
}
|
|
1831
|
-
let remoteFiles = [];
|
|
1832
|
-
if (!ctx.input.commitAction || ctx.input.commitAction === "auto") {
|
|
1833
|
-
try {
|
|
1834
|
-
remoteFiles = await api.Repositories.tree(repoID, {
|
|
1835
|
-
ref: targetBranch,
|
|
1836
|
-
recursive: true,
|
|
1837
|
-
path: targetPath ?? void 0
|
|
1838
|
-
});
|
|
1839
|
-
} catch (e) {
|
|
1840
|
-
ctx.logger.warn(
|
|
1841
|
-
`Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${e}`
|
|
1842
|
-
);
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
const actions = fileContents.map((file) => ({
|
|
1846
|
-
action: getFileAction(
|
|
1847
|
-
{ file, targetPath },
|
|
1848
|
-
remoteFiles,
|
|
1849
|
-
ctx.input.commitAction
|
|
1850
|
-
),
|
|
1851
|
-
filePath: targetPath ? path__default.default.posix.join(targetPath, file.path) : file.path,
|
|
1852
|
-
encoding: "base64",
|
|
1853
|
-
content: file.content.toString("base64"),
|
|
1854
|
-
execute_filemode: file.executable
|
|
1855
|
-
}));
|
|
1856
|
-
try {
|
|
1857
|
-
await api.Branches.create(repoID, branchName, String(targetBranch));
|
|
1858
|
-
} catch (e) {
|
|
1859
|
-
throw new errors.InputError(
|
|
1860
|
-
`The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${e}`
|
|
1861
|
-
);
|
|
1862
|
-
}
|
|
1863
|
-
try {
|
|
1864
|
-
await api.Commits.create(repoID, branchName, ctx.input.title, actions);
|
|
1865
|
-
} catch (e) {
|
|
1866
|
-
throw new errors.InputError(
|
|
1867
|
-
`Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${e}`
|
|
1868
|
-
);
|
|
1869
|
-
}
|
|
1870
|
-
try {
|
|
1871
|
-
const mergeRequestUrl = await api.MergeRequests.create(
|
|
1872
|
-
repoID,
|
|
1873
|
-
branchName,
|
|
1874
|
-
String(targetBranch),
|
|
1875
|
-
title,
|
|
1876
|
-
{
|
|
1877
|
-
description,
|
|
1878
|
-
removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,
|
|
1879
|
-
assigneeId
|
|
1880
|
-
}
|
|
1881
|
-
).then((mergeRequest) => {
|
|
1882
|
-
return mergeRequest.web_url;
|
|
1883
|
-
});
|
|
1884
|
-
ctx.output("projectid", repoID);
|
|
1885
|
-
ctx.output("targetBranchName", targetBranch);
|
|
1886
|
-
ctx.output("projectPath", repoID);
|
|
1887
|
-
ctx.output("mergeRequestUrl", mergeRequestUrl);
|
|
1888
|
-
} catch (e) {
|
|
1889
|
-
throw new errors.InputError(`Merge request creation failed${e}`);
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1892
|
-
});
|
|
1893
|
-
};
|
|
1894
|
-
|
|
1895
|
-
const examples$4 = [
|
|
1896
|
-
{
|
|
1897
|
-
description: "Trigger a GitLab Project Pipeline",
|
|
1898
|
-
example: yaml__default.default.stringify({
|
|
1899
|
-
steps: [
|
|
1900
|
-
{
|
|
1901
|
-
id: "triggerPipeline",
|
|
1902
|
-
name: "Trigger Project Pipeline",
|
|
1903
|
-
action: "gitlab:pipeline:trigger",
|
|
1904
|
-
input: {
|
|
1905
|
-
...commonGitlabConfigExample,
|
|
1906
|
-
projectId: 12,
|
|
1907
|
-
tokenDescription: "This is the text that will appear in the pipeline token",
|
|
1908
|
-
token: "glpt-xxxxxxxxxxxx",
|
|
1909
|
-
branch: "main",
|
|
1910
|
-
variables: { var_one: "one", var_two: "two" }
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
]
|
|
1914
|
-
})
|
|
1915
|
-
},
|
|
1916
|
-
{
|
|
1917
|
-
description: "Trigger a GitLab Project Pipeline with No Variables",
|
|
1918
|
-
example: yaml__default.default.stringify({
|
|
1919
|
-
steps: [
|
|
1920
|
-
{
|
|
1921
|
-
id: "triggerPipeline",
|
|
1922
|
-
name: "Trigger Project Pipeline",
|
|
1923
|
-
action: "gitlab:pipeline:trigger",
|
|
1924
|
-
input: {
|
|
1925
|
-
...commonGitlabConfigExample,
|
|
1926
|
-
projectId: 12,
|
|
1927
|
-
tokenDescription: "This is the text that will appear in the pipeline token",
|
|
1928
|
-
token: "glpt-xxxxxxxxxxxx",
|
|
1929
|
-
branch: "main",
|
|
1930
|
-
variables: {}
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
]
|
|
1934
|
-
})
|
|
1935
|
-
},
|
|
1936
|
-
{
|
|
1937
|
-
description: "Trigger a GitLab Project Pipeline with Single Variables",
|
|
1938
|
-
example: yaml__default.default.stringify({
|
|
1939
|
-
steps: [
|
|
1940
|
-
{
|
|
1941
|
-
id: "triggerPipeline",
|
|
1942
|
-
name: "Trigger Project Pipeline",
|
|
1943
|
-
action: "gitlab:pipeline:trigger",
|
|
1944
|
-
input: {
|
|
1945
|
-
...commonGitlabConfigExample,
|
|
1946
|
-
projectId: 12,
|
|
1947
|
-
tokenDescription: "This is the text that will appear in the pipeline token",
|
|
1948
|
-
token: "glpt-xxxxxxxxxxxx",
|
|
1949
|
-
branch: "main",
|
|
1950
|
-
variables: { var_one: "one" }
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
]
|
|
1954
|
-
})
|
|
1955
|
-
},
|
|
1956
|
-
{
|
|
1957
|
-
description: "Trigger a GitLab Project Pipeline with Multiple Variables",
|
|
1958
|
-
example: yaml__default.default.stringify({
|
|
1959
|
-
steps: [
|
|
1960
|
-
{
|
|
1961
|
-
id: "triggerPipeline",
|
|
1962
|
-
name: "Trigger Project Pipeline",
|
|
1963
|
-
action: "gitlab:pipeline:trigger",
|
|
1964
|
-
input: {
|
|
1965
|
-
...commonGitlabConfigExample,
|
|
1966
|
-
projectId: 12,
|
|
1967
|
-
tokenDescription: "This is the text that will appear in the pipeline token",
|
|
1968
|
-
token: "glpt-xxxxxxxxxxxx",
|
|
1969
|
-
branch: "main",
|
|
1970
|
-
variables: { var_one: "one", var_two: "two", var_three: "three" }
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
]
|
|
1974
|
-
})
|
|
1975
|
-
}
|
|
1976
|
-
];
|
|
1977
|
-
|
|
1978
|
-
const pipelineInputProperties = zod.z.object({
|
|
1979
|
-
projectId: zod.z.number().describe("Project Id"),
|
|
1980
|
-
tokenDescription: zod.z.string().describe("Pipeline token description"),
|
|
1981
|
-
branch: zod.z.string().describe("Project branch"),
|
|
1982
|
-
variables: zod.z.record(zod.z.string(), zod.z.string()).optional().describe(
|
|
1983
|
-
"A object/record of key-valued strings containing the pipeline variables."
|
|
1984
|
-
)
|
|
1985
|
-
});
|
|
1986
|
-
const pipelineOutputProperties = zod.z.object({
|
|
1987
|
-
pipelineUrl: zod.z.string({ description: "Pipeline Url" })
|
|
1988
|
-
});
|
|
1989
|
-
const createTriggerGitlabPipelineAction = (options) => {
|
|
1990
|
-
const { integrations } = options;
|
|
1991
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
1992
|
-
id: "gitlab:pipeline:trigger",
|
|
1993
|
-
description: "Triggers a GitLab Pipeline.",
|
|
1994
|
-
examples: examples$4,
|
|
1995
|
-
schema: {
|
|
1996
|
-
input: commonGitlabConfig.merge(pipelineInputProperties),
|
|
1997
|
-
output: pipelineOutputProperties
|
|
1998
|
-
},
|
|
1999
|
-
async handler(ctx) {
|
|
2000
|
-
let pipelineTokenResponse = null;
|
|
2001
|
-
const { repoUrl, projectId, tokenDescription, token, branch, variables } = commonGitlabConfig.merge(pipelineInputProperties).parse(ctx.input);
|
|
2002
|
-
const { host } = parseRepoUrl(repoUrl, integrations);
|
|
2003
|
-
const api = getClient({ host, integrations, token });
|
|
2004
|
-
try {
|
|
2005
|
-
pipelineTokenResponse = await api.PipelineTriggerTokens.create(
|
|
2006
|
-
projectId,
|
|
2007
|
-
tokenDescription
|
|
2008
|
-
);
|
|
2009
|
-
if (!pipelineTokenResponse.token) {
|
|
2010
|
-
ctx.logger.error("Failed to create pipeline token.");
|
|
2011
|
-
return;
|
|
2012
|
-
}
|
|
2013
|
-
ctx.logger.info(
|
|
2014
|
-
`Pipeline token id ${pipelineTokenResponse.id} created.`
|
|
2015
|
-
);
|
|
2016
|
-
const pipelineTriggerResponse = await api.PipelineTriggerTokens.trigger(
|
|
2017
|
-
projectId,
|
|
2018
|
-
branch,
|
|
2019
|
-
pipelineTokenResponse.token,
|
|
2020
|
-
{ variables }
|
|
2021
|
-
);
|
|
2022
|
-
if (!pipelineTriggerResponse.id) {
|
|
2023
|
-
ctx.logger.error("Failed to trigger pipeline.");
|
|
2024
|
-
return;
|
|
2025
|
-
}
|
|
2026
|
-
ctx.logger.info(`Pipeline id ${pipelineTriggerResponse.id} triggered.`);
|
|
2027
|
-
ctx.output("pipelineUrl", pipelineTriggerResponse.web_url);
|
|
2028
|
-
} catch (error) {
|
|
2029
|
-
if (error instanceof zod.z.ZodError) {
|
|
2030
|
-
throw new errors.InputError(`Validation error: ${error.message}`, {
|
|
2031
|
-
validationErrors: error.errors
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
throw new errors.InputError(`Failed to trigger Pipeline: ${error.message}`);
|
|
2035
|
-
} finally {
|
|
2036
|
-
if (pipelineTokenResponse && pipelineTokenResponse.id) {
|
|
2037
|
-
try {
|
|
2038
|
-
await api.PipelineTriggerTokens.remove(
|
|
2039
|
-
projectId,
|
|
2040
|
-
pipelineTokenResponse.id
|
|
2041
|
-
);
|
|
2042
|
-
ctx.logger.info(
|
|
2043
|
-
`Deleted pipeline token ${pipelineTokenResponse.id}.`
|
|
2044
|
-
);
|
|
2045
|
-
} catch (error) {
|
|
2046
|
-
ctx.logger.error(
|
|
2047
|
-
`Failed to delete pipeline token id ${pipelineTokenResponse.id}.`
|
|
2048
|
-
);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
});
|
|
2054
|
-
};
|
|
2055
|
-
|
|
2056
|
-
const examples$3 = [
|
|
2057
|
-
{
|
|
2058
|
-
description: "Create a GitLab project access token with minimal options.",
|
|
2059
|
-
example: yaml__default.default.stringify({
|
|
2060
|
-
steps: [
|
|
2061
|
-
{
|
|
2062
|
-
id: "createAccessToken",
|
|
2063
|
-
action: "gitlab:projectAccessToken:create",
|
|
2064
|
-
name: "Create GitLab Project Access Token",
|
|
2065
|
-
input: {
|
|
2066
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2067
|
-
projectId: "456"
|
|
2068
|
-
}
|
|
2069
|
-
}
|
|
2070
|
-
]
|
|
2071
|
-
})
|
|
2072
|
-
},
|
|
2073
|
-
{
|
|
2074
|
-
description: "Create a GitLab project access token with custom scopes.",
|
|
2075
|
-
example: yaml__default.default.stringify({
|
|
2076
|
-
steps: [
|
|
2077
|
-
{
|
|
2078
|
-
id: "createAccessToken",
|
|
2079
|
-
action: "gitlab:projectAccessToken:create",
|
|
2080
|
-
name: "Create GitLab Project Access Token",
|
|
2081
|
-
input: {
|
|
2082
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2083
|
-
projectId: "789",
|
|
2084
|
-
scopes: ["read_registry", "write_repository"]
|
|
2085
|
-
}
|
|
2086
|
-
}
|
|
2087
|
-
]
|
|
2088
|
-
})
|
|
2089
|
-
},
|
|
2090
|
-
{
|
|
2091
|
-
description: "Create a GitLab project access token with a specified name.",
|
|
2092
|
-
example: yaml__default.default.stringify({
|
|
2093
|
-
steps: [
|
|
2094
|
-
{
|
|
2095
|
-
id: "createAccessToken",
|
|
2096
|
-
action: "gitlab:projectAccessToken:create",
|
|
2097
|
-
name: "Create GitLab Project Access Token",
|
|
2098
|
-
input: {
|
|
2099
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2100
|
-
projectId: "101112",
|
|
2101
|
-
name: "my-custom-token"
|
|
2102
|
-
}
|
|
2103
|
-
}
|
|
2104
|
-
]
|
|
2105
|
-
})
|
|
2106
|
-
},
|
|
2107
|
-
{
|
|
2108
|
-
description: "Create a GitLab project access token with a numeric project ID.",
|
|
2109
|
-
example: yaml__default.default.stringify({
|
|
2110
|
-
steps: [
|
|
2111
|
-
{
|
|
2112
|
-
id: "createAccessToken",
|
|
2113
|
-
action: "gitlab:projectAccessToken:create",
|
|
2114
|
-
name: "Create GitLab Project Access Token",
|
|
2115
|
-
input: {
|
|
2116
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2117
|
-
projectId: 42
|
|
2118
|
-
}
|
|
2119
|
-
}
|
|
2120
|
-
]
|
|
2121
|
-
})
|
|
2122
|
-
},
|
|
2123
|
-
{
|
|
2124
|
-
description: "Create a GitLab project access token with a specified expired Date.",
|
|
2125
|
-
example: yaml__default.default.stringify({
|
|
2126
|
-
steps: [
|
|
2127
|
-
{
|
|
2128
|
-
id: "createAccessToken",
|
|
2129
|
-
action: "gitlab:projectAccessToken:create",
|
|
2130
|
-
name: "Create GitLab Project Access Token",
|
|
2131
|
-
input: {
|
|
2132
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2133
|
-
projectId: "123",
|
|
2134
|
-
expiresAt: "2024-06-25"
|
|
2135
|
-
}
|
|
2136
|
-
}
|
|
2137
|
-
]
|
|
2138
|
-
})
|
|
2139
|
-
},
|
|
2140
|
-
{
|
|
2141
|
-
description: "Create a GitLab project access token with an access level",
|
|
2142
|
-
example: yaml__default.default.stringify({
|
|
2143
|
-
steps: [
|
|
2144
|
-
{
|
|
2145
|
-
id: "createAccessToken",
|
|
2146
|
-
action: "gitlab:projectAccessToken:create",
|
|
2147
|
-
name: "Create GitLab Project Access Token",
|
|
2148
|
-
input: {
|
|
2149
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2150
|
-
projectId: "456",
|
|
2151
|
-
accessLevel: 30
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
]
|
|
2155
|
-
})
|
|
2156
|
-
},
|
|
2157
|
-
{
|
|
2158
|
-
description: "Create a GitLab project access token with multiple options",
|
|
2159
|
-
example: yaml__default.default.stringify({
|
|
2160
|
-
steps: [
|
|
2161
|
-
{
|
|
2162
|
-
id: "createAccessToken",
|
|
2163
|
-
action: "gitlab:projectAccessToken:create",
|
|
2164
|
-
name: "Create GitLab Project Access Token",
|
|
2165
|
-
input: {
|
|
2166
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2167
|
-
projectId: "456",
|
|
2168
|
-
accessLevel: 40,
|
|
2169
|
-
name: "full-access-token",
|
|
2170
|
-
expiresAt: "2024-12-31"
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
]
|
|
2174
|
-
})
|
|
2175
|
-
},
|
|
2176
|
-
{
|
|
2177
|
-
description: "Create a GitLab project access token with a token for authorization",
|
|
2178
|
-
example: yaml__default.default.stringify({
|
|
2179
|
-
steps: [
|
|
2180
|
-
{
|
|
2181
|
-
id: "createAccessToken",
|
|
2182
|
-
action: "gitlab:projectAccessToken:create",
|
|
2183
|
-
name: "Create GitLab Project Access Token",
|
|
2184
|
-
input: {
|
|
2185
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2186
|
-
projectId: "101112",
|
|
2187
|
-
token: "personal-access-token"
|
|
2188
|
-
}
|
|
2189
|
-
}
|
|
2190
|
-
]
|
|
2191
|
-
})
|
|
2192
|
-
},
|
|
2193
|
-
{
|
|
2194
|
-
description: "Create a GitLab project access token with read-only scopes",
|
|
2195
|
-
example: yaml__default.default.stringify({
|
|
2196
|
-
steps: [
|
|
2197
|
-
{
|
|
2198
|
-
id: "createAccessToken",
|
|
2199
|
-
action: "gitlab:projectAccessToken:create",
|
|
2200
|
-
name: "Create GitLab Project Access Token",
|
|
2201
|
-
input: {
|
|
2202
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2203
|
-
projectId: "101112",
|
|
2204
|
-
scopes: ["read_repository", "read_api"]
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
]
|
|
2208
|
-
})
|
|
2209
|
-
},
|
|
2210
|
-
{
|
|
2211
|
-
description: "Create a GitLab project access token with guest access level",
|
|
2212
|
-
example: yaml__default.default.stringify({
|
|
2213
|
-
steps: [
|
|
2214
|
-
{
|
|
2215
|
-
id: "createAccessToken",
|
|
2216
|
-
action: "gitlab:projectAccessToken:create",
|
|
2217
|
-
name: "Create GitLab Project Access Token",
|
|
2218
|
-
input: {
|
|
2219
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2220
|
-
projectId: "101112",
|
|
2221
|
-
accessLevel: 10
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
]
|
|
2225
|
-
})
|
|
2226
|
-
},
|
|
2227
|
-
{
|
|
2228
|
-
description: "Create a GitLab project access token with maintainer access level",
|
|
2229
|
-
example: yaml__default.default.stringify({
|
|
2230
|
-
steps: [
|
|
2231
|
-
{
|
|
2232
|
-
id: "createAccessToken",
|
|
2233
|
-
action: "gitlab:projectAccessToken:create",
|
|
2234
|
-
name: "Create GitLab Project Access Token",
|
|
2235
|
-
input: {
|
|
2236
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2237
|
-
projectId: "101112",
|
|
2238
|
-
accessLevel: 40
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
]
|
|
2242
|
-
})
|
|
2243
|
-
},
|
|
2244
|
-
{
|
|
2245
|
-
description: "Create a GitLab project access token with owner access level",
|
|
2246
|
-
example: yaml__default.default.stringify({
|
|
2247
|
-
steps: [
|
|
2248
|
-
{
|
|
2249
|
-
id: "createAccessToken",
|
|
2250
|
-
action: "gitlab:projectAccessToken:create",
|
|
2251
|
-
name: "Create GitLab Project Access Token",
|
|
2252
|
-
input: {
|
|
2253
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2254
|
-
projectId: "101112",
|
|
2255
|
-
accessLevel: 50
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
]
|
|
2259
|
-
})
|
|
2260
|
-
},
|
|
2261
|
-
{
|
|
2262
|
-
description: "Create a GitLab project access token with a specified name and no expiration date",
|
|
2263
|
-
example: yaml__default.default.stringify({
|
|
2264
|
-
steps: [
|
|
2265
|
-
{
|
|
2266
|
-
id: "createAccessToken",
|
|
2267
|
-
action: "gitlab:projectAccessToken:create",
|
|
2268
|
-
name: "Create GitLab Project Access Token",
|
|
2269
|
-
input: {
|
|
2270
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2271
|
-
projectId: "101112",
|
|
2272
|
-
name: "no-expiry-token"
|
|
2273
|
-
}
|
|
2274
|
-
}
|
|
2275
|
-
]
|
|
2276
|
-
})
|
|
2277
|
-
},
|
|
2278
|
-
{
|
|
2279
|
-
description: "Create a GitLab project access token for a specific gitlab instance",
|
|
2280
|
-
example: yaml__default.default.stringify({
|
|
2281
|
-
steps: [
|
|
2282
|
-
{
|
|
2283
|
-
id: "createAccessToken",
|
|
2284
|
-
action: "gitlab:projectAccessToken:create",
|
|
2285
|
-
name: "Create GitLab Project Access Token",
|
|
2286
|
-
input: {
|
|
2287
|
-
repoUrl: "gitlab.example.com?repo=repo&owner=owner",
|
|
2288
|
-
projectId: "101112"
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
]
|
|
2292
|
-
})
|
|
2293
|
-
}
|
|
2294
|
-
];
|
|
2295
|
-
|
|
2296
|
-
const createGitlabProjectAccessTokenAction = (options) => {
|
|
2297
|
-
const { integrations } = options;
|
|
2298
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
2299
|
-
id: "gitlab:projectAccessToken:create",
|
|
2300
|
-
examples: examples$3,
|
|
2301
|
-
schema: {
|
|
2302
|
-
input: zod.z.object({
|
|
2303
|
-
projectId: zod.z.union([zod.z.number(), zod.z.string()], {
|
|
2304
|
-
description: "Project ID/Name(slug) of the Gitlab Project"
|
|
2305
|
-
}),
|
|
2306
|
-
token: zod.z.string({
|
|
2307
|
-
description: "The token to use for authorization to GitLab"
|
|
2308
|
-
}).optional(),
|
|
2309
|
-
name: zod.z.string({ description: "Name of Access Key" }).optional(),
|
|
2310
|
-
repoUrl: zod.z.string({ description: "URL to gitlab instance" }),
|
|
2311
|
-
accessLevel: zod.z.number({
|
|
2312
|
-
description: "Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)"
|
|
2313
|
-
}).optional(),
|
|
2314
|
-
scopes: zod.z.string({
|
|
2315
|
-
description: "Scopes for a project access token"
|
|
2316
|
-
}).array().optional(),
|
|
2317
|
-
expiresAt: zod.z.string({
|
|
2318
|
-
description: "Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days."
|
|
2319
|
-
}).optional()
|
|
2320
|
-
}),
|
|
2321
|
-
output: zod.z.object({
|
|
2322
|
-
access_token: zod.z.string({ description: "Access Token" })
|
|
2323
|
-
})
|
|
2324
|
-
},
|
|
2325
|
-
async handler(ctx) {
|
|
2326
|
-
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
|
|
2327
|
-
const {
|
|
2328
|
-
projectId,
|
|
2329
|
-
name = "tokenname",
|
|
2330
|
-
accessLevel = 40,
|
|
2331
|
-
scopes = ["read_repository"],
|
|
2332
|
-
expiresAt
|
|
2333
|
-
} = ctx.input;
|
|
2334
|
-
const { token, integrationConfig } = getToken(ctx.input, integrations);
|
|
2335
|
-
if (!integrationConfig.config.token && token) {
|
|
2336
|
-
throw new errors.InputError(
|
|
2337
|
-
`No token available for host ${integrationConfig.config.baseUrl}`
|
|
2338
|
-
);
|
|
2339
|
-
}
|
|
2340
|
-
let api;
|
|
2341
|
-
if (!ctx.input.token) {
|
|
2342
|
-
api = new rest.Gitlab({
|
|
2343
|
-
host: integrationConfig.config.baseUrl,
|
|
2344
|
-
token
|
|
2345
|
-
});
|
|
2346
|
-
} else {
|
|
2347
|
-
api = new rest.Gitlab({
|
|
2348
|
-
host: integrationConfig.config.baseUrl,
|
|
2349
|
-
oauthToken: token
|
|
2350
|
-
});
|
|
2351
|
-
}
|
|
2352
|
-
const response = await api.ProjectAccessTokens.create(
|
|
2353
|
-
projectId,
|
|
2354
|
-
name,
|
|
2355
|
-
scopes,
|
|
2356
|
-
{
|
|
2357
|
-
expiresAt: expiresAt || luxon.DateTime.now().plus({ days: 365 }).toISODate(),
|
|
2358
|
-
accessLevel
|
|
2359
|
-
}
|
|
2360
|
-
);
|
|
2361
|
-
if (!response.token) {
|
|
2362
|
-
throw new Error("Could not create project access token");
|
|
2363
|
-
}
|
|
2364
|
-
ctx.output("access_token", response.token);
|
|
2365
|
-
}
|
|
2366
|
-
});
|
|
2367
|
-
};
|
|
2368
|
-
|
|
2369
|
-
const examples$2 = [
|
|
2370
|
-
{
|
|
2371
|
-
description: "Create a GitLab project deploy token with minimal options.",
|
|
2372
|
-
example: yaml__default.default.stringify({
|
|
2373
|
-
steps: [
|
|
2374
|
-
{
|
|
2375
|
-
id: "createDeployToken",
|
|
2376
|
-
action: "gitlab:projectDeployToken:create",
|
|
2377
|
-
name: "Create GitLab Project Deploy Token",
|
|
2378
|
-
input: {
|
|
2379
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2380
|
-
projectId: "456",
|
|
2381
|
-
name: "tokenname"
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
]
|
|
2385
|
-
})
|
|
2386
|
-
},
|
|
2387
|
-
{
|
|
2388
|
-
description: "Create a GitLab project deploy token with custom scopes.",
|
|
2389
|
-
example: yaml__default.default.stringify({
|
|
2390
|
-
steps: [
|
|
2391
|
-
{
|
|
2392
|
-
id: "createDeployToken",
|
|
2393
|
-
action: "gitlab:projectDeployToken:create",
|
|
2394
|
-
name: "Create GitLab Project Deploy Token",
|
|
2395
|
-
input: {
|
|
2396
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2397
|
-
projectId: "789",
|
|
2398
|
-
name: "tokenname",
|
|
2399
|
-
scopes: ["read_registry", "write_repository"]
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
]
|
|
2403
|
-
})
|
|
2404
|
-
},
|
|
2405
|
-
{
|
|
2406
|
-
description: "Create a GitLab project deploy token with a specified name.",
|
|
2407
|
-
example: yaml__default.default.stringify({
|
|
2408
|
-
steps: [
|
|
2409
|
-
{
|
|
2410
|
-
id: "createDeployToken",
|
|
2411
|
-
action: "gitlab:projectDeployToken:create",
|
|
2412
|
-
name: "Create GitLab Project Deploy Token",
|
|
2413
|
-
input: {
|
|
2414
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2415
|
-
projectId: "101112",
|
|
2416
|
-
name: "my-custom-token"
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
]
|
|
2420
|
-
})
|
|
2421
|
-
},
|
|
2422
|
-
{
|
|
2423
|
-
description: "Create a GitLab project deploy token with a numeric project ID.",
|
|
2424
|
-
example: yaml__default.default.stringify({
|
|
2425
|
-
steps: [
|
|
2426
|
-
{
|
|
2427
|
-
id: "createDeployToken",
|
|
2428
|
-
action: "gitlab:projectDeployToken:create",
|
|
2429
|
-
name: "Create GitLab Project Deploy Token",
|
|
2430
|
-
input: {
|
|
2431
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2432
|
-
projectId: 42,
|
|
2433
|
-
name: "tokenname"
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
]
|
|
2437
|
-
})
|
|
2438
|
-
},
|
|
2439
|
-
{
|
|
2440
|
-
description: "Create a GitLab project deploy token with a custom username",
|
|
2441
|
-
example: yaml__default.default.stringify({
|
|
2442
|
-
steps: [
|
|
2443
|
-
{
|
|
2444
|
-
id: "createDeployToken",
|
|
2445
|
-
action: "gitlab:projectDeployToken:create",
|
|
2446
|
-
name: "Create GitLab Project Deploy Token",
|
|
2447
|
-
input: {
|
|
2448
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2449
|
-
projectId: 42,
|
|
2450
|
-
name: "tokenname",
|
|
2451
|
-
username: "tokenuser"
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
]
|
|
2455
|
-
})
|
|
2456
|
-
}
|
|
2457
|
-
];
|
|
2458
|
-
|
|
2459
|
-
const createGitlabProjectDeployTokenAction = (options) => {
|
|
2460
|
-
const { integrations } = options;
|
|
2461
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
2462
|
-
id: "gitlab:projectDeployToken:create",
|
|
2463
|
-
examples: examples$2,
|
|
2464
|
-
schema: {
|
|
2465
|
-
input: commonGitlabConfig.merge(
|
|
2466
|
-
zod.z.object({
|
|
2467
|
-
projectId: zod.z.union([zod.z.number(), zod.z.string()], {
|
|
2468
|
-
description: "Project ID"
|
|
2469
|
-
}),
|
|
2470
|
-
name: zod.z.string({ description: "Deploy Token Name" }),
|
|
2471
|
-
username: zod.z.string({ description: "Deploy Token Username" }).optional(),
|
|
2472
|
-
scopes: zod.z.array(zod.z.string(), { description: "Scopes" }).optional()
|
|
2473
|
-
})
|
|
2474
|
-
),
|
|
2475
|
-
output: zod.z.object({
|
|
2476
|
-
deploy_token: zod.z.string({ description: "Deploy Token" }),
|
|
2477
|
-
user: zod.z.string({ description: "User" })
|
|
2478
|
-
})
|
|
2479
|
-
},
|
|
2480
|
-
async handler(ctx) {
|
|
2481
|
-
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
|
|
2482
|
-
const { projectId, name, username, scopes } = ctx.input;
|
|
2483
|
-
const { token, integrationConfig } = getToken(ctx.input, integrations);
|
|
2484
|
-
const api = new node.Gitlab({
|
|
2485
|
-
host: integrationConfig.config.baseUrl,
|
|
2486
|
-
token
|
|
2487
|
-
});
|
|
2488
|
-
const deployToken = await api.ProjectDeployTokens.add(
|
|
2489
|
-
projectId,
|
|
2490
|
-
name,
|
|
2491
|
-
scopes,
|
|
2492
|
-
{
|
|
2493
|
-
username
|
|
2494
|
-
}
|
|
2495
|
-
);
|
|
2496
|
-
if (!deployToken.hasOwnProperty("token")) {
|
|
2497
|
-
throw new errors.InputError(`No deploy_token given from gitlab instance`);
|
|
2498
|
-
}
|
|
2499
|
-
ctx.output("deploy_token", deployToken.token);
|
|
2500
|
-
ctx.output("user", deployToken.username);
|
|
2501
|
-
}
|
|
2502
|
-
});
|
|
2503
|
-
};
|
|
2504
|
-
|
|
2505
|
-
const examples$1 = [
|
|
2506
|
-
{
|
|
2507
|
-
description: "Creating a GitLab project variable of type env_var",
|
|
2508
|
-
example: yaml__default.default.stringify({
|
|
2509
|
-
steps: [
|
|
2510
|
-
{
|
|
2511
|
-
id: "createVariable",
|
|
2512
|
-
action: "gitlab:createGitlabProjectVariableAction",
|
|
2513
|
-
name: "Create GitLab Project Variable",
|
|
2514
|
-
input: {
|
|
2515
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2516
|
-
projectId: "123",
|
|
2517
|
-
key: "MY_VARIABLE",
|
|
2518
|
-
value: "my_value",
|
|
2519
|
-
variableType: "env_var"
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
]
|
|
2523
|
-
})
|
|
2524
|
-
},
|
|
2525
|
-
{
|
|
2526
|
-
description: "Creating a GitLab project variable of type file",
|
|
2527
|
-
example: yaml__default.default.stringify({
|
|
2528
|
-
steps: [
|
|
2529
|
-
{
|
|
2530
|
-
id: "createVariable",
|
|
2531
|
-
action: "gitlab:createGitlabProjectVariableAction",
|
|
2532
|
-
name: "Create GitLab Project Variable",
|
|
2533
|
-
input: {
|
|
2534
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2535
|
-
projectId: "123",
|
|
2536
|
-
key: "MY_VARIABLE",
|
|
2537
|
-
value: "my-file-content",
|
|
2538
|
-
variableType: "file"
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
]
|
|
2542
|
-
})
|
|
2543
|
-
},
|
|
2544
|
-
{
|
|
2545
|
-
description: "Create a GitLab project variable that is protected.",
|
|
2546
|
-
example: yaml__default.default.stringify({
|
|
2547
|
-
steps: [
|
|
2548
|
-
{
|
|
2549
|
-
id: "createVariable",
|
|
2550
|
-
action: "gitlab:createGitlabProjectVariableAction",
|
|
2551
|
-
name: "Create GitLab Project Variable",
|
|
2552
|
-
input: {
|
|
2553
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2554
|
-
projectId: "456",
|
|
2555
|
-
key: "MY_VARIABLE",
|
|
2556
|
-
value: "my_value",
|
|
2557
|
-
variableType: "env_var",
|
|
2558
|
-
variableProtected: true
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
]
|
|
2562
|
-
})
|
|
2563
|
-
},
|
|
2564
|
-
{
|
|
2565
|
-
description: "Create a GitLab project variable with masked flag as true",
|
|
2566
|
-
example: yaml__default.default.stringify({
|
|
2567
|
-
steps: [
|
|
2568
|
-
{
|
|
2569
|
-
id: "createVariable",
|
|
2570
|
-
action: "gitlab:createGitlabProjectVariableAction",
|
|
2571
|
-
name: "Create GitLab Project Variable",
|
|
2572
|
-
input: {
|
|
2573
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2574
|
-
projectId: "789",
|
|
2575
|
-
key: "DB_PASSWORD",
|
|
2576
|
-
value: "password123",
|
|
2577
|
-
variableType: "env_var",
|
|
2578
|
-
masked: true
|
|
2579
|
-
}
|
|
2580
|
-
}
|
|
2581
|
-
]
|
|
2582
|
-
})
|
|
2583
|
-
},
|
|
2584
|
-
{
|
|
2585
|
-
description: "Create a GitLab project variable that is expandable.",
|
|
2586
|
-
example: yaml__default.default.stringify({
|
|
2587
|
-
steps: [
|
|
2588
|
-
{
|
|
2589
|
-
id: "createVariable",
|
|
2590
|
-
action: "gitlab:projectVariable:create",
|
|
2591
|
-
name: "Create GitLab Project Variable",
|
|
2592
|
-
input: {
|
|
2593
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2594
|
-
projectId: "123",
|
|
2595
|
-
key: "MY_VARIABLE",
|
|
2596
|
-
value: "my_value",
|
|
2597
|
-
variableType: "env_var",
|
|
2598
|
-
raw: true
|
|
2599
|
-
}
|
|
2600
|
-
}
|
|
2601
|
-
]
|
|
2602
|
-
})
|
|
2603
|
-
},
|
|
2604
|
-
{
|
|
2605
|
-
description: "Create a GitLab project variable with a specific environment scope.",
|
|
2606
|
-
example: yaml__default.default.stringify({
|
|
2607
|
-
steps: [
|
|
2608
|
-
{
|
|
2609
|
-
id: "createVariable",
|
|
2610
|
-
action: "gitlab:projectVariable:create",
|
|
2611
|
-
name: "Create GitLab Project Variable",
|
|
2612
|
-
input: {
|
|
2613
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2614
|
-
projectId: "123",
|
|
2615
|
-
key: "MY_VARIABLE",
|
|
2616
|
-
value: "my_value",
|
|
2617
|
-
variableType: "env_var",
|
|
2618
|
-
environmentScope: "production"
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2621
|
-
]
|
|
2622
|
-
})
|
|
2623
|
-
},
|
|
2624
|
-
{
|
|
2625
|
-
description: "Create a GitLab project variable with a wildcard environment scope.",
|
|
2626
|
-
example: yaml__default.default.stringify({
|
|
2627
|
-
steps: [
|
|
2628
|
-
{
|
|
2629
|
-
id: "createVariable",
|
|
2630
|
-
action: "gitlab:projectVariable:create",
|
|
2631
|
-
name: "Create GitLab Project Variable",
|
|
2632
|
-
input: {
|
|
2633
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2634
|
-
projectId: "123",
|
|
2635
|
-
key: "MY_VARIABLE",
|
|
2636
|
-
value: "my_value",
|
|
2637
|
-
variableType: "env_var",
|
|
2638
|
-
environmentScope: "*"
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
]
|
|
2642
|
-
})
|
|
2643
|
-
}
|
|
2644
|
-
];
|
|
2645
|
-
|
|
2646
|
-
const createGitlabProjectVariableAction = (options) => {
|
|
2647
|
-
const { integrations } = options;
|
|
2648
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
2649
|
-
id: "gitlab:projectVariable:create",
|
|
2650
|
-
examples: examples$1,
|
|
2651
|
-
schema: {
|
|
2652
|
-
input: commonGitlabConfig.merge(
|
|
2653
|
-
zod.z.object({
|
|
2654
|
-
projectId: zod.z.union([zod.z.number(), zod.z.string()], {
|
|
2655
|
-
description: "Project ID"
|
|
2656
|
-
}),
|
|
2657
|
-
key: zod.z.string({
|
|
2658
|
-
description: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed"
|
|
2659
|
-
}).regex(/^[A-Za-z0-9_]{1,255}$/),
|
|
2660
|
-
value: zod.z.string({ description: "The value of a variable" }),
|
|
2661
|
-
variableType: zod.z.string({
|
|
2662
|
-
description: "Variable Type (env_var or file)"
|
|
2663
|
-
}),
|
|
2664
|
-
variableProtected: zod.z.boolean({ description: "Whether the variable is protected" }).default(false).optional(),
|
|
2665
|
-
masked: zod.z.boolean({ description: "Whether the variable is masked" }).default(false).optional(),
|
|
2666
|
-
raw: zod.z.boolean({ description: "Whether the variable is expandable" }).default(false).optional(),
|
|
2667
|
-
environmentScope: zod.z.string({ description: "The environment_scope of the variable" }).default("*").optional()
|
|
2668
|
-
})
|
|
2669
|
-
)
|
|
2670
|
-
},
|
|
2671
|
-
async handler(ctx) {
|
|
2672
|
-
const {
|
|
2673
|
-
repoUrl,
|
|
2674
|
-
projectId,
|
|
2675
|
-
key,
|
|
2676
|
-
value,
|
|
2677
|
-
variableType,
|
|
2678
|
-
variableProtected = false,
|
|
2679
|
-
masked = false,
|
|
2680
|
-
raw = false,
|
|
2681
|
-
environmentScope = "*",
|
|
2682
|
-
token
|
|
2683
|
-
} = ctx.input;
|
|
2684
|
-
const { host } = parseRepoUrl(repoUrl, integrations);
|
|
2685
|
-
const api = getClient({ host, integrations, token });
|
|
2686
|
-
await api.ProjectVariables.create(projectId, key, value, {
|
|
2687
|
-
variableType,
|
|
2688
|
-
protected: variableProtected,
|
|
2689
|
-
masked,
|
|
2690
|
-
raw,
|
|
2691
|
-
environmentScope
|
|
2692
|
-
});
|
|
2693
|
-
}
|
|
2694
|
-
});
|
|
2695
|
-
};
|
|
2696
|
-
|
|
2697
|
-
const examples = [
|
|
2698
|
-
{
|
|
2699
|
-
description: "Push changes to gitlab repository with minimal changes",
|
|
2700
|
-
example: yaml__default.default.stringify({
|
|
2701
|
-
steps: [
|
|
2702
|
-
{
|
|
2703
|
-
id: "pushChanges",
|
|
2704
|
-
action: "gitlab:repo:push",
|
|
2705
|
-
name: "Push changes to gitlab repository",
|
|
2706
|
-
input: {
|
|
2707
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2708
|
-
commitMessage: "Initial Commit",
|
|
2709
|
-
branchName: "feature-branch"
|
|
2710
|
-
}
|
|
2711
|
-
}
|
|
2712
|
-
]
|
|
2713
|
-
})
|
|
2714
|
-
},
|
|
2715
|
-
{
|
|
2716
|
-
description: "Push changes to gitlab repository with a specific source and target path",
|
|
2717
|
-
example: yaml__default.default.stringify({
|
|
2718
|
-
steps: [
|
|
2719
|
-
{
|
|
2720
|
-
id: "pushChanges",
|
|
2721
|
-
action: "gitlab:repo:push",
|
|
2722
|
-
name: "Push changes to gitlab repository",
|
|
2723
|
-
input: {
|
|
2724
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2725
|
-
commitMessage: "Initial Commit",
|
|
2726
|
-
branchName: "feature-branch",
|
|
2727
|
-
sourcePath: "src",
|
|
2728
|
-
targetPath: "dest"
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2731
|
-
]
|
|
2732
|
-
})
|
|
2733
|
-
},
|
|
2734
|
-
{
|
|
2735
|
-
description: "Push changes to gitlab repository with a specific commit action",
|
|
2736
|
-
example: yaml__default.default.stringify({
|
|
2737
|
-
steps: [
|
|
2738
|
-
{
|
|
2739
|
-
id: "pushChanges",
|
|
2740
|
-
action: "gitlab:repo:push",
|
|
2741
|
-
name: "Push changes to gitlab repository",
|
|
2742
|
-
input: {
|
|
2743
|
-
repoUrl: "gitlab.com?repo=repo&owner=owner",
|
|
2744
|
-
commitMessage: "Initial Commit",
|
|
2745
|
-
branchName: "feature-branch",
|
|
2746
|
-
commitAction: "update"
|
|
2747
|
-
}
|
|
2748
|
-
}
|
|
2749
|
-
]
|
|
2750
|
-
})
|
|
2751
|
-
}
|
|
2752
|
-
];
|
|
2753
|
-
|
|
2754
|
-
const createGitlabRepoPushAction = (options) => {
|
|
2755
|
-
const { integrations } = options;
|
|
2756
|
-
return pluginScaffolderNode.createTemplateAction({
|
|
2757
|
-
id: "gitlab:repo:push",
|
|
2758
|
-
examples,
|
|
2759
|
-
schema: {
|
|
2760
|
-
input: {
|
|
2761
|
-
required: ["repoUrl", "branchName", "commitMessage"],
|
|
2762
|
-
type: "object",
|
|
2763
|
-
properties: {
|
|
2764
|
-
repoUrl: {
|
|
2765
|
-
type: "string",
|
|
2766
|
-
title: "Repository Location",
|
|
2767
|
-
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`
|
|
2768
|
-
},
|
|
2769
|
-
branchName: {
|
|
2770
|
-
type: "string",
|
|
2771
|
-
title: "Source Branch Name",
|
|
2772
|
-
description: "The branch name for the commit"
|
|
2773
|
-
},
|
|
2774
|
-
commitMessage: {
|
|
2775
|
-
type: "string",
|
|
2776
|
-
title: "Commit Message",
|
|
2777
|
-
description: `The commit message`
|
|
2778
|
-
},
|
|
2779
|
-
sourcePath: {
|
|
2780
|
-
type: "string",
|
|
2781
|
-
title: "Working Subdirectory",
|
|
2782
|
-
description: "Subdirectory of working directory to copy changes from"
|
|
2783
|
-
},
|
|
2784
|
-
targetPath: {
|
|
2785
|
-
type: "string",
|
|
2786
|
-
title: "Repository Subdirectory",
|
|
2787
|
-
description: "Subdirectory of repository to apply changes to"
|
|
2788
|
-
},
|
|
2789
|
-
token: {
|
|
2790
|
-
title: "Authentication Token",
|
|
2791
|
-
type: "string",
|
|
2792
|
-
description: "The token to use for authorization to GitLab"
|
|
2793
|
-
},
|
|
2794
|
-
commitAction: {
|
|
2795
|
-
title: "Commit action",
|
|
2796
|
-
type: "string",
|
|
2797
|
-
enum: ["create", "update", "delete"],
|
|
2798
|
-
description: "The action to be used for git commit. Defaults to create."
|
|
2799
|
-
}
|
|
2800
|
-
}
|
|
2801
|
-
},
|
|
2802
|
-
output: {
|
|
2803
|
-
type: "object",
|
|
2804
|
-
properties: {
|
|
2805
|
-
projectid: {
|
|
2806
|
-
title: "Gitlab Project id/Name(slug)",
|
|
2807
|
-
type: "string"
|
|
2808
|
-
},
|
|
2809
|
-
projectPath: {
|
|
2810
|
-
title: "Gitlab Project path",
|
|
2811
|
-
type: "string"
|
|
2812
|
-
},
|
|
2813
|
-
commitHash: {
|
|
2814
|
-
title: "The git commit hash of the commit",
|
|
2815
|
-
type: "string"
|
|
2816
|
-
}
|
|
2817
|
-
}
|
|
2818
|
-
}
|
|
2819
|
-
},
|
|
2820
|
-
async handler(ctx) {
|
|
2821
|
-
const {
|
|
2822
|
-
branchName,
|
|
2823
|
-
repoUrl,
|
|
2824
|
-
targetPath,
|
|
2825
|
-
sourcePath,
|
|
2826
|
-
token,
|
|
2827
|
-
commitAction
|
|
2828
|
-
} = ctx.input;
|
|
2829
|
-
const { owner, repo, project } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
2830
|
-
const repoID = project ? project : `${owner}/${repo}`;
|
|
2831
|
-
const api = createGitlabApi({
|
|
2832
|
-
integrations,
|
|
2833
|
-
token,
|
|
2834
|
-
repoUrl
|
|
2835
|
-
});
|
|
2836
|
-
let fileRoot;
|
|
2837
|
-
if (sourcePath) {
|
|
2838
|
-
fileRoot = backendPluginApi.resolveSafeChildPath(ctx.workspacePath, sourcePath);
|
|
2839
|
-
} else {
|
|
2840
|
-
fileRoot = ctx.workspacePath;
|
|
2841
|
-
}
|
|
2842
|
-
const fileContents = await pluginScaffolderNode.serializeDirectoryContents(fileRoot, {
|
|
2843
|
-
gitignore: true
|
|
2844
|
-
});
|
|
2845
|
-
const actions = fileContents.map((file) => ({
|
|
2846
|
-
action: commitAction ?? "create",
|
|
2847
|
-
filePath: targetPath ? path__default.default.posix.join(targetPath, file.path) : file.path,
|
|
2848
|
-
encoding: "base64",
|
|
2849
|
-
content: file.content.toString("base64"),
|
|
2850
|
-
execute_filemode: file.executable
|
|
2851
|
-
}));
|
|
2852
|
-
let branchExists = false;
|
|
2853
|
-
try {
|
|
2854
|
-
await api.Branches.show(repoID, branchName);
|
|
2855
|
-
branchExists = true;
|
|
2856
|
-
} catch (e) {
|
|
2857
|
-
if (e.response?.statusCode !== 404) {
|
|
2858
|
-
throw new errors.InputError(
|
|
2859
|
-
`Failed to check status of branch '${branchName}'. Please make sure that branch already exists or Backstage has permissions to create one. ${e}`
|
|
2860
|
-
);
|
|
2861
|
-
}
|
|
2862
|
-
}
|
|
2863
|
-
if (!branchExists) {
|
|
2864
|
-
try {
|
|
2865
|
-
const projects = await api.Projects.show(repoID);
|
|
2866
|
-
const { default_branch: defaultBranch } = projects;
|
|
2867
|
-
await api.Branches.create(repoID, branchName, String(defaultBranch));
|
|
2868
|
-
} catch (e) {
|
|
2869
|
-
throw new errors.InputError(
|
|
2870
|
-
`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. ${e}`
|
|
2871
|
-
);
|
|
2872
|
-
}
|
|
2873
|
-
}
|
|
2874
|
-
try {
|
|
2875
|
-
const commit = await api.Commits.create(
|
|
2876
|
-
repoID,
|
|
2877
|
-
branchName,
|
|
2878
|
-
ctx.input.commitMessage,
|
|
2879
|
-
actions
|
|
2880
|
-
);
|
|
2881
|
-
ctx.output("projectid", repoID);
|
|
2882
|
-
ctx.output("projectPath", repoID);
|
|
2883
|
-
ctx.output("commitHash", commit.id);
|
|
2884
|
-
} catch (e) {
|
|
2885
|
-
throw new errors.InputError(
|
|
2886
|
-
`Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${e}`
|
|
2887
|
-
);
|
|
2888
|
-
}
|
|
2889
|
-
}
|
|
2890
|
-
});
|
|
2891
|
-
};
|
|
2892
|
-
|
|
2893
|
-
const gitlabModule = backendPluginApi.createBackendModule({
|
|
2894
|
-
pluginId: "scaffolder",
|
|
2895
|
-
moduleId: "gitlab",
|
|
2896
|
-
register({ registerInit }) {
|
|
2897
|
-
registerInit({
|
|
2898
|
-
deps: {
|
|
2899
|
-
scaffolder: alpha.scaffolderActionsExtensionPoint,
|
|
2900
|
-
config: backendPluginApi.coreServices.rootConfig
|
|
2901
|
-
},
|
|
2902
|
-
async init({ scaffolder, config }) {
|
|
2903
|
-
const integrations = integration.ScmIntegrations.fromConfig(config);
|
|
2904
|
-
scaffolder.addActions(
|
|
2905
|
-
createGitlabGroupEnsureExistsAction({ integrations }),
|
|
2906
|
-
createGitlabIssueAction({ integrations }),
|
|
2907
|
-
createGitlabProjectAccessTokenAction({ integrations }),
|
|
2908
|
-
createGitlabProjectDeployTokenAction({ integrations }),
|
|
2909
|
-
createGitlabProjectVariableAction({ integrations }),
|
|
2910
|
-
createGitlabRepoPushAction({ integrations }),
|
|
2911
|
-
editGitlabIssueAction({ integrations }),
|
|
2912
|
-
createPublishGitlabAction({ config, integrations }),
|
|
2913
|
-
createPublishGitlabMergeRequestAction({ integrations }),
|
|
2914
|
-
createTriggerGitlabPipelineAction({ integrations })
|
|
2915
|
-
);
|
|
2916
|
-
}
|
|
2917
|
-
});
|
|
2918
|
-
}
|
|
2919
|
-
});
|
|
2920
|
-
|
|
2921
|
-
exports.IssueStateEvent = IssueStateEvent;
|
|
2922
|
-
exports.IssueType = IssueType;
|
|
2923
|
-
exports.createGitlabGroupEnsureExistsAction = createGitlabGroupEnsureExistsAction;
|
|
2924
|
-
exports.createGitlabIssueAction = createGitlabIssueAction;
|
|
2925
|
-
exports.createGitlabProjectAccessTokenAction = createGitlabProjectAccessTokenAction;
|
|
2926
|
-
exports.createGitlabProjectDeployTokenAction = createGitlabProjectDeployTokenAction;
|
|
2927
|
-
exports.createGitlabProjectVariableAction = createGitlabProjectVariableAction;
|
|
2928
|
-
exports.createGitlabRepoPushAction = createGitlabRepoPushAction;
|
|
2929
|
-
exports.createPublishGitlabAction = createPublishGitlabAction;
|
|
2930
|
-
exports.createPublishGitlabMergeRequestAction = createPublishGitlabMergeRequestAction;
|
|
2931
|
-
exports.createTriggerGitlabPipelineAction = createTriggerGitlabPipelineAction;
|
|
2932
|
-
exports.default = gitlabModule;
|
|
2933
|
-
exports.editGitlabIssueAction = editGitlabIssueAction;
|
|
5
|
+
var gitlab = require('./actions/gitlab.cjs.js');
|
|
6
|
+
var gitlabGroupEnsureExists = require('./actions/gitlabGroupEnsureExists.cjs.js');
|
|
7
|
+
var gitlabIssueCreate = require('./actions/gitlabIssueCreate.cjs.js');
|
|
8
|
+
var gitlabIssueEdit = require('./actions/gitlabIssueEdit.cjs.js');
|
|
9
|
+
var gitlabMergeRequest = require('./actions/gitlabMergeRequest.cjs.js');
|
|
10
|
+
var gitlabPipelineTrigger = require('./actions/gitlabPipelineTrigger.cjs.js');
|
|
11
|
+
var gitlabProjectAccessTokenCreate = require('./actions/gitlabProjectAccessTokenCreate.cjs.js');
|
|
12
|
+
var gitlabProjectDeployTokenCreate = require('./actions/gitlabProjectDeployTokenCreate.cjs.js');
|
|
13
|
+
var gitlabProjectVariableCreate = require('./actions/gitlabProjectVariableCreate.cjs.js');
|
|
14
|
+
var gitlabRepoPush = require('./actions/gitlabRepoPush.cjs.js');
|
|
15
|
+
var commonGitlabConfig = require('./commonGitlabConfig.cjs.js');
|
|
16
|
+
var module$1 = require('./module.cjs.js');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.createPublishGitlabAction = gitlab.createPublishGitlabAction;
|
|
21
|
+
exports.createGitlabGroupEnsureExistsAction = gitlabGroupEnsureExists.createGitlabGroupEnsureExistsAction;
|
|
22
|
+
exports.createGitlabIssueAction = gitlabIssueCreate.createGitlabIssueAction;
|
|
23
|
+
exports.editGitlabIssueAction = gitlabIssueEdit.editGitlabIssueAction;
|
|
24
|
+
exports.createPublishGitlabMergeRequestAction = gitlabMergeRequest.createPublishGitlabMergeRequestAction;
|
|
25
|
+
exports.createTriggerGitlabPipelineAction = gitlabPipelineTrigger.createTriggerGitlabPipelineAction;
|
|
26
|
+
exports.createGitlabProjectAccessTokenAction = gitlabProjectAccessTokenCreate.createGitlabProjectAccessTokenAction;
|
|
27
|
+
exports.createGitlabProjectDeployTokenAction = gitlabProjectDeployTokenCreate.createGitlabProjectDeployTokenAction;
|
|
28
|
+
exports.createGitlabProjectVariableAction = gitlabProjectVariableCreate.createGitlabProjectVariableAction;
|
|
29
|
+
exports.createGitlabRepoPushAction = gitlabRepoPush.createGitlabRepoPushAction;
|
|
30
|
+
exports.IssueStateEvent = commonGitlabConfig.IssueStateEvent;
|
|
31
|
+
exports.IssueType = commonGitlabConfig.IssueType;
|
|
32
|
+
exports.default = module$1.gitlabModule;
|
|
2934
33
|
//# sourceMappingURL=index.cjs.js.map
|