From a0419a6c6ca82394d02d19bad88a4b46579f06cb Mon Sep 17 00:00:00 2001 From: Bogdan Nechyporenko Date: Thu, 6 Feb 2025 19:18:45 +0100 Subject: [PATCH] Made gitlab:group:ensureExists action idempotent. Signed-off-by: Bogdan Nechyporenko --- .changeset/beige-cycles-sit.md | 6 ++++ .../src/actions/gitlabGroupEnsureExists.ts | 29 ++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 .changeset/beige-cycles-sit.md diff --git a/.changeset/beige-cycles-sit.md b/.changeset/beige-cycles-sit.md new file mode 100644 index 0000000000..147e984ea3 --- /dev/null +++ b/.changeset/beige-cycles-sit.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-scaffolder-backend-module-gitlab': patch +'@backstage/plugin-scaffolder-node-test-utils': patch +--- + +Made gitlab:group:ensureExists action idempotent diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts index 50ce7a761b..5be5b7c10d 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.ts @@ -90,17 +90,24 @@ export const createGitlabGroupEnsureExistsAction = (options: { ); if (!subGroup) { ctx.logger.info(`creating missing group ${fullPath}`); - parentId = ( - await api.Groups.create( - name, - slug, - parentId - ? { - parentId: parentId, - } - : {}, - ) - )?.id; + + parentId = await ctx.checkpoint({ + key: `ensure.${name}.${slug}.${parentId}`, + // eslint-disable-next-line no-loop-func + fn: async () => { + return ( + await api.Groups.create( + name, + slug, + parentId + ? { + parentId: parentId, + } + : {}, + ) + )?.id; + }, + }); } else { parentId = subGroup.id; }