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
@@ -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);