@backstage/plugin-scaffolder-backend-module-gitlab 0.7.2-next.0 → 0.8.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/actions/gitlab.cjs.js +131 -89
- package/dist/actions/gitlab.cjs.js.map +1 -1
- package/dist/actions/gitlab.examples.cjs.js +18 -0
- package/dist/actions/gitlab.examples.cjs.js.map +1 -1
- package/dist/actions/gitlabMergeRequest.cjs.js +60 -24
- package/dist/actions/gitlabMergeRequest.cjs.js.map +1 -1
- package/dist/actions/gitlabProjectMigrate.cjs.js +13 -5
- package/dist/actions/gitlabProjectMigrate.cjs.js.map +1 -1
- package/dist/autocomplete/autocomplete.cjs.js +1 -1
- package/dist/autocomplete/autocomplete.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/package.json +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @backstage/plugin-scaffolder-backend-module-gitlab
|
|
2
2
|
|
|
3
|
+
## 0.8.0-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9d04e91: Fix automated assignment of reviewers for instances without premium/ultimate license (404). Introduce opt-in flag for automatic reviewer assignment based on approval rules
|
|
8
|
+
- 9545c5f: `createGitlabProjectMigrateAction` can now output the `migrationId`
|
|
9
|
+
- fe44946: Fixed bug of passing wrong value to `onChange` handler when using `GitLab` autocomplete
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
- @backstage/backend-plugin-api@1.2.0-next.1
|
|
12
|
+
- @backstage/config@1.3.2
|
|
13
|
+
- @backstage/errors@1.2.7
|
|
14
|
+
- @backstage/integration@1.16.1
|
|
15
|
+
- @backstage/plugin-scaffolder-node@0.7.0-next.1
|
|
16
|
+
|
|
17
|
+
## 0.8.0-next.1
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 06eee14: Support empty repository creation in gitlab without workspace pushing and conditionally skip if the repository already exists.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
- @backstage/backend-plugin-api@1.2.0-next.0
|
|
27
|
+
- @backstage/config@1.3.2
|
|
28
|
+
- @backstage/errors@1.2.7
|
|
29
|
+
- @backstage/integration@1.16.1
|
|
30
|
+
- @backstage/plugin-scaffolder-node@0.7.0-next.0
|
|
31
|
+
|
|
3
32
|
## 0.7.2-next.0
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -49,8 +49,13 @@ function createPublishGitlabAction(options) {
|
|
|
49
49
|
},
|
|
50
50
|
sourcePath: {
|
|
51
51
|
title: "Source Path",
|
|
52
|
-
description: "Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.",
|
|
53
|
-
type: "string"
|
|
52
|
+
description: "Path within the workspace that will be used as the repository root. If omitted or set to true, the entire workspace will be published as the repository. If set to false, the created repository will be empty.",
|
|
53
|
+
type: ["string", "boolean"]
|
|
54
|
+
},
|
|
55
|
+
skipExisting: {
|
|
56
|
+
title: "Skip if repository exists",
|
|
57
|
+
description: "Do not publish the repository if it already exists. The default value is false.",
|
|
58
|
+
type: ["boolean"]
|
|
54
59
|
},
|
|
55
60
|
token: {
|
|
56
61
|
title: "Authentication Token",
|
|
@@ -234,6 +239,10 @@ function createPublishGitlabAction(options) {
|
|
|
234
239
|
commitHash: {
|
|
235
240
|
title: "The git commit hash of the initial commit",
|
|
236
241
|
type: "string"
|
|
242
|
+
},
|
|
243
|
+
created: {
|
|
244
|
+
title: "Whether the repository was created or not",
|
|
245
|
+
type: "boolean"
|
|
237
246
|
}
|
|
238
247
|
}
|
|
239
248
|
}
|
|
@@ -250,7 +259,8 @@ function createPublishGitlabAction(options) {
|
|
|
250
259
|
topics = [],
|
|
251
260
|
settings = {},
|
|
252
261
|
branches = [],
|
|
253
|
-
projectVariables = []
|
|
262
|
+
projectVariables = [],
|
|
263
|
+
skipExisting = false
|
|
254
264
|
} = ctx.input;
|
|
255
265
|
const { owner, repo, host } = pluginScaffolderNode.parseRepoUrl(repoUrl, integrations);
|
|
256
266
|
if (!owner) {
|
|
@@ -289,104 +299,136 @@ function createPublishGitlabAction(options) {
|
|
|
289
299
|
if (!targetNamespaceId) {
|
|
290
300
|
targetNamespaceId = userId;
|
|
291
301
|
}
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
name: repo,
|
|
295
|
-
visibility: repoVisibility,
|
|
296
|
-
...topics.length ? { topics } : {},
|
|
297
|
-
...Object.keys(settings).length ? { ...settings } : {}
|
|
302
|
+
const existingProjects = await client.Groups.allProjects(owner, {
|
|
303
|
+
search: repo
|
|
298
304
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
305
|
+
const existingProject = existingProjects.find(
|
|
306
|
+
(searchPathElem) => searchPathElem.path === repo
|
|
307
|
+
);
|
|
308
|
+
if (!skipExisting || skipExisting && !existingProject) {
|
|
309
|
+
ctx.logger.info(`Creating repo ${repo} in namespace ${owner}.`);
|
|
310
|
+
const { id: projectId, http_url_to_repo } = await client.Projects.create({
|
|
311
|
+
namespaceId: targetNamespaceId,
|
|
312
|
+
name: repo,
|
|
313
|
+
visibility: repoVisibility,
|
|
314
|
+
...topics.length ? { topics } : {},
|
|
315
|
+
...Object.keys(settings).length ? { ...settings } : {}
|
|
303
316
|
});
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
317
|
+
if (setUserAsOwner && integrationConfig.config.token) {
|
|
318
|
+
const adminClient = new rest.Gitlab({
|
|
319
|
+
host: integrationConfig.config.baseUrl,
|
|
320
|
+
token: integrationConfig.config.token
|
|
321
|
+
});
|
|
322
|
+
await adminClient.ProjectMembers.add(projectId, userId, 50);
|
|
323
|
+
}
|
|
324
|
+
const remoteUrl = http_url_to_repo.replace(/\.git$/, "");
|
|
325
|
+
const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;
|
|
326
|
+
const gitAuthorInfo = {
|
|
327
|
+
name: gitAuthorName ? gitAuthorName : config.getOptionalString("scaffolder.defaultAuthor.name"),
|
|
328
|
+
email: gitAuthorEmail ? gitAuthorEmail : config.getOptionalString("scaffolder.defaultAuthor.email")
|
|
329
|
+
};
|
|
330
|
+
const shouldSkipPublish = typeof ctx.input.sourcePath === "boolean" && !ctx.input.sourcePath;
|
|
331
|
+
if (!shouldSkipPublish) {
|
|
332
|
+
const commitResult = await pluginScaffolderNode.initRepoAndPush({
|
|
333
|
+
dir: typeof ctx.input.sourcePath === "boolean" ? ctx.workspacePath : pluginScaffolderNode.getRepoSourceDirectory(
|
|
334
|
+
ctx.workspacePath,
|
|
335
|
+
ctx.input.sourcePath
|
|
336
|
+
),
|
|
337
|
+
remoteUrl: http_url_to_repo,
|
|
338
|
+
defaultBranch,
|
|
339
|
+
auth: {
|
|
340
|
+
username: "oauth2",
|
|
341
|
+
password: token
|
|
342
|
+
},
|
|
343
|
+
logger: ctx.logger,
|
|
344
|
+
commitMessage: gitCommitMessage ? gitCommitMessage : config.getOptionalString("scaffolder.defaultCommitMessage"),
|
|
345
|
+
gitAuthorInfo
|
|
346
|
+
});
|
|
347
|
+
if (branches) {
|
|
348
|
+
for (const branch of branches) {
|
|
349
|
+
const {
|
|
350
|
+
name,
|
|
351
|
+
protect = false,
|
|
352
|
+
create = false,
|
|
353
|
+
ref = "master"
|
|
354
|
+
} = branch;
|
|
355
|
+
if (create) {
|
|
356
|
+
try {
|
|
357
|
+
await client.Branches.create(projectId, name, ref);
|
|
358
|
+
} catch (e) {
|
|
359
|
+
throw new errors.InputError(
|
|
360
|
+
`Branch creation failed for ${name}. ${printGitlabError(
|
|
361
|
+
e
|
|
362
|
+
)}`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
ctx.logger.info(
|
|
366
|
+
`Branch ${name} created for ${projectId} with ref ${ref}`
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
if (protect) {
|
|
370
|
+
try {
|
|
371
|
+
await client.ProtectedBranches.protect(projectId, name);
|
|
372
|
+
} catch (e) {
|
|
373
|
+
throw new errors.InputError(
|
|
374
|
+
`Branch protection failed for ${name}. ${printGitlabError(
|
|
375
|
+
e
|
|
376
|
+
)}`
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
ctx.logger.info(`Branch ${name} protected for ${projectId}`);
|
|
380
|
+
}
|
|
339
381
|
}
|
|
340
|
-
ctx.logger.info(
|
|
341
|
-
`Branch ${name} created for ${projectId} with ref ${ref}`
|
|
342
|
-
);
|
|
343
382
|
}
|
|
344
|
-
|
|
383
|
+
ctx.output("commitHash", commitResult?.commitHash);
|
|
384
|
+
}
|
|
385
|
+
if (projectVariables) {
|
|
386
|
+
for (const variable of projectVariables) {
|
|
387
|
+
const variableWithDefaults = Object.assign(variable, {
|
|
388
|
+
variable_type: variable.variable_type ?? "env_var",
|
|
389
|
+
protected: variable.protected ?? false,
|
|
390
|
+
masked: variable.masked ?? false,
|
|
391
|
+
raw: variable.raw ?? false,
|
|
392
|
+
environment_scope: variable.environment_scope ?? "*"
|
|
393
|
+
});
|
|
345
394
|
try {
|
|
346
|
-
await client.
|
|
395
|
+
await client.ProjectVariables.create(
|
|
396
|
+
projectId,
|
|
397
|
+
variableWithDefaults.key,
|
|
398
|
+
variableWithDefaults.value,
|
|
399
|
+
{
|
|
400
|
+
variableType: variableWithDefaults.variable_type,
|
|
401
|
+
protected: variableWithDefaults.protected,
|
|
402
|
+
masked: variableWithDefaults.masked,
|
|
403
|
+
environmentScope: variableWithDefaults.environment_scope,
|
|
404
|
+
description: variableWithDefaults.description,
|
|
405
|
+
raw: variableWithDefaults.raw
|
|
406
|
+
}
|
|
407
|
+
);
|
|
347
408
|
} catch (e) {
|
|
348
409
|
throw new errors.InputError(
|
|
349
|
-
`
|
|
410
|
+
`Environment variable creation failed for ${variableWithDefaults.key}. ${printGitlabError(e)}`
|
|
350
411
|
);
|
|
351
412
|
}
|
|
352
|
-
ctx.logger.info(`Branch ${name} protected for ${projectId}`);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (projectVariables) {
|
|
357
|
-
for (const variable of projectVariables) {
|
|
358
|
-
const variableWithDefaults = Object.assign(variable, {
|
|
359
|
-
variable_type: variable.variable_type ?? "env_var",
|
|
360
|
-
protected: variable.protected ?? false,
|
|
361
|
-
masked: variable.masked ?? false,
|
|
362
|
-
raw: variable.raw ?? false,
|
|
363
|
-
environment_scope: variable.environment_scope ?? "*"
|
|
364
|
-
});
|
|
365
|
-
try {
|
|
366
|
-
await client.ProjectVariables.create(
|
|
367
|
-
projectId,
|
|
368
|
-
variableWithDefaults.key,
|
|
369
|
-
variableWithDefaults.value,
|
|
370
|
-
{
|
|
371
|
-
variableType: variableWithDefaults.variable_type,
|
|
372
|
-
protected: variableWithDefaults.protected,
|
|
373
|
-
masked: variableWithDefaults.masked,
|
|
374
|
-
environmentScope: variableWithDefaults.environment_scope,
|
|
375
|
-
description: variableWithDefaults.description,
|
|
376
|
-
raw: variableWithDefaults.raw
|
|
377
|
-
}
|
|
378
|
-
);
|
|
379
|
-
} catch (e) {
|
|
380
|
-
throw new errors.InputError(
|
|
381
|
-
`Environment variable creation failed for ${variableWithDefaults.key}. ${printGitlabError(e)}`
|
|
382
|
-
);
|
|
383
413
|
}
|
|
384
414
|
}
|
|
415
|
+
ctx.output("remoteUrl", remoteUrl);
|
|
416
|
+
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
417
|
+
ctx.output("projectId", projectId);
|
|
418
|
+
ctx.output("created", true);
|
|
419
|
+
} else if (existingProject) {
|
|
420
|
+
ctx.logger.info(`Repo ${repo} already exists in namespace ${owner}.`);
|
|
421
|
+
const {
|
|
422
|
+
id: projectId,
|
|
423
|
+
http_url_to_repo,
|
|
424
|
+
default_branch
|
|
425
|
+
} = existingProject;
|
|
426
|
+
const remoteUrl = http_url_to_repo.replace(/\.git$/, "");
|
|
427
|
+
ctx.output("remoteUrl", remoteUrl);
|
|
428
|
+
ctx.output("repoContentsUrl", `${remoteUrl}/-/blob/${default_branch}`);
|
|
429
|
+
ctx.output("projectId", projectId);
|
|
430
|
+
ctx.output("created", false);
|
|
385
431
|
}
|
|
386
|
-
ctx.output("commitHash", commitResult?.commitHash);
|
|
387
|
-
ctx.output("remoteUrl", remoteUrl);
|
|
388
|
-
ctx.output("repoContentsUrl", repoContentsUrl);
|
|
389
|
-
ctx.output("projectId", projectId);
|
|
390
432
|
}
|
|
391
433
|
});
|
|
392
434
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlab.cjs.js","sources":["../../src/actions/gitlab.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { Gitlab, VariableType } from '@gitbeaker/rest';\nimport {\n initRepoAndPush,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport { examples } from './gitlab.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitLab.\n *\n * @public\n */\nexport function createPublishGitlabAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n defaultBranch?: string;\n /** @deprecated in favour of settings.visibility field */\n repoVisibility?: 'private' | 'internal' | 'public';\n sourcePath?: string;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n setUserAsOwner?: boolean;\n /** @deprecated in favour of settings.topics field */\n topics?: string[];\n settings?: {\n path?: string;\n auto_devops_enabled?: boolean;\n ci_config_path?: string;\n description?: string;\n merge_method?: 'merge' | 'rebase_merge' | 'ff';\n squash_option?: 'default_off' | 'default_on' | 'never' | 'always';\n topics?: string[];\n visibility?: 'private' | 'internal' | 'public';\n only_allow_merge_if_all_discussions_are_resolved?: boolean;\n only_allow_merge_if_pipeline_succeeds?: boolean;\n allow_merge_on_skipped_pipeline?: boolean;\n };\n branches?: Array<{\n name: string;\n protect?: boolean;\n create?: boolean;\n ref?: string;\n }>;\n projectVariables?: Array<{\n key: string;\n value: string;\n description?: string;\n variable_type?: string;\n protected?: boolean;\n masked?: boolean;\n raw?: boolean;\n environment_scope?: string;\n }>;\n }>({\n id: 'publish:gitlab',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to GitLab.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n repoVisibility: {\n title: 'Repository Visibility',\n description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'master'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n description:\n 'Path within the workspace that will be used as the repository root. If omitted, the entire workspace will be published as the repository.',\n type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n setUserAsOwner: {\n title: 'Set User As Owner',\n type: 'boolean',\n description:\n 'Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host',\n },\n topics: {\n title: 'Topic labels',\n description:\n 'Topic labels to apply on the repository. (deprecated, use settings.topics instead)',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n settings: {\n title: 'Project settings',\n description:\n 'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes',\n type: 'object',\n properties: {\n path: {\n title: 'Project path',\n description:\n 'Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).',\n type: 'string',\n },\n auto_devops_enabled: {\n title: 'Auto DevOps enabled',\n description: 'Enable Auto DevOps for this project',\n type: 'boolean',\n },\n ci_config_path: {\n title: 'CI config path',\n description: 'Custom CI config path for this project',\n type: 'string',\n },\n description: {\n title: 'Project description',\n description: 'Short project description',\n type: 'string',\n },\n merge_method: {\n title: 'Merge Method to use',\n description: 'Merge Methods (merge, rebase_merge, ff)',\n type: 'string',\n enum: ['merge', 'rebase_merge', 'ff'],\n },\n squash_option: {\n title: 'Squash option',\n description:\n 'Set squash option for the project (never, always, default_on, default_off)',\n type: 'string',\n enum: ['default_off', 'default_on', 'never', 'always'],\n },\n topics: {\n title: 'Topic labels',\n description: 'Topic labels to apply on the repository',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n visibility: {\n title: 'Project visibility',\n description:\n 'The visibility of the project. Can be private, internal, or public. The default value is private.',\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n only_allow_merge_if_all_discussions_are_resolved: {\n title: 'All threads must be resolved',\n description:\n 'Set whether merge requests can only be merged when all the discussions are resolved.',\n type: 'boolean',\n },\n only_allow_merge_if_pipeline_succeeds: {\n title: 'Pipelines must succeed',\n description:\n 'Set whether merge requests can only be merged with successful pipelines. This setting is named Pipelines must succeed in the project settings.',\n type: 'boolean',\n },\n allow_merge_on_skipped_pipeline: {\n title: 'Skipped pipelines are considered successful',\n description:\n 'Set whether or not merge requests can be merged with skipped jobs.',\n type: 'boolean',\n },\n },\n },\n branches: {\n title: 'Project branches settings',\n type: 'array',\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: {\n title: 'Branch name',\n type: 'string',\n },\n protect: {\n title: 'Should branch be protected',\n description: `Will mark branch as protected. The default value is 'false'`,\n type: 'boolean',\n },\n create: {\n title: 'Should branch be created',\n description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,\n type: 'boolean',\n },\n ref: {\n title: 'Branch reference',\n description: `Branch reference to create branch from. The default value is 'master'`,\n type: 'string',\n },\n },\n },\n },\n projectVariables: {\n title: 'Project variables',\n description:\n 'Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable',\n type: 'array',\n items: {\n type: 'object',\n required: ['key', 'value'],\n properties: {\n key: {\n title: 'Variable key',\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n type: 'string',\n },\n value: {\n title: 'Variable value',\n description: 'The value of a variable',\n type: 'string',\n },\n description: {\n title: 'Variable description',\n description: `The description of the variable. The default value is 'null'`,\n type: 'string',\n },\n variable_type: {\n title: 'Variable type',\n description: `The type of a variable. The default value is 'env_var'`,\n type: 'string',\n enum: ['env_var', 'file'],\n },\n protected: {\n title: 'Variable protection',\n description: `Whether the variable is protected. The default value is 'false'`,\n type: 'boolean',\n },\n raw: {\n title: 'Variable raw',\n description: `Whether the variable is in raw format. The default value is 'false'`,\n type: 'boolean',\n },\n environment_scope: {\n title: 'Variable environment scope',\n description: `The environment_scope of the variable. The default value is '*'`,\n type: 'string',\n },\n },\n },\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n projectId: {\n title: 'The ID of the project',\n type: 'number',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n repoVisibility = 'private',\n defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n setUserAsOwner = false,\n topics = [],\n settings = {},\n branches = [],\n projectVariables = [],\n } = ctx.input;\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\n\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!integrationConfig.config.token && !ctx.input.token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = ctx.input.token || integrationConfig.config.token!;\n const tokenType = ctx.input.token ? 'oauthToken' : 'token';\n\n const client = new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n\n let targetNamespaceId;\n\n try {\n const namespaceResponse = (await client.Namespaces.show(owner)) as {\n id: number;\n };\n\n targetNamespaceId = namespaceResponse.id;\n } catch (e) {\n if (e.response && e.response.statusCode === 404) {\n throw new InputError(\n `The namespace ${owner} is not found or the user doesn't have permissions to access it`,\n );\n }\n throw e;\n }\n\n const { id: userId } = (await client.Users.showCurrentUser()) as {\n id: number;\n };\n\n if (!targetNamespaceId) {\n targetNamespaceId = userId;\n }\n\n const { id: projectId, http_url_to_repo } = await client.Projects.create({\n namespaceId: targetNamespaceId,\n name: repo,\n visibility: repoVisibility,\n ...(topics.length ? { topics } : {}),\n ...(Object.keys(settings).length ? { ...settings } : {}),\n });\n\n // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab\n // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to\n // create the repository, but not to push the default protected branch (e.g. master).\n // In order to set the user as owner of the newly created repository we need to check that the\n // GitLab integration configuration for the matching host contains a token and use\n // such token to bootstrap a new privileged client.\n if (setUserAsOwner && integrationConfig.config.token) {\n const adminClient = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: integrationConfig.config.token,\n });\n\n await adminClient.ProjectMembers.add(projectId, userId, 50);\n }\n\n const remoteUrl = (http_url_to_repo as string).replace(/\\.git$/, '');\n const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n const commitResult = await initRepoAndPush({\n dir: getRepoSourceDirectory(ctx.workspacePath, ctx.input.sourcePath),\n remoteUrl: http_url_to_repo as string,\n defaultBranch,\n auth: {\n username: 'oauth2',\n password: token,\n },\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n });\n\n if (branches) {\n for (const branch of branches) {\n const {\n name,\n protect = false,\n create = false,\n ref = 'master',\n } = branch;\n\n if (create) {\n try {\n await client.Branches.create(projectId, name, ref);\n } catch (e) {\n throw new InputError(\n `Branch creation failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(\n `Branch ${name} created for ${projectId} with ref ${ref}`,\n );\n }\n\n if (protect) {\n try {\n await client.ProtectedBranches.protect(projectId, name);\n } catch (e) {\n throw new InputError(\n `Branch protection failed for ${name}. ${printGitlabError(e)}`,\n );\n }\n ctx.logger.info(`Branch ${name} protected for ${projectId}`);\n }\n }\n }\n\n if (projectVariables) {\n for (const variable of projectVariables) {\n const variableWithDefaults = Object.assign(variable, {\n variable_type: (variable.variable_type ??\n 'env_var') as VariableType,\n protected: variable.protected ?? false,\n masked: variable.masked ?? false,\n raw: variable.raw ?? false,\n environment_scope: variable.environment_scope ?? '*',\n });\n\n try {\n await client.ProjectVariables.create(\n projectId,\n variableWithDefaults.key,\n variableWithDefaults.value,\n {\n variableType: variableWithDefaults.variable_type,\n protected: variableWithDefaults.protected,\n masked: variableWithDefaults.masked,\n environmentScope: variableWithDefaults.environment_scope,\n description: variableWithDefaults.description,\n raw: variableWithDefaults.raw,\n },\n );\n } catch (e) {\n throw new InputError(\n `Environment variable creation failed for ${\n variableWithDefaults.key\n }. ${printGitlabError(e)}`,\n );\n }\n }\n }\n\n ctx.output('commitHash', commitResult?.commitHash);\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('projectId', projectId);\n },\n });\n}\n\nfunction printGitlabError(error: any): string {\n return JSON.stringify({ code: error.code, message: error.description });\n}\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","Gitlab","initRepoAndPush","getRepoSourceDirectory"],"mappings":";;;;;;;AAkCO,SAAS,0BAA0B,OAGvC,EAAA;AACD,EAAM,MAAA,EAAE,YAAc,EAAA,MAAA,EAAW,GAAA,OAAA;AAEjC,EAAA,OAAOA,yCA0CJ,CAAA;AAAA,IACD,EAAI,EAAA,gBAAA;AAAA,IACJ,WACE,EAAA,2FAAA;AAAA,cACFC,wBAAA;AAAA,IACA,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA;AAAA,QACL,IAAM,EAAA,QA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AA,CAAO,aAAa,SAAS,CAAA;AACjC,MAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,MAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AAAA;AACnC,GACD,CAAA;AACH;AAEA,SAAS,iBAAiB,KAAoB,EAAA;AAC5C,EAAO,OAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,MAAM,IAAM,EAAA,OAAA,EAAS,KAAM,CAAA,WAAA,EAAa,CAAA;AACxE;;;;"}
|
|
1
|
+
{"version":3,"file":"gitlab.cjs.js","sources":["../../src/actions/gitlab.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { Gitlab, VariableType } from '@gitbeaker/rest';\nimport {\n initRepoAndPush,\n getRepoSourceDirectory,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { Config } from '@backstage/config';\nimport { examples } from './gitlab.examples';\n\n/**\n * Creates a new action that initializes a git repository of the content in the workspace\n * and publishes it to GitLab.\n *\n * @public\n */\nexport function createPublishGitlabAction(options: {\n integrations: ScmIntegrationRegistry;\n config: Config;\n}) {\n const { integrations, config } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n defaultBranch?: string;\n /** @deprecated in favour of settings.visibility field */\n repoVisibility?: 'private' | 'internal' | 'public';\n sourcePath?: string | boolean;\n skipExisting?: boolean;\n token?: string;\n gitCommitMessage?: string;\n gitAuthorName?: string;\n gitAuthorEmail?: string;\n setUserAsOwner?: boolean;\n /** @deprecated in favour of settings.topics field */\n topics?: string[];\n settings?: {\n path?: string;\n auto_devops_enabled?: boolean;\n ci_config_path?: string;\n description?: string;\n merge_method?: 'merge' | 'rebase_merge' | 'ff';\n squash_option?: 'default_off' | 'default_on' | 'never' | 'always';\n topics?: string[];\n visibility?: 'private' | 'internal' | 'public';\n only_allow_merge_if_all_discussions_are_resolved?: boolean;\n only_allow_merge_if_pipeline_succeeds?: boolean;\n allow_merge_on_skipped_pipeline?: boolean;\n };\n branches?: Array<{\n name: string;\n protect?: boolean;\n create?: boolean;\n ref?: string;\n }>;\n projectVariables?: Array<{\n key: string;\n value: string;\n description?: string;\n variable_type?: string;\n protected?: boolean;\n masked?: boolean;\n raw?: boolean;\n environment_scope?: string;\n }>;\n }>({\n id: 'publish:gitlab',\n description:\n 'Initializes a git repository of the content in the workspace, and publishes it to GitLab.',\n examples,\n schema: {\n input: {\n type: 'object',\n required: ['repoUrl'],\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n repoVisibility: {\n title: 'Repository Visibility',\n description: `Sets the visibility of the repository. The default value is 'private'. (deprecated, use settings.visibility instead)`,\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n defaultBranch: {\n title: 'Default Branch',\n type: 'string',\n description: `Sets the default branch on the repository. The default value is 'master'`,\n },\n gitCommitMessage: {\n title: 'Git Commit Message',\n type: 'string',\n description: `Sets the commit message on the repository. The default value is 'initial commit'`,\n },\n gitAuthorName: {\n title: 'Default Author Name',\n type: 'string',\n description: `Sets the default author name for the commit. The default value is 'Scaffolder'`,\n },\n gitAuthorEmail: {\n title: 'Default Author Email',\n type: 'string',\n description: `Sets the default author email for the commit.`,\n },\n sourcePath: {\n title: 'Source Path',\n description:\n 'Path within the workspace that will be used as the repository root. If omitted or set to true, the entire workspace will be published as the repository. If set to false, the created repository will be empty.',\n type: ['string', 'boolean'],\n },\n skipExisting: {\n title: 'Skip if repository exists',\n description:\n 'Do not publish the repository if it already exists. The default value is false.',\n type: ['boolean'],\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n setUserAsOwner: {\n title: 'Set User As Owner',\n type: 'boolean',\n description:\n 'Set the token user as owner of the newly created repository. Requires a token authorized to do the edit in the integration configuration for the matching host',\n },\n topics: {\n title: 'Topic labels',\n description:\n 'Topic labels to apply on the repository. (deprecated, use settings.topics instead)',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n settings: {\n title: 'Project settings',\n description:\n 'Additional project settings, based on https://docs.gitlab.com/ee/api/projects.html#create-project attributes',\n type: 'object',\n properties: {\n path: {\n title: 'Project path',\n description:\n 'Repository name for new project. Generated based on name if not provided (generated as lowercase with dashes).',\n type: 'string',\n },\n auto_devops_enabled: {\n title: 'Auto DevOps enabled',\n description: 'Enable Auto DevOps for this project',\n type: 'boolean',\n },\n ci_config_path: {\n title: 'CI config path',\n description: 'Custom CI config path for this project',\n type: 'string',\n },\n description: {\n title: 'Project description',\n description: 'Short project description',\n type: 'string',\n },\n merge_method: {\n title: 'Merge Method to use',\n description: 'Merge Methods (merge, rebase_merge, ff)',\n type: 'string',\n enum: ['merge', 'rebase_merge', 'ff'],\n },\n squash_option: {\n title: 'Squash option',\n description:\n 'Set squash option for the project (never, always, default_on, default_off)',\n type: 'string',\n enum: ['default_off', 'default_on', 'never', 'always'],\n },\n topics: {\n title: 'Topic labels',\n description: 'Topic labels to apply on the repository',\n type: 'array',\n items: {\n type: 'string',\n },\n },\n visibility: {\n title: 'Project visibility',\n description:\n 'The visibility of the project. Can be private, internal, or public. The default value is private.',\n type: 'string',\n enum: ['private', 'public', 'internal'],\n },\n only_allow_merge_if_all_discussions_are_resolved: {\n title: 'All threads must be resolved',\n description:\n 'Set whether merge requests can only be merged when all the discussions are resolved.',\n type: 'boolean',\n },\n only_allow_merge_if_pipeline_succeeds: {\n title: 'Pipelines must succeed',\n description:\n 'Set whether merge requests can only be merged with successful pipelines. This setting is named Pipelines must succeed in the project settings.',\n type: 'boolean',\n },\n allow_merge_on_skipped_pipeline: {\n title: 'Skipped pipelines are considered successful',\n description:\n 'Set whether or not merge requests can be merged with skipped jobs.',\n type: 'boolean',\n },\n },\n },\n branches: {\n title: 'Project branches settings',\n type: 'array',\n items: {\n type: 'object',\n required: ['name'],\n properties: {\n name: {\n title: 'Branch name',\n type: 'string',\n },\n protect: {\n title: 'Should branch be protected',\n description: `Will mark branch as protected. The default value is 'false'`,\n type: 'boolean',\n },\n create: {\n title: 'Should branch be created',\n description: `If branch does not exist, it will be created from provided ref. The default value is 'false'`,\n type: 'boolean',\n },\n ref: {\n title: 'Branch reference',\n description: `Branch reference to create branch from. The default value is 'master'`,\n type: 'string',\n },\n },\n },\n },\n projectVariables: {\n title: 'Project variables',\n description:\n 'Project variables settings based on Gitlab Project Environments API - https://docs.gitlab.com/ee/api/project_level_variables.html#create-a-variable',\n type: 'array',\n items: {\n type: 'object',\n required: ['key', 'value'],\n properties: {\n key: {\n title: 'Variable key',\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n type: 'string',\n },\n value: {\n title: 'Variable value',\n description: 'The value of a variable',\n type: 'string',\n },\n description: {\n title: 'Variable description',\n description: `The description of the variable. The default value is 'null'`,\n type: 'string',\n },\n variable_type: {\n title: 'Variable type',\n description: `The type of a variable. The default value is 'env_var'`,\n type: 'string',\n enum: ['env_var', 'file'],\n },\n protected: {\n title: 'Variable protection',\n description: `Whether the variable is protected. The default value is 'false'`,\n type: 'boolean',\n },\n raw: {\n title: 'Variable raw',\n description: `Whether the variable is in raw format. The default value is 'false'`,\n type: 'boolean',\n },\n environment_scope: {\n title: 'Variable environment scope',\n description: `The environment_scope of the variable. The default value is '*'`,\n type: 'string',\n },\n },\n },\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n remoteUrl: {\n title: 'A URL to the repository with the provider',\n type: 'string',\n },\n repoContentsUrl: {\n title: 'A URL to the root of the repository',\n type: 'string',\n },\n projectId: {\n title: 'The ID of the project',\n type: 'number',\n },\n commitHash: {\n title: 'The git commit hash of the initial commit',\n type: 'string',\n },\n created: {\n title: 'Whether the repository was created or not',\n type: 'boolean',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n repoVisibility = 'private',\n defaultBranch = 'master',\n gitCommitMessage = 'initial commit',\n gitAuthorName,\n gitAuthorEmail,\n setUserAsOwner = false,\n topics = [],\n settings = {},\n branches = [],\n projectVariables = [],\n skipExisting = false,\n } = ctx.input;\n const { owner, repo, host } = parseRepoUrl(repoUrl, integrations);\n\n if (!owner) {\n throw new InputError(\n `No owner provided for host: ${host}, and repo ${repo}`,\n );\n }\n\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n if (!integrationConfig.config.token && !ctx.input.token) {\n throw new InputError(`No token available for host ${host}`);\n }\n\n const token = ctx.input.token || integrationConfig.config.token!;\n const tokenType = ctx.input.token ? 'oauthToken' : 'token';\n\n const client = new Gitlab({\n host: integrationConfig.config.baseUrl,\n [tokenType]: token,\n });\n\n let targetNamespaceId;\n\n try {\n const namespaceResponse = (await client.Namespaces.show(owner)) as {\n id: number;\n };\n\n targetNamespaceId = namespaceResponse.id;\n } catch (e) {\n if (e.response && e.response.statusCode === 404) {\n throw new InputError(\n `The namespace ${owner} is not found or the user doesn't have permissions to access it`,\n );\n }\n throw e;\n }\n\n const { id: userId } = (await client.Users.showCurrentUser()) as {\n id: number;\n };\n\n if (!targetNamespaceId) {\n targetNamespaceId = userId;\n }\n\n const existingProjects = await client.Groups.allProjects(owner, {\n search: repo,\n });\n const existingProject = existingProjects.find(\n searchPathElem => searchPathElem.path === repo,\n );\n\n if (!skipExisting || (skipExisting && !existingProject)) {\n ctx.logger.info(`Creating repo ${repo} in namespace ${owner}.`);\n const { id: projectId, http_url_to_repo } =\n await client.Projects.create({\n namespaceId: targetNamespaceId,\n name: repo,\n visibility: repoVisibility,\n ...(topics.length ? { topics } : {}),\n ...(Object.keys(settings).length ? { ...settings } : {}),\n });\n\n // When setUserAsOwner is true the input token is expected to come from an unprivileged user GitLab\n // OAuth flow. In this case GitLab works in a way that allows the unprivileged user to\n // create the repository, but not to push the default protected branch (e.g. master).\n // In order to set the user as owner of the newly created repository we need to check that the\n // GitLab integration configuration for the matching host contains a token and use\n // such token to bootstrap a new privileged client.\n if (setUserAsOwner && integrationConfig.config.token) {\n const adminClient = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: integrationConfig.config.token,\n });\n\n await adminClient.ProjectMembers.add(projectId, userId, 50);\n }\n\n const remoteUrl = (http_url_to_repo as string).replace(/\\.git$/, '');\n const repoContentsUrl = `${remoteUrl}/-/blob/${defaultBranch}`;\n\n const gitAuthorInfo = {\n name: gitAuthorName\n ? gitAuthorName\n : config.getOptionalString('scaffolder.defaultAuthor.name'),\n email: gitAuthorEmail\n ? gitAuthorEmail\n : config.getOptionalString('scaffolder.defaultAuthor.email'),\n };\n const shouldSkipPublish =\n typeof ctx.input.sourcePath === 'boolean' && !ctx.input.sourcePath;\n if (!shouldSkipPublish) {\n const commitResult = await initRepoAndPush({\n dir:\n typeof ctx.input.sourcePath === 'boolean'\n ? ctx.workspacePath\n : getRepoSourceDirectory(\n ctx.workspacePath,\n ctx.input.sourcePath,\n ),\n remoteUrl: http_url_to_repo as string,\n defaultBranch,\n auth: {\n username: 'oauth2',\n password: token,\n },\n logger: ctx.logger,\n commitMessage: gitCommitMessage\n ? gitCommitMessage\n : config.getOptionalString('scaffolder.defaultCommitMessage'),\n gitAuthorInfo,\n });\n\n if (branches) {\n for (const branch of branches) {\n const {\n name,\n protect = false,\n create = false,\n ref = 'master',\n } = branch;\n\n if (create) {\n try {\n await client.Branches.create(projectId, name, ref);\n } catch (e) {\n throw new InputError(\n `Branch creation failed for ${name}. ${printGitlabError(\n e,\n )}`,\n );\n }\n ctx.logger.info(\n `Branch ${name} created for ${projectId} with ref ${ref}`,\n );\n }\n\n if (protect) {\n try {\n await client.ProtectedBranches.protect(projectId, name);\n } catch (e) {\n throw new InputError(\n `Branch protection failed for ${name}. ${printGitlabError(\n e,\n )}`,\n );\n }\n ctx.logger.info(`Branch ${name} protected for ${projectId}`);\n }\n }\n }\n ctx.output('commitHash', commitResult?.commitHash);\n }\n\n if (projectVariables) {\n for (const variable of projectVariables) {\n const variableWithDefaults = Object.assign(variable, {\n variable_type: (variable.variable_type ??\n 'env_var') as VariableType,\n protected: variable.protected ?? false,\n masked: variable.masked ?? false,\n raw: variable.raw ?? false,\n environment_scope: variable.environment_scope ?? '*',\n });\n\n try {\n await client.ProjectVariables.create(\n projectId,\n variableWithDefaults.key,\n variableWithDefaults.value,\n {\n variableType: variableWithDefaults.variable_type,\n protected: variableWithDefaults.protected,\n masked: variableWithDefaults.masked,\n environmentScope: variableWithDefaults.environment_scope,\n description: variableWithDefaults.description,\n raw: variableWithDefaults.raw,\n },\n );\n } catch (e) {\n throw new InputError(\n `Environment variable creation failed for ${\n variableWithDefaults.key\n }. ${printGitlabError(e)}`,\n );\n }\n }\n }\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', repoContentsUrl);\n ctx.output('projectId', projectId);\n ctx.output('created', true);\n } else if (existingProject) {\n ctx.logger.info(`Repo ${repo} already exists in namespace ${owner}.`);\n const {\n id: projectId,\n http_url_to_repo,\n default_branch,\n } = existingProject;\n const remoteUrl = (http_url_to_repo as string).replace(/\\.git$/, '');\n ctx.output('remoteUrl', remoteUrl);\n ctx.output('repoContentsUrl', `${remoteUrl}/-/blob/${default_branch}`);\n ctx.output('projectId', projectId);\n ctx.output('created', false);\n }\n },\n });\n}\n\nfunction printGitlabError(error: any): string {\n return JSON.stringify({ code: error.code, message: error.description });\n}\n"],"names":["createTemplateAction","examples","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,CAAC,CAAA;AAAA,eAC1B;AAAA;AACF;AACF;AAEF,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,QAAI,GAAA,CAAA,MAAA,CAAO,mBAAmB,eAAe,CAAA;AAC7C,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,QAAI,GAAA,CAAA,MAAA,CAAO,WAAW,IAAI,CAAA;AAAA,iBACjB,eAAiB,EAAA;AAC1B,QAAA,GAAA,CAAI,OAAO,IAAK,CAAA,CAAA,KAAA,EAAQ,IAAI,CAAA,6BAAA,EAAgC,KAAK,CAAG,CAAA,CAAA,CAAA;AACpE,QAAM,MAAA;AAAA,UACJ,EAAI,EAAA,SAAA;AAAA,UACJ,gBAAA;AAAA,UACA;AAAA,SACE,GAAA,eAAA;AACJ,QAAA,MAAM,SAAa,GAAA,gBAAA,CAA4B,OAAQ,CAAA,QAAA,EAAU,EAAE,CAAA;AACnE,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,QAAA,GAAA,CAAI,OAAO,iBAAmB,EAAA,CAAA,EAAG,SAAS,CAAA,QAAA,EAAW,cAAc,CAAE,CAAA,CAAA;AACrE,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,SAAS,CAAA;AACjC,QAAI,GAAA,CAAA,MAAA,CAAO,WAAW,KAAK,CAAA;AAAA;AAC7B;AACF,GACD,CAAA;AACH;AAEA,SAAS,iBAAiB,KAAoB,EAAA;AAC5C,EAAO,OAAA,IAAA,CAAK,UAAU,EAAE,IAAA,EAAM,MAAM,IAAM,EAAA,OAAA,EAAS,KAAM,CAAA,WAAA,EAAa,CAAA;AACxE;;;;"}
|
|
@@ -185,6 +185,24 @@ const examples = [
|
|
|
185
185
|
}
|
|
186
186
|
]
|
|
187
187
|
})
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
description: "Initializes a GitLab repository with the default readme and no files from workspace only if this repository does not exist yet.",
|
|
191
|
+
example: yaml__default.default.stringify({
|
|
192
|
+
steps: [
|
|
193
|
+
{
|
|
194
|
+
id: "publish",
|
|
195
|
+
action: "publish:gitlab",
|
|
196
|
+
name: "Publish to GitLab",
|
|
197
|
+
input: {
|
|
198
|
+
repoUrl: "gitlab.com?repo=project_name&owner=group_name",
|
|
199
|
+
skipExisting: true,
|
|
200
|
+
initialize_with_readme: true,
|
|
201
|
+
sourcePath: false
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
})
|
|
188
206
|
}
|
|
189
207
|
];
|
|
190
208
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlab.examples.cjs.js","sources":["../../src/actions/gitlab.examples.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Initializes a git repository with the content in the workspace, and publishes it to GitLab with the default configuration.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n },\n },\n ],\n }),\n },\n {\n description: 'Add a description.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n gitCommitMessage: 'Started a project.',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with aditional settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n ci_config_path: '.gitlab-ci.yml',\n visibility: 'public',\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with fast forward merge and always squash settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n merge_method: 'ff',\n squash_option: 'always',\n },\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with branch settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n branches: [\n {\n name: 'dev',\n create: true,\n protect: true,\n ref: 'master',\n },\n {\n name: 'master',\n protect: true,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with environment variables.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n projectVariables: [\n {\n key: 'key1',\n value: 'value1',\n protected: true,\n masked: false,\n },\n {\n key: 'key2',\n value: 'value2',\n protected: true,\n masked: false,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with pipeline must succeed and allow merge on skipped pipeline settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n only_allow_merge_if_pipeline_succeeds: true,\n allow_merge_on_skipped_pipeline: true,\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with setting to require all threads (discussions) on merge request to be resolved before merging.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n only_allow_merge_if_all_discussions_are_resolved: true,\n },\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,4HAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA;AAAA;AACX;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,oBAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,WAAa,EAAA;AAAA;AACf;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,0GAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ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AA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,mIAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,QAAU,EAAA;AAAA,cACR,gDAAkD,EAAA;AAAA;AACpD;AACF;AACF;AACF,KACD;AAAA;AAEL;;;;"}
|
|
1
|
+
{"version":3,"file":"gitlab.examples.cjs.js","sources":["../../src/actions/gitlab.examples.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TemplateExample } from '@backstage/plugin-scaffolder-node';\nimport yaml from 'yaml';\n\nexport const examples: TemplateExample[] = [\n {\n description:\n 'Initializes a git repository with the content in the workspace, and publishes it to GitLab with the default configuration.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n },\n },\n ],\n }),\n },\n {\n description: 'Add a description.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with an initial commit message, if not set defaults to `initial commit`.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n description: 'Initialize a git repository',\n gitCommitMessage: 'Started a project.',\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with aditional settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n ci_config_path: '.gitlab-ci.yml',\n visibility: 'public',\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with fast forward merge and always squash settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n merge_method: 'ff',\n squash_option: 'always',\n },\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with branch settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n branches: [\n {\n name: 'dev',\n create: true,\n protect: true,\n ref: 'master',\n },\n {\n name: 'master',\n protect: true,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description: 'Initializes a GitLab repository with environment variables.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n projectVariables: [\n {\n key: 'key1',\n value: 'value1',\n protected: true,\n masked: false,\n },\n {\n key: 'key2',\n value: 'value2',\n protected: true,\n masked: false,\n },\n ],\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with pipeline must succeed and allow merge on skipped pipeline settings.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n only_allow_merge_if_pipeline_succeeds: true,\n allow_merge_on_skipped_pipeline: true,\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with setting to require all threads (discussions) on merge request to be resolved before merging.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n settings: {\n only_allow_merge_if_all_discussions_are_resolved: true,\n },\n },\n },\n ],\n }),\n },\n {\n description:\n 'Initializes a GitLab repository with the default readme and no files from workspace only if this repository does not exist yet.',\n example: yaml.stringify({\n steps: [\n {\n id: 'publish',\n action: 'publish:gitlab',\n name: 'Publish to GitLab',\n input: {\n repoUrl: 'gitlab.com?repo=project_name&owner=group_name',\n skipExisting: true,\n initialize_with_readme: true,\n sourcePath: false,\n },\n },\n ],\n }),\n },\n];\n"],"names":["yaml"],"mappings":";;;;;;;;AAmBO,MAAM,QAA8B,GAAA;AAAA,EACzC;AAAA,IACE,WACE,EAAA,4HAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA;AAAA;AACX;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WAAa,EAAA,oBAAA;AAAA,IACb,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+C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,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,QAAU,EAAA;AAAA,cACR,qCAAuC,EAAA,IAAA;AAAA,cACvC,+BAAiC,EAAA;AAAA;AACnC;AACF;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,mIAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,QAAU,EAAA;AAAA,cACR,gDAAkD,EAAA;AAAA;AACpD;AACF;AACF;AACF,KACD;AAAA,GACH;AAAA,EACA;AAAA,IACE,WACE,EAAA,iIAAA;AAAA,IACF,OAAA,EAASA,sBAAK,SAAU,CAAA;AAAA,MACtB,KAAO,EAAA;AAAA,QACL;AAAA,UACE,EAAI,EAAA,SAAA;AAAA,UACJ,MAAQ,EAAA,gBAAA;AAAA,UACR,IAAM,EAAA,mBAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,OAAS,EAAA,+CAAA;AAAA,YACT,YAAc,EAAA,IAAA;AAAA,YACd,sBAAwB,EAAA,IAAA;AAAA,YACxB,UAAY,EAAA;AAAA;AACd;AACF;AACF,KACD;AAAA;AAEL;;;;"}
|
|
@@ -41,6 +41,34 @@ async function getFileAction(fileInfo, target, api, logger, remoteFiles, default
|
|
|
41
41
|
}
|
|
42
42
|
return defaultCommitAction;
|
|
43
43
|
}
|
|
44
|
+
async function getReviewersFromApprovalRules(api, mergerequestIId, repoID, ctx) {
|
|
45
|
+
try {
|
|
46
|
+
let mergeRequest = await api.MergeRequests.show(
|
|
47
|
+
repoID,
|
|
48
|
+
mergerequestIId
|
|
49
|
+
);
|
|
50
|
+
while (mergeRequest.detailed_merge_status === "preparing" || mergeRequest.detailed_merge_status === "approvals_syncing" || mergeRequest.detailed_merge_status === "checking") {
|
|
51
|
+
mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);
|
|
52
|
+
ctx.logger.info(`${mergeRequest.detailed_merge_status}`);
|
|
53
|
+
}
|
|
54
|
+
const approvalRules = await api.MergeRequestApprovals.allApprovalRules(
|
|
55
|
+
repoID,
|
|
56
|
+
{
|
|
57
|
+
mergerequestIId: mergeRequest.iid
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
return approvalRules.filter((rule) => rule.eligible_approvers !== void 0).map((rule) => {
|
|
61
|
+
return rule.eligible_approvers;
|
|
62
|
+
}).flat().map((user) => user.id);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
ctx.logger.warn(
|
|
65
|
+
`Failed to retrieve approval rules for MR ${mergerequestIId}: ${helpers.getErrorMessage(
|
|
66
|
+
e
|
|
67
|
+
)}. Proceeding with MR creation without reviewers from approval rules.`
|
|
68
|
+
);
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
44
72
|
const createPublishGitlabMergeRequestAction = (options) => {
|
|
45
73
|
const { integrations } = options;
|
|
46
74
|
return pluginScaffolderNode.createTemplateAction({
|
|
@@ -121,6 +149,11 @@ which uses additional API calls in order to detect whether to 'create', 'update'
|
|
|
121
149
|
type: "string"
|
|
122
150
|
},
|
|
123
151
|
description: "Users that will be assigned as reviewers"
|
|
152
|
+
},
|
|
153
|
+
assignReviewersFromApprovalRules: {
|
|
154
|
+
title: "Assign reviewers from approval rules",
|
|
155
|
+
type: "boolean",
|
|
156
|
+
description: "Automatically assign reviewers from the approval rules of the MR. Includes Codeowners"
|
|
124
157
|
}
|
|
125
158
|
}
|
|
126
159
|
},
|
|
@@ -307,31 +340,34 @@ which uses additional API calls in order to detect whether to 'create', 'update'
|
|
|
307
340
|
reviewerIds
|
|
308
341
|
}
|
|
309
342
|
);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
mergeRequest.iid,
|
|
331
|
-
{
|
|
332
|
-
reviewerIds: Array.from(eligibleUserIds)
|
|
343
|
+
if (ctx.input.assignReviewersFromApprovalRules) {
|
|
344
|
+
try {
|
|
345
|
+
const reviewersFromApprovalRules = await getReviewersFromApprovalRules(
|
|
346
|
+
api,
|
|
347
|
+
mergeRequest.iid,
|
|
348
|
+
repoID,
|
|
349
|
+
ctx
|
|
350
|
+
);
|
|
351
|
+
if (reviewersFromApprovalRules.length > 0) {
|
|
352
|
+
const eligibleUserIds = /* @__PURE__ */ new Set([
|
|
353
|
+
...reviewersFromApprovalRules,
|
|
354
|
+
...reviewerIds ?? []
|
|
355
|
+
]);
|
|
356
|
+
mergeRequest = await api.MergeRequests.edit(
|
|
357
|
+
repoID,
|
|
358
|
+
mergeRequest.iid,
|
|
359
|
+
{
|
|
360
|
+
reviewerIds: Array.from(eligibleUserIds)
|
|
361
|
+
}
|
|
362
|
+
);
|
|
333
363
|
}
|
|
334
|
-
)
|
|
364
|
+
} catch (e) {
|
|
365
|
+
ctx.logger.warn(
|
|
366
|
+
`Failed to assign reviewers from approval rules: ${helpers.getErrorMessage(
|
|
367
|
+
e
|
|
368
|
+
)}.`
|
|
369
|
+
);
|
|
370
|
+
}
|
|
335
371
|
}
|
|
336
372
|
ctx.output("projectid", repoID);
|
|
337
373
|
ctx.output("targetBranchName", targetBranch);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlabMergeRequest.cjs.js","sources":["../../src/actions/gitlabMergeRequest.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n SerializedFile,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport {\n Gitlab,\n RepositoryTreeSchema,\n CommitAction,\n SimpleUserSchema,\n} from '@gitbeaker/rest';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport {\n LoggerService,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabMergeRequest.examples';\nimport { createHash } from 'crypto';\n\nfunction computeSha256(file: SerializedFile): string {\n const hash = createHash('sha256');\n hash.update(file.content);\n return hash.digest('hex');\n}\n\nasync function getFileAction(\n fileInfo: { file: SerializedFile; targetPath?: string },\n target: { repoID: string; branch: string },\n api: InstanceType<typeof Gitlab>,\n logger: LoggerService,\n remoteFiles: RepositoryTreeSchema[],\n defaultCommitAction:\n | 'create'\n | 'delete'\n | 'update'\n | 'skip'\n | 'auto' = 'auto',\n): Promise<'create' | 'delete' | 'update' | 'skip'> {\n if (defaultCommitAction === 'auto') {\n const filePath = path.join(fileInfo.targetPath ?? '', fileInfo.file.path);\n\n if (remoteFiles?.some(remoteFile => remoteFile.path === filePath)) {\n try {\n const targetFile = await api.RepositoryFiles.show(\n target.repoID,\n filePath,\n target.branch,\n );\n if (computeSha256(fileInfo.file) === targetFile.content_sha256) {\n return 'skip';\n }\n } catch (error) {\n logger.warn(\n `Unable to retrieve detailed information for remote file ${filePath}`,\n );\n }\n return 'update';\n }\n return 'create';\n }\n return defaultCommitAction;\n}\n\n/**\n * Create a new action that creates a gitlab merge request.\n *\n * @public\n */\nexport const createPublishGitlabMergeRequestAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n title: string;\n description: string;\n branchName: string;\n targetBranchName?: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update' | 'skip' | 'auto';\n /** @deprecated projectID passed as query parameters in the repoUrl */\n projectid?: string;\n removeSourceBranch?: boolean;\n assignee?: string;\n reviewers?: string[];\n }>({\n id: 'publish:gitlab:merge-request',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository Location',\n description: `\\\nAccepts the format 'gitlab.com?repo=project_name&owner=group_name' where \\\n'project_name' is the repository name and 'group_name' is a group or username`,\n },\n /** @deprecated projectID is passed as query parameters in the repoUrl */\n projectid: {\n type: 'string',\n title: 'projectid',\n description: 'Project ID/Name(slug) of the Gitlab Project',\n },\n title: {\n type: 'string',\n title: 'Merge Request Name',\n description: 'The name for the merge request',\n },\n description: {\n type: 'string',\n title: 'Merge Request Description',\n description: 'The description of the merge request',\n },\n branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The source branch name of the merge request',\n },\n targetBranchName: {\n type: 'string',\n title: 'Target Branch Name',\n description: 'The target branch name of the merge request',\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description: `\\\nSubdirectory of working directory to copy changes from. \\\nFor reasons of backward compatibility, any specified 'targetPath' input will \\\nbe applied in place of an absent/falsy value for this input. \\\nCircumvent this behavior using '.'`,\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete', 'auto'],\n description: `\\\nThe action to be used for git commit. Defaults to the custom 'auto' action provided by backstage,\nwhich uses additional API calls in order to detect whether to 'create', 'update' or 'skip' each source file.`,\n },\n removeSourceBranch: {\n title: 'Delete source branch',\n type: 'boolean',\n description:\n 'Option to delete source branch once the MR has been merged. Default: false',\n },\n assignee: {\n title: 'Merge Request Assignee',\n type: 'string',\n description: 'User this merge request will be assigned to',\n },\n reviewers: {\n title: 'Merge Request Reviewers',\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Users that will be assigned as reviewers',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n targetBranchName: {\n title: 'Target branch name of the merge request',\n type: 'string',\n },\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n mergeRequestUrl: {\n title: 'MergeRequest(MR) URL',\n type: 'string',\n description: 'Link to the merge request in GitLab',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n assignee,\n reviewers,\n branchName,\n targetBranchName,\n description,\n repoUrl,\n removeSourceBranch,\n targetPath,\n sourcePath,\n title,\n token,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let assigneeId = undefined;\n\n if (assignee !== undefined) {\n try {\n const assigneeUser = await api.Users.all({ username: assignee });\n assigneeId = assigneeUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${assignee}: ${getErrorMessage(\n e,\n )}. Proceeding with MR creation without an assignee.`,\n );\n }\n }\n\n let reviewerIds: number[] | undefined = undefined; // Explicitly set to undefined. Strangely, passing an empty array to the API will result the other options being undefined also being explicity passed to the Gitlab API call (e.g. assigneeId)\n if (reviewers !== undefined) {\n reviewerIds = (\n await Promise.all(\n reviewers.map(async reviewer => {\n try {\n const reviewerUser = await api.Users.all({\n username: reviewer,\n });\n return reviewerUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${reviewer}: ${e}. Proceeding with MR creation without reviewer.`,\n );\n return undefined;\n }\n }),\n )\n ).filter(id => id !== undefined) as number[];\n }\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else if (targetPath) {\n // for backward compatibility\n fileRoot = resolveSafeChildPath(ctx.workspacePath, targetPath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n let targetBranch = targetBranchName;\n if (!targetBranch) {\n const projects = await api.Projects.show(repoID);\n const defaultBranch = projects.default_branch ?? projects.defaultBranch;\n if (typeof defaultBranch !== 'string' || !defaultBranch) {\n throw new InputError(\n `The branch creation failed. Target branch was not provided, and could not find default branch from project settings. Project: ${JSON.stringify(\n project,\n )}`,\n );\n }\n targetBranch = defaultBranch;\n }\n\n let remoteFiles: RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.allRepositoryTrees(repoID, {\n ref: targetBranch,\n recursive: true,\n path: targetPath ?? undefined,\n });\n } catch (e) {\n ctx.logger.warn(\n `Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n const actions: CommitAction[] =\n ctx.input.commitAction === 'skip'\n ? []\n : (\n (\n await Promise.all(\n fileContents.map(async file => {\n const action = await getFileAction(\n { file, targetPath },\n { repoID, branch: targetBranch! },\n api,\n ctx.logger,\n remoteFiles,\n ctx.input.commitAction,\n );\n return { file, action };\n }),\n )\n ).filter(o => o.action !== 'skip') as {\n file: SerializedFile;\n action: CommitAction['action'];\n }[]\n ).map(({ file, action }) => ({\n action,\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n let createBranch: boolean;\n if (actions.length) {\n createBranch = true;\n } else {\n try {\n await api.Branches.show(repoID, branchName);\n createBranch = false;\n ctx.logger.info(\n `Using existing branch ${branchName} without modification.`,\n );\n } catch (e) {\n createBranch = true;\n }\n }\n if (createBranch) {\n try {\n await api.Branches.create(repoID, branchName, String(targetBranch));\n } catch (e) {\n throw new InputError(\n `The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n if (actions.length) {\n try {\n await api.Commits.create(repoID, branchName, title, actions);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n try {\n let mergeRequest = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,\n assigneeId,\n reviewerIds,\n },\n );\n\n // Because we don't know the code owners before the MR is created, we can't check the approval rules beforehand.\n // Getting the approval rules beforehand is very difficult, especially, because of the inheritance rules for groups.\n // Code owners take a moment to be processed and added to the approval rules after the MR is created.\n\n while (\n mergeRequest.detailed_merge_status === 'preparing' ||\n mergeRequest.detailed_merge_status === 'approvals_syncing' ||\n mergeRequest.detailed_merge_status === 'checking'\n ) {\n mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);\n ctx.logger.info(`${mergeRequest.detailed_merge_status}`);\n }\n\n const approvalRules = await api.MergeRequestApprovals.allApprovalRules(\n repoID,\n {\n mergerequestIId: mergeRequest.iid,\n },\n );\n\n if (approvalRules.length !== 0) {\n const eligibleApprovers = approvalRules\n .filter(rule => rule.eligible_approvers !== undefined)\n .map(rule => {\n return rule.eligible_approvers as SimpleUserSchema[];\n })\n .flat();\n\n const eligibleUserIds = new Set([\n ...eligibleApprovers.map(user => user.id),\n ...(reviewerIds ?? []),\n ]);\n\n mergeRequest = await api.MergeRequests.edit(\n repoID,\n mergeRequest.iid,\n {\n reviewerIds: Array.from(eligibleUserIds),\n },\n );\n }\n\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output(\n 'mergeRequestUrl',\n mergeRequest.web_url ?? mergeRequest.webUrl,\n );\n } catch (e) {\n throw new InputError(\n `Merge request creation failed. ${getErrorMessage(e)}`,\n );\n }\n },\n });\n};\n"],"names":["createHash","path","createTemplateAction","examples","parseRepoUrl","createGitlabApi","getErrorMessage","resolveSafeChildPath","serializeDirectoryContents","InputError"],"mappings":";;;;;;;;;;;;;;AAuCA,SAAS,cAAc,IAA8B,EAAA;AACnD,EAAM,MAAA,IAAA,GAAOA,kBAAW,QAAQ,CAAA;AAChC,EAAK,IAAA,CAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACxB,EAAO,OAAA,IAAA,CAAK,OAAO,KAAK,CAAA;AAC1B;AAEA,eAAe,cACb,QACA,EAAA,MAAA,EACA,KACA,MACA,EAAA,WAAA,EACA,sBAKa,MACqC,EAAA;AAClD,EAAA,IAAI,wBAAwB,MAAQ,EAAA;AAClC,IAAM,MAAA,QAAA,GAAWC,sBAAK,IAAK,CAAA,QAAA,CAAS,cAAc,EAAI,EAAA,QAAA,CAAS,KAAK,IAAI,CAAA;AAExE,IAAA,IAAI,aAAa,IAAK,CAAA,CAAA,UAAA,KAAc,UAAW,CAAA,IAAA,KAAS,QAAQ,CAAG,EAAA;AACjE,MAAI,IAAA;AACF,QAAM,MAAA,UAAA,GAAa,MAAM,GAAA,CAAI,eAAgB,CAAA,IAAA;AAAA,UAC3C,MAAO,CAAA,MAAA;AAAA,UACP,QAAA;AAAA,UACA,MAAO,CAAA;AAAA,SACT;AACA,QAAA,IAAI,aAAc,CAAA,QAAA,CAAS,IAAI,CAAA,KAAM,WAAW,cAAgB,EAAA;AAC9D,UAAO,OAAA,MAAA;AAAA;AACT,eACO,KAAO,EAAA;AACd,QAAO,MAAA,CAAA,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,EACA,IAAK,EAAA;AAER,UAAM,MAAA,eAAA,uBAAsB,GAAI,CAAA;AAAA,YAC9B,GAAG,iBAAA,CAAkB,GAAI,CAAA,CAAA,IAAA,KAAQ,KAAK,EAAE,CAAA;AAAA,YACxC,GAAI,eAAe;AAAC,WACrB,CAAA;AAED,UAAe,YAAA,GAAA,MAAM,IAAI,aAAc,CAAA,IAAA;AAAA,YACrC,MAAA;AAAA,YACA,YAAa,CAAA,GAAA;AAAA,YACb;AAAA,cACE,WAAA,EAAa,KAAM,CAAA,IAAA,CAAK,eAAe;AAAA;AACzC,WACF;AAAA;AAGF,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAI,GAAA,CAAA,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA;AAAA,UACF,iBAAA;AAAA,UACA,YAAA,CAAa,WAAW,YAAa,CAAA;AAAA,SACvC;AAAA,eACO,CAAG,EAAA;AACV,QAAA,MAAM,IAAIG,iBAAA;AAAA,UACR,CAAA,+BAAA,EAAkCH,uBAAgB,CAAA,CAAC,CAAC,CAAA;AAAA,SACtD;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
1
|
+
{"version":3,"file":"gitlabMergeRequest.cjs.js","sources":["../../src/actions/gitlabMergeRequest.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n SerializedFile,\n serializeDirectoryContents,\n} from '@backstage/plugin-scaffolder-node';\nimport {\n Gitlab,\n RepositoryTreeSchema,\n CommitAction,\n SimpleUserSchema,\n ExpandedMergeRequestSchema,\n Camelize,\n} from '@gitbeaker/rest';\nimport path from 'path';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport {\n LoggerService,\n resolveSafeChildPath,\n} from '@backstage/backend-plugin-api';\nimport { createGitlabApi, getErrorMessage } from './helpers';\nimport { examples } from './gitlabMergeRequest.examples';\nimport { createHash } from 'crypto';\n\nfunction computeSha256(file: SerializedFile): string {\n const hash = createHash('sha256');\n hash.update(file.content);\n return hash.digest('hex');\n}\n\nasync function getFileAction(\n fileInfo: { file: SerializedFile; targetPath?: string },\n target: { repoID: string; branch: string },\n api: InstanceType<typeof Gitlab>,\n logger: LoggerService,\n remoteFiles: RepositoryTreeSchema[],\n defaultCommitAction:\n | 'create'\n | 'delete'\n | 'update'\n | 'skip'\n | 'auto' = 'auto',\n): Promise<'create' | 'delete' | 'update' | 'skip'> {\n if (defaultCommitAction === 'auto') {\n const filePath = path.join(fileInfo.targetPath ?? '', fileInfo.file.path);\n\n if (remoteFiles?.some(remoteFile => remoteFile.path === filePath)) {\n try {\n const targetFile = await api.RepositoryFiles.show(\n target.repoID,\n filePath,\n target.branch,\n );\n if (computeSha256(fileInfo.file) === targetFile.content_sha256) {\n return 'skip';\n }\n } catch (error) {\n logger.warn(\n `Unable to retrieve detailed information for remote file ${filePath}`,\n );\n }\n return 'update';\n }\n return 'create';\n }\n return defaultCommitAction;\n}\n\nasync function getReviewersFromApprovalRules(\n api: InstanceType<typeof Gitlab>,\n mergerequestIId: number,\n repoID: string,\n ctx: any,\n): Promise<number[]> {\n try {\n // Because we don't know the code owners before the MR is created, we can't check the approval rules beforehand.\n // Getting the approval rules beforehand is very difficult, especially, because of the inheritance rules for groups.\n // Code owners take a moment to be processed and added to the approval rules after the MR is created.\n\n let mergeRequest:\n | ExpandedMergeRequestSchema\n | Camelize<ExpandedMergeRequestSchema> = await api.MergeRequests.show(\n repoID,\n mergerequestIId,\n );\n\n while (\n mergeRequest.detailed_merge_status === 'preparing' ||\n mergeRequest.detailed_merge_status === 'approvals_syncing' ||\n mergeRequest.detailed_merge_status === 'checking'\n ) {\n mergeRequest = await api.MergeRequests.show(repoID, mergeRequest.iid);\n ctx.logger.info(`${mergeRequest.detailed_merge_status}`);\n }\n\n const approvalRules = await api.MergeRequestApprovals.allApprovalRules(\n repoID,\n {\n mergerequestIId: mergeRequest.iid,\n },\n );\n\n return approvalRules\n .filter(rule => rule.eligible_approvers !== undefined)\n .map(rule => {\n return rule.eligible_approvers as SimpleUserSchema[];\n })\n .flat()\n .map(user => user.id);\n } catch (e) {\n ctx.logger.warn(\n `Failed to retrieve approval rules for MR ${mergerequestIId}: ${getErrorMessage(\n e,\n )}. Proceeding with MR creation without reviewers from approval rules.`,\n );\n return [];\n }\n}\n\n/**\n * Create a new action that creates a gitlab merge request.\n *\n * @public\n */\nexport const createPublishGitlabMergeRequestAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n repoUrl: string;\n title: string;\n description: string;\n branchName: string;\n targetBranchName?: string;\n sourcePath?: string;\n targetPath?: string;\n token?: string;\n commitAction?: 'create' | 'delete' | 'update' | 'skip' | 'auto';\n /** @deprecated projectID passed as query parameters in the repoUrl */\n projectid?: string;\n removeSourceBranch?: boolean;\n assignee?: string;\n reviewers?: string[];\n assignReviewersFromApprovalRules?: boolean;\n }>({\n id: 'publish:gitlab:merge-request',\n examples,\n schema: {\n input: {\n required: ['repoUrl', 'branchName'],\n type: 'object',\n properties: {\n repoUrl: {\n type: 'string',\n title: 'Repository Location',\n description: `\\\nAccepts the format 'gitlab.com?repo=project_name&owner=group_name' where \\\n'project_name' is the repository name and 'group_name' is a group or username`,\n },\n /** @deprecated projectID is passed as query parameters in the repoUrl */\n projectid: {\n type: 'string',\n title: 'projectid',\n description: 'Project ID/Name(slug) of the Gitlab Project',\n },\n title: {\n type: 'string',\n title: 'Merge Request Name',\n description: 'The name for the merge request',\n },\n description: {\n type: 'string',\n title: 'Merge Request Description',\n description: 'The description of the merge request',\n },\n branchName: {\n type: 'string',\n title: 'Source Branch Name',\n description: 'The source branch name of the merge request',\n },\n targetBranchName: {\n type: 'string',\n title: 'Target Branch Name',\n description: 'The target branch name of the merge request',\n },\n sourcePath: {\n type: 'string',\n title: 'Working Subdirectory',\n description: `\\\nSubdirectory of working directory to copy changes from. \\\nFor reasons of backward compatibility, any specified 'targetPath' input will \\\nbe applied in place of an absent/falsy value for this input. \\\nCircumvent this behavior using '.'`,\n },\n targetPath: {\n type: 'string',\n title: 'Repository Subdirectory',\n description: 'Subdirectory of repository to apply changes to',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n commitAction: {\n title: 'Commit action',\n type: 'string',\n enum: ['create', 'update', 'delete', 'auto'],\n description: `\\\nThe action to be used for git commit. Defaults to the custom 'auto' action provided by backstage,\nwhich uses additional API calls in order to detect whether to 'create', 'update' or 'skip' each source file.`,\n },\n removeSourceBranch: {\n title: 'Delete source branch',\n type: 'boolean',\n description:\n 'Option to delete source branch once the MR has been merged. Default: false',\n },\n assignee: {\n title: 'Merge Request Assignee',\n type: 'string',\n description: 'User this merge request will be assigned to',\n },\n reviewers: {\n title: 'Merge Request Reviewers',\n type: 'array',\n items: {\n type: 'string',\n },\n description: 'Users that will be assigned as reviewers',\n },\n assignReviewersFromApprovalRules: {\n title: 'Assign reviewers from approval rules',\n type: 'boolean',\n description:\n 'Automatically assign reviewers from the approval rules of the MR. Includes Codeowners',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n targetBranchName: {\n title: 'Target branch name of the merge request',\n type: 'string',\n },\n projectid: {\n title: 'Gitlab Project id/Name(slug)',\n type: 'string',\n },\n projectPath: {\n title: 'Gitlab Project path',\n type: 'string',\n },\n mergeRequestUrl: {\n title: 'MergeRequest(MR) URL',\n type: 'string',\n description: 'Link to the merge request in GitLab',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n assignee,\n reviewers,\n branchName,\n targetBranchName,\n description,\n repoUrl,\n removeSourceBranch,\n targetPath,\n sourcePath,\n title,\n token,\n } = ctx.input;\n\n const { owner, repo, project } = parseRepoUrl(repoUrl, integrations);\n const repoID = project ? project : `${owner}/${repo}`;\n\n const api = createGitlabApi({\n integrations,\n token,\n repoUrl,\n });\n\n let assigneeId = undefined;\n\n if (assignee !== undefined) {\n try {\n const assigneeUser = await api.Users.all({ username: assignee });\n assigneeId = assigneeUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${assignee}: ${getErrorMessage(\n e,\n )}. Proceeding with MR creation without an assignee.`,\n );\n }\n }\n\n let reviewerIds: number[] | undefined = undefined; // Explicitly set to undefined. Strangely, passing an empty array to the API will result the other options being undefined also being explicity passed to the Gitlab API call (e.g. assigneeId)\n if (reviewers !== undefined) {\n reviewerIds = (\n await Promise.all(\n reviewers.map(async reviewer => {\n try {\n const reviewerUser = await api.Users.all({\n username: reviewer,\n });\n return reviewerUser[0].id;\n } catch (e) {\n ctx.logger.warn(\n `Failed to find gitlab user id for ${reviewer}: ${e}. Proceeding with MR creation without reviewer.`,\n );\n return undefined;\n }\n }),\n )\n ).filter(id => id !== undefined) as number[];\n }\n\n let fileRoot: string;\n if (sourcePath) {\n fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);\n } else if (targetPath) {\n // for backward compatibility\n fileRoot = resolveSafeChildPath(ctx.workspacePath, targetPath);\n } else {\n fileRoot = ctx.workspacePath;\n }\n\n const fileContents = await serializeDirectoryContents(fileRoot, {\n gitignore: true,\n });\n\n let targetBranch = targetBranchName;\n if (!targetBranch) {\n const projects = await api.Projects.show(repoID);\n const defaultBranch = projects.default_branch ?? projects.defaultBranch;\n if (typeof defaultBranch !== 'string' || !defaultBranch) {\n throw new InputError(\n `The branch creation failed. Target branch was not provided, and could not find default branch from project settings. Project: ${JSON.stringify(\n project,\n )}`,\n );\n }\n targetBranch = defaultBranch;\n }\n\n let remoteFiles: RepositoryTreeSchema[] = [];\n if ((ctx.input.commitAction ?? 'auto') === 'auto') {\n try {\n remoteFiles = await api.Repositories.allRepositoryTrees(repoID, {\n ref: targetBranch,\n recursive: true,\n path: targetPath ?? undefined,\n });\n } catch (e) {\n ctx.logger.warn(\n `Could not retrieve the list of files for ${repoID} (branch: ${targetBranch}) : ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n const actions: CommitAction[] =\n ctx.input.commitAction === 'skip'\n ? []\n : (\n (\n await Promise.all(\n fileContents.map(async file => {\n const action = await getFileAction(\n { file, targetPath },\n { repoID, branch: targetBranch! },\n api,\n ctx.logger,\n remoteFiles,\n ctx.input.commitAction,\n );\n return { file, action };\n }),\n )\n ).filter(o => o.action !== 'skip') as {\n file: SerializedFile;\n action: CommitAction['action'];\n }[]\n ).map(({ file, action }) => ({\n action,\n filePath: targetPath\n ? path.posix.join(targetPath, file.path)\n : file.path,\n encoding: 'base64',\n content: file.content.toString('base64'),\n execute_filemode: file.executable,\n }));\n\n let createBranch: boolean;\n if (actions.length) {\n createBranch = true;\n } else {\n try {\n await api.Branches.show(repoID, branchName);\n createBranch = false;\n ctx.logger.info(\n `Using existing branch ${branchName} without modification.`,\n );\n } catch (e) {\n createBranch = true;\n }\n }\n if (createBranch) {\n try {\n await api.Branches.create(repoID, branchName, String(targetBranch));\n } catch (e) {\n throw new InputError(\n `The branch creation failed. Please check that your repo does not already contain a branch named '${branchName}'. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n if (actions.length) {\n try {\n await api.Commits.create(repoID, branchName, title, actions);\n } catch (e) {\n throw new InputError(\n `Committing the changes to ${branchName} failed. Please check that none of the files created by the template already exists. ${getErrorMessage(\n e,\n )}`,\n );\n }\n }\n try {\n let mergeRequest = await api.MergeRequests.create(\n repoID,\n branchName,\n String(targetBranch),\n title,\n {\n description,\n removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,\n assigneeId,\n reviewerIds,\n },\n );\n\n if (ctx.input.assignReviewersFromApprovalRules) {\n try {\n const reviewersFromApprovalRules =\n await getReviewersFromApprovalRules(\n api,\n mergeRequest.iid,\n repoID,\n ctx,\n );\n if (reviewersFromApprovalRules.length > 0) {\n const eligibleUserIds = new Set([\n ...reviewersFromApprovalRules,\n ...(reviewerIds ?? []),\n ]);\n\n mergeRequest = await api.MergeRequests.edit(\n repoID,\n mergeRequest.iid,\n {\n reviewerIds: Array.from(eligibleUserIds),\n },\n );\n }\n } catch (e) {\n ctx.logger.warn(\n `Failed to assign reviewers from approval rules: ${getErrorMessage(\n e,\n )}.`,\n );\n }\n }\n ctx.output('projectid', repoID);\n ctx.output('targetBranchName', targetBranch);\n ctx.output('projectPath', repoID);\n ctx.output(\n 'mergeRequestUrl',\n mergeRequest.web_url ?? mergeRequest.webUrl,\n );\n } catch (e) {\n throw new InputError(\n `Merge request creation failed. ${getErrorMessage(e)}`,\n );\n }\n },\n });\n};\n"],"names":["createHash","path","getErrorMessage","createTemplateAction","examples","parseRepoUrl","createGitlabApi","resolveSafeChildPath","serializeDirectoryContents","InputError"],"mappings":";;;;;;;;;;;;;;AAyCA,SAAS,cAAc,IAA8B,EAAA;AACnD,EAAM,MAAA,IAAA,GAAOA,kBAAW,QAAQ,CAAA;AAChC,EAAK,IAAA,CAAA,MAAA,CAAO,KAAK,OAAO,CAAA;AACxB,EAAO,OAAA,IAAA,CAAK,OAAO,KAAK,CAAA;AAC1B;AAEA,eAAe,cACb,QACA,EAAA,MAAA,EACA,KACA,MACA,EAAA,WAAA,EACA,sBAKa,MACqC,EAAA;AAClD,EAAA,IAAI,wBAAwB,MAAQ,EAAA;AAClC,IAAM,MAAA,QAAA,GAAWC,sBAAK,IAAK,CAAA,QAAA,CAAS,cAAc,EAAI,EAAA,QAAA,CAAS,KAAK,IAAI,CAAA;AAExE,IAAA,IAAI,aAAa,IAAK,CAAA,CAAA,UAAA,KAA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AAAC,eACrB,CAAA;AAED,cAAe,YAAA,GAAA,MAAM,IAAI,aAAc,CAAA,IAAA;AAAA,gBACrC,MAAA;AAAA,gBACA,YAAa,CAAA,GAAA;AAAA,gBACb;AAAA,kBACE,WAAA,EAAa,KAAM,CAAA,IAAA,CAAK,eAAe;AAAA;AACzC,eACF;AAAA;AACF,mBACO,CAAG,EAAA;AACV,YAAA,GAAA,CAAI,MAAO,CAAA,IAAA;AAAA,cACT,CAAmD,gDAAA,EAAAA,uBAAA;AAAA,gBACjD;AAAA,eACD,CAAA,CAAA;AAAA,aACH;AAAA;AACF;AAEF,QAAI,GAAA,CAAA,MAAA,CAAO,aAAa,MAAM,CAAA;AAC9B,QAAI,GAAA,CAAA,MAAA,CAAO,oBAAoB,YAAY,CAAA;AAC3C,QAAI,GAAA,CAAA,MAAA,CAAO,eAAe,MAAM,CAAA;AAChC,QAAI,GAAA,CAAA,MAAA;AAAA,UACF,iBAAA;AAAA,UACA,YAAA,CAAa,WAAW,YAAa,CAAA;AAAA,SACvC;AAAA,eACO,CAAG,EAAA;AACV,QAAA,MAAM,IAAIO,iBAAA;AAAA,UACR,CAAA,+BAAA,EAAkCP,uBAAgB,CAAA,CAAC,CAAC,CAAA;AAAA,SACtD;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -54,6 +54,10 @@ const createGitlabProjectMigrateAction = (options) => {
|
|
|
54
54
|
importedRepoUrl: {
|
|
55
55
|
title: "URL to the newly imported repo",
|
|
56
56
|
type: "string"
|
|
57
|
+
},
|
|
58
|
+
migrationId: {
|
|
59
|
+
title: "Id of the migration that imports the project",
|
|
60
|
+
type: "number"
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
@@ -94,17 +98,21 @@ const createGitlabProjectMigrateAction = (options) => {
|
|
|
94
98
|
access_token: sourceAccessToken
|
|
95
99
|
};
|
|
96
100
|
try {
|
|
97
|
-
await api.Migrations.create(
|
|
101
|
+
const { id: migrationId } = await api.Migrations.create(
|
|
102
|
+
sourceConfig,
|
|
103
|
+
migrationEntity
|
|
104
|
+
);
|
|
105
|
+
ctx.output(
|
|
106
|
+
"importedRepoUrl",
|
|
107
|
+
`${destinationHost}/${destinationNamespace}/${destinationSlug}`
|
|
108
|
+
);
|
|
109
|
+
ctx.output("migrationId", migrationId);
|
|
98
110
|
} catch (e) {
|
|
99
111
|
throw new errors.InputError(
|
|
100
112
|
`Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.
|
|
101
113
|
Error: ${e}`
|
|
102
114
|
);
|
|
103
115
|
}
|
|
104
|
-
ctx.output(
|
|
105
|
-
"importedRepoUrl",
|
|
106
|
-
`${destinationHost}/${destinationNamespace}/${destinationSlug}`
|
|
107
|
-
);
|
|
108
116
|
}
|
|
109
117
|
});
|
|
110
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n await api.Migrations.create(sourceConfig,
|
|
1
|
+
{"version":3,"file":"gitlabProjectMigrate.cjs.js","sources":["../../src/actions/gitlabProjectMigrate.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createTemplateAction,\n parseRepoUrl,\n} from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { InputError } from '@backstage/errors';\nimport { createGitlabApi } from './helpers';\nimport { examples } from './gitlabRepoPush.examples';\nimport { MigrationEntityOptions } from '@gitbeaker/rest';\n\n/**\n * Create a new action that imports a gitlab project into another gitlab project (potentially from another gitlab instance).\n *\n * @public\n */\nexport const createGitlabProjectMigrateAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction<{\n destinationAccessToken: string;\n destinationUrl: string;\n sourceAccessToken: string;\n sourceFullPath: string;\n sourceUrl: string;\n }>({\n id: 'gitlab:group:migrate',\n examples,\n schema: {\n input: {\n required: [\n 'destinationAccessToken',\n 'destinationUrl',\n 'sourceAccessToken',\n 'sourceFullPath',\n 'sourceUrl',\n ],\n type: 'object',\n properties: {\n destinationAccessToken: {\n type: 'string',\n title: 'Target Repository Access Token',\n description: `The token to use for authorization to the target GitLab'`,\n },\n destinationUrl: {\n type: 'string',\n title: 'Target Project Location',\n description: `Accepts the format 'gitlab.com?repo=project_name&owner=group_name' where 'project_name' is the repository name and 'group_name' is a group or username`,\n },\n sourceAccessToken: {\n type: 'string',\n title: 'Source Group Access Token',\n description: `The token to use for authorization to the source GitLab'`,\n },\n sourceFullPath: {\n type: 'string',\n title: 'Group Full Path',\n description:\n 'Full path to the project in the source Gitlab instance',\n },\n sourceUrl: {\n type: 'string',\n title: 'Source URL Location',\n description: `Accepts the format 'https://gitlab.com/'`,\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n importedRepoUrl: {\n title: 'URL to the newly imported repo',\n type: 'string',\n },\n migrationId: {\n title: 'Id of the migration that imports the project',\n type: 'number',\n },\n },\n },\n },\n\n async handler(ctx) {\n const {\n destinationAccessToken,\n destinationUrl,\n sourceAccessToken,\n sourceFullPath,\n sourceUrl,\n } = ctx.input;\n\n const {\n host: destinationHost,\n repo: destinationSlug,\n owner: destinationNamespace,\n } = parseRepoUrl(destinationUrl, integrations);\n\n if (!destinationNamespace) {\n throw new InputError(\n `Failed to determine target repository to migrate to. Make sure destinationUrl matches the format 'gitlab.myorg.com?repo=project_name&owner=group_name'`,\n );\n }\n\n const api = createGitlabApi({\n integrations,\n token: destinationAccessToken,\n repoUrl: destinationUrl,\n });\n\n const migrationEntity: MigrationEntityOptions[] = [\n {\n sourceType: 'project_entity',\n sourceFullPath: sourceFullPath,\n destinationSlug: destinationSlug,\n destinationNamespace: destinationNamespace,\n },\n ];\n\n const sourceConfig = {\n url: sourceUrl,\n access_token: sourceAccessToken,\n };\n\n try {\n const { id: migrationId } = await api.Migrations.create(\n sourceConfig,\n migrationEntity,\n );\n\n ctx.output(\n 'importedRepoUrl',\n `${destinationHost}/${destinationNamespace}/${destinationSlug}`,\n );\n ctx.output('migrationId', migrationId);\n } catch (e: any) {\n throw new InputError(\n `Failed to transfer repo ${sourceFullPath}. Make sure that ${sourceFullPath} exists in ${sourceUrl}, and token has enough rights.\\nError: ${e}`,\n );\n }\n },\n });\n};\n"],"names":["createTemplateAction","examples","parseRepoUrl","InputError","createGitlabApi"],"mappings":";;;;;;;AA+Ba,MAAA,gCAAA,GAAmC,CAAC,OAE3C,K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A,EAAA,cAAc,CAAoB,iBAAA,EAAA,cAAc,cAAc,SAAS,CAAA;AAAA,OAAA,EAA0C,CAAC,CAAA;AAAA,SAC/I;AAAA;AACF;AACF,GACD,CAAA;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete.cjs.js","sources":["../../src/autocomplete/autocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getClient } from '../util';\n\nexport function createHandleAutocompleteRequest(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n return async function handleAutocompleteRequest({\n resource,\n token,\n context,\n }: {\n resource: string;\n token: string;\n context: Record<string, string>;\n }): Promise<{\n results: {\n title?: string;\n id: string;\n }[];\n }> {\n const { integrations } = options;\n const client = getClient({\n host: context.host ?? 'gitlab.com',\n integrations,\n token,\n });\n\n switch (resource) {\n case 'groups': {\n let groups: any[] = [];\n let page = 1;\n const perPage = 100;\n let response = [];\n let continueFetch = true;\n while (continueFetch) {\n response = await client.Groups.all({\n pagination: 'offset',\n page,\n perPage,\n });\n\n groups = groups.concat(response);\n if (response.length < perPage) continueFetch = false;\n page++;\n }\n\n const result: {\n results: {\n title: string;\n id: string;\n }[];\n } = {\n results: groups.map(group => ({\n title: group.full_path,\n id: group.id.toString(),\n })),\n };\n // append also user context\n const user = await client.Users.showCurrentUser();\n result.results.push({\n title: user.username,\n id: user.id.toString(),\n });\n\n return result;\n }\n case 'repositories': {\n if (!context.id)\n throw new InputError('Missing groupId and userId context parameter');\n\n let response;\n if (\n context.id === (await client.Users.showCurrentUser())?.id.toString()\n ) {\n response = await client.Users.allProjects(context.id);\n } else {\n response = await client.Groups.allProjects(context.id);\n }\n\n return {\n results: response.map(project => ({\n title: project.name.trim(),\n id: project.
|
|
1
|
+
{"version":3,"file":"autocomplete.cjs.js","sources":["../../src/autocomplete/autocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { getClient } from '../util';\n\nexport function createHandleAutocompleteRequest(options: {\n integrations: ScmIntegrationRegistry;\n}) {\n return async function handleAutocompleteRequest({\n resource,\n token,\n context,\n }: {\n resource: string;\n token: string;\n context: Record<string, string>;\n }): Promise<{\n results: {\n title?: string;\n id: string;\n }[];\n }> {\n const { integrations } = options;\n const client = getClient({\n host: context.host ?? 'gitlab.com',\n integrations,\n token,\n });\n\n switch (resource) {\n case 'groups': {\n let groups: any[] = [];\n let page = 1;\n const perPage = 100;\n let response = [];\n let continueFetch = true;\n while (continueFetch) {\n response = await client.Groups.all({\n pagination: 'offset',\n page,\n perPage,\n });\n\n groups = groups.concat(response);\n if (response.length < perPage) continueFetch = false;\n page++;\n }\n\n const result: {\n results: {\n title: string;\n id: string;\n }[];\n } = {\n results: groups.map(group => ({\n title: group.full_path,\n id: group.id.toString(),\n })),\n };\n // append also user context\n const user = await client.Users.showCurrentUser();\n result.results.push({\n title: user.username,\n id: user.id.toString(),\n });\n\n return result;\n }\n case 'repositories': {\n if (!context.id)\n throw new InputError('Missing groupId and userId context parameter');\n\n let response;\n if (\n context.id === (await client.Users.showCurrentUser())?.id.toString()\n ) {\n response = await client.Users.allProjects(context.id);\n } else {\n response = await client.Groups.allProjects(context.id);\n }\n\n return {\n results: response.map(project => ({\n title: project.name.trim(),\n id: project.path,\n })),\n };\n }\n default:\n throw new InputError(`Invalid resource: ${resource}`);\n }\n };\n}\n"],"names":["getClient","InputError"],"mappings":";;;;;AAoBO,SAAS,gCAAgC,OAE7C,EAAA;AACD,EAAA,OAAO,eAAe,yBAA0B,CAAA;AAAA,IAC9C,QAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GAUC,EAAA;AACD,IAAM,MAAA,EAAE,cAAiB,GAAA,OAAA;AACzB,IAAA,MAAM,SAASA,cAAU,CAAA;AAAA,MACvB,IAAA,EAAM,QAAQ,IAAQ,IAAA,YAAA;AAAA,MACtB,YAAA;AAAA,MACA;AAAA,KACD,CAAA;AAED,IAAA,QAAQ,QAAU;AAAA,MAChB,KAAK,QAAU,EAAA;AACb,QAAA,IAAI,SAAgB,EAAC;AACrB,QAAA,IAAI,IAAO,GAAA,CAAA;AACX,QAAA,MAAM,OAAU,GAAA,GAAA;AAChB,QAAA,IAAI,WAAW,EAAC;AAChB,QAAA,IAAI,aAAgB,GAAA,IAAA;AACpB,QAAA,OAAO,aAAe,EAAA;AACpB,UAAW,QAAA,GAAA,MAAM,MAAO,CAAA,MAAA,CAAO,GAAI,CAAA;AAAA,YACjC,UAAY,EAAA,QAAA;AAAA,YACZ,IAAA;AAAA,YACA;AAAA,WACD,CAAA;AAED,UAAS,MAAA,GAAA,MAAA,CAAO,OAAO,QAAQ,CAAA;AAC/B,UAAI,IAAA,QAAA,CAAS,MAAS,GAAA,OAAA,EAAyB,aAAA,GAAA,KAAA;AAC/C,UAAA,IAAA,EAAA;AAAA;AAGF,QAAA,MAAM,MAKF,GAAA;AAAA,UACF,OAAA,EAAS,MAAO,CAAA,GAAA,CAAI,CAAU,KAAA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
|
|
18
18
|
defaultBranch?: string | undefined;
|
|
19
19
|
/** @deprecated in favour of settings.visibility field */
|
|
20
20
|
repoVisibility?: "internal" | "private" | "public" | undefined;
|
|
21
|
-
sourcePath?: string | undefined;
|
|
21
|
+
sourcePath?: string | boolean | undefined;
|
|
22
|
+
skipExisting?: boolean | undefined;
|
|
22
23
|
token?: string | undefined;
|
|
23
24
|
gitCommitMessage?: string | undefined;
|
|
24
25
|
gitAuthorName?: string | undefined;
|
|
@@ -187,6 +188,7 @@ declare const createPublishGitlabMergeRequestAction: (options: {
|
|
|
187
188
|
removeSourceBranch?: boolean | undefined;
|
|
188
189
|
assignee?: string | undefined;
|
|
189
190
|
reviewers?: string[] | undefined;
|
|
191
|
+
assignReviewersFromApprovalRules?: boolean | undefined;
|
|
190
192
|
}, _backstage_types.JsonObject>;
|
|
191
193
|
|
|
192
194
|
/**
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-scaffolder-backend-module-gitlab",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-next.2",
|
|
4
4
|
"backstage": {
|
|
5
5
|
"role": "backend-plugin-module",
|
|
6
6
|
"pluginId": "scaffolder",
|
|
7
|
-
"pluginPackage": "@backstage/plugin-scaffolder-backend"
|
|
7
|
+
"pluginPackage": "@backstage/plugin-scaffolder-backend",
|
|
8
|
+
"features": {
|
|
9
|
+
".": "@backstage/BackendFeature"
|
|
10
|
+
}
|
|
8
11
|
},
|
|
9
12
|
"publishConfig": {
|
|
10
13
|
"access": "public"
|
|
@@ -51,11 +54,11 @@
|
|
|
51
54
|
},
|
|
52
55
|
"dependencies": {
|
|
53
56
|
"@backstage/backend-common": "^0.25.0",
|
|
54
|
-
"@backstage/backend-plugin-api": "1.2.0-next.
|
|
57
|
+
"@backstage/backend-plugin-api": "1.2.0-next.1",
|
|
55
58
|
"@backstage/config": "1.3.2",
|
|
56
59
|
"@backstage/errors": "1.2.7",
|
|
57
60
|
"@backstage/integration": "1.16.1",
|
|
58
|
-
"@backstage/plugin-scaffolder-node": "0.7.0-next.
|
|
61
|
+
"@backstage/plugin-scaffolder-node": "0.7.0-next.1",
|
|
59
62
|
"@gitbeaker/rest": "^41.2.0",
|
|
60
63
|
"luxon": "^3.0.0",
|
|
61
64
|
"winston": "^3.2.1",
|
|
@@ -63,9 +66,9 @@
|
|
|
63
66
|
"zod": "^3.22.4"
|
|
64
67
|
},
|
|
65
68
|
"devDependencies": {
|
|
66
|
-
"@backstage/backend-test-utils": "1.3.0-next.
|
|
67
|
-
"@backstage/cli": "0.30.0-next.
|
|
68
|
-
"@backstage/core-app-api": "1.15.
|
|
69
|
-
"@backstage/plugin-scaffolder-node-test-utils": "0.1.19-next.
|
|
69
|
+
"@backstage/backend-test-utils": "1.3.0-next.2",
|
|
70
|
+
"@backstage/cli": "0.30.0-next.2",
|
|
71
|
+
"@backstage/core-app-api": "1.15.5-next.0",
|
|
72
|
+
"@backstage/plugin-scaffolder-node-test-utils": "0.1.19-next.2"
|
|
70
73
|
}
|
|
71
74
|
}
|