update gitbeaker to support reviewerId's in it's interface (#3498), add reviewer id's with async retrieval

Signed-off-by: Hghtwr <johannes.sonner@outlook.com>
This commit is contained in:
Hghtwr
2024-12-21 21:13:09 +01:00
committed by blam
parent bd585a6b84
commit 27ad9a3446
3 changed files with 47 additions and 5 deletions
+3
View File
@@ -61,4 +61,7 @@ backend.add(import('@backstage/plugin-signals-backend'));
backend.add(import('@backstage/plugin-notifications-backend'));
backend.add(import('./instanceMetadata'));
// backend.add(eventsModuleGitlabWebhook);
backend.add(import('@backstage/plugin-catalog-backend-module-gitlab-org'));
backend.start();
@@ -100,6 +100,7 @@ export const createPublishGitlabMergeRequestAction = (options: {
projectid?: string;
removeSourceBranch?: boolean;
assignee?: string;
reviewers?: string[];
}>({
id: 'publish:gitlab:merge-request',
examples,
@@ -179,6 +180,14 @@ which uses additional API calls in order to detect whether to 'create', 'update'
type: 'string',
description: 'User this merge request will be assigned to',
},
reviewers: {
title: 'Merge Request Reviewers',
type: 'array',
items: {
type: 'string',
},
description: 'Users that will be assigned as reviewers',
},
},
},
output: {
@@ -207,6 +216,7 @@ which uses additional API calls in order to detect whether to 'create', 'update'
async handler(ctx) {
const {
assignee,
reviewers,
branchName,
targetBranchName,
description,
@@ -242,6 +252,23 @@ which uses additional API calls in order to detect whether to 'create', 'update'
}
}
let reviewerIds: number[] | undefined;
if (reviewers !== undefined) {
reviewerIds = await Promise.all(
reviewers.map(async reviewer => {
try {
const reviewerUser = await api.Users.username(reviewer);
return reviewerUser[0].id;
} catch (e) {
ctx.logger.warn(
`Failed to find gitlab user id for ${reviewer}: ${e}. Proceeding with MR creation without reviewer.`,
);
return undefined;
}
}),
);
}
let fileRoot: string;
if (sourcePath) {
fileRoot = resolveSafeChildPath(ctx.workspacePath, sourcePath);
@@ -364,6 +391,7 @@ which uses additional API calls in order to detect whether to 'create', 'update'
description,
removeSourceBranch: removeSourceBranch ? removeSourceBranch : false,
assigneeId,
reviewerIds,
},
).then(mergeRequest => mergeRequest.web_url ?? mergeRequest.webUrl);
ctx.output('projectid', repoID);
+16 -5
View File
@@ -1,6 +1,3 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 6
cacheKey: 8
@@ -6018,7 +6015,7 @@ __metadata:
languageName: unknown
linkType: soft
"@backstage/plugin-catalog-backend-module-gitlab-org@workspace:plugins/catalog-backend-module-gitlab-org":
"@backstage/plugin-catalog-backend-module-gitlab-org@workspace:^, @backstage/plugin-catalog-backend-module-gitlab-org@workspace:plugins/catalog-backend-module-gitlab-org":
version: 0.0.0-use.local
resolution: "@backstage/plugin-catalog-backend-module-gitlab-org@workspace:plugins/catalog-backend-module-gitlab-org"
dependencies:
@@ -7736,7 +7733,9 @@ __metadata:
"@backstage/integration": "workspace:^"
"@backstage/plugin-scaffolder-node": "workspace:^"
"@backstage/plugin-scaffolder-node-test-utils": "workspace:^"
"@gitbeaker/rest": ^41.2.0
"@gitbeaker/core": ^39.28.0
"@gitbeaker/node": ^35.8.0
"@gitbeaker/rest": ^39.25.0
luxon: ^3.0.0
winston: ^3.2.1
yaml: ^2.0.0
@@ -10176,6 +10175,17 @@ __metadata:
languageName: node
linkType: hard
"@gitbeaker/core@npm:^39.28.0, @gitbeaker/core@npm:^39.34.3":
version: 39.34.3
resolution: "@gitbeaker/core@npm:39.34.3"
dependencies:
"@gitbeaker/requester-utils": ^39.34.3
qs: ^6.11.2
xcase: ^2.0.1
checksum: 2b0ccd6137ee717b6f51c51c8f7063b84beeebfdb044574f2257f282864411c4f0932f2619893385f2a86bb4fa342b75be972fd1868640ab4e260f2280cc52b3
languageName: node
linkType: hard
"@gitbeaker/core@npm:^40.6.0":
version: 40.6.0
resolution: "@gitbeaker/core@npm:40.6.0"
@@ -28878,6 +28888,7 @@ __metadata:
"@backstage/plugin-auth-node": "workspace:^"
"@backstage/plugin-catalog-backend": "workspace:^"
"@backstage/plugin-catalog-backend-module-backstage-openapi": "workspace:^"
"@backstage/plugin-catalog-backend-module-gitlab-org": "workspace:^"
"@backstage/plugin-catalog-backend-module-openapi": "workspace:^"
"@backstage/plugin-catalog-backend-module-scaffolder-entity-model": "workspace:^"
"@backstage/plugin-catalog-backend-module-unprocessed": "workspace:^"