From 2834f98cfadd7eda5af9c1df9315fd03e9c80078 Mon Sep 17 00:00:00 2001 From: Thorsten Lanfer Date: Wed, 18 Sep 2024 21:42:12 +0200 Subject: [PATCH] PR feedback * Use only the ID returned from the group create method, to avoid unnecessary cast * Better changeset Signed-off-by: Thorsten Lanfer --- .changeset/sour-phones-fix.md | 2 +- .../src/actions/gitlabGroupEnsureExists.ts | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.changeset/sour-phones-fix.md b/.changeset/sour-phones-fix.md index 41d35a0c21..d2519f2ef5 100644 --- a/.changeset/sour-phones-fix.md +++ b/.changeset/sour-phones-fix.md @@ -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. diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts index 0a270fc167..41bc5755c9 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts @@ -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); } }, });