PR feedback

* Use only the ID returned from the group create method, to avoid
  unnecessary cast
* Better changeset

Signed-off-by: Thorsten Lanfer <tlanfer@gmail.com>
This commit is contained in:
Thorsten Lanfer
2024-09-18 21:42:12 +02:00
parent e769ae6deb
commit 2834f98cfa
2 changed files with 16 additions and 14 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@backstage/plugin-scaffolder-backend-module-gitlab': patch
---
Allow the usage of oauth tokens for the gitlab:group:ensureExists action
Updated `gitlab:group:ensureExists` action to instead use oauth client.
@@ -66,7 +66,7 @@ export const createGitlabGroupEnsureExistsAction = (options: {
const api = getClient({ host, integrations, token });
let currentPath: string | null = null;
let parent: GroupSchema | null = null;
let parentId: number | null = null;
for (const pathElement of path) {
const fullPath: string = currentPath
? `${currentPath}/${pathElement}`
@@ -79,22 +79,24 @@ export const createGitlabGroupEnsureExistsAction = (options: {
);
if (!subGroup) {
ctx.logger.info(`creating missing group ${fullPath}`);
parent = (await api.Groups.create(
pathElement,
pathElement,
parent
? {
parentId: parent.id,
}
: {},
)) as GroupSchema;
parentId = (
await api.Groups.create(
pathElement,
pathElement,
parentId
? {
parentId: parentId,
}
: {},
)
)?.id;
} else {
parent = subGroup;
parentId = subGroup.id;
}
currentPath = fullPath;
}
if (parent !== null) {
ctx.output('groupId', parent?.id);
if (parentId !== null) {
ctx.output('groupId', parentId);
}
},
});