diff --git a/.changeset/wicked-ears-scream.md b/.changeset/wicked-ears-scream.md new file mode 100644 index 0000000000..44bb0d92d6 --- /dev/null +++ b/.changeset/wicked-ears-scream.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-gitlab': patch +--- + +Fixed a bug in `gitlab:group:ensureExists` where `repos` was always set as the root group. diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.test.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.test.ts index 3c67477ed5..72dcddc83d 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.test.ts @@ -51,17 +51,17 @@ describe('gitlab:group:ensureExists', () => { mockGitlabClient.Groups.search.mockResolvedValue([ { id: 1, - full_path: 'repos/bar', + full_path: 'bar', }, { id: 2, - full_path: 'repos/foo', + full_path: 'foo', }, ]); mockGitlabClient.Groups.create.mockResolvedValue({ id: 3, - full_path: 'repos/foo/bar', + full_path: 'foo/bar', }); const config = new ConfigReader({ @@ -98,15 +98,15 @@ describe('gitlab:group:ensureExists', () => { mockGitlabClient.Groups.search.mockResolvedValue([ { id: 1, - full_path: 'repos/bar', + full_path: 'bar', }, { id: 2, - full_path: 'repos/foo', + full_path: 'foo', }, { id: 42, - full_path: 'repos/foo/bar', + full_path: 'foo/bar', }, ]); diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts index 169cdb5b25..74d3805254 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabGroupEnsureExistsAction.ts @@ -66,10 +66,12 @@ export const createGitlabGroupEnsureExistsAction = (options: { token: token, }); - let currentPath: string = 'repos'; + let currentPath: string | null = null; let parent: GroupSchema | null = null; for (const pathElement of path) { - const fullPath = `${currentPath}/${pathElement}`; + const fullPath: string = currentPath + ? `${currentPath}/${pathElement}` + : pathElement; const result = (await api.Groups.search( fullPath, )) as unknown as Array; // recast since the return type for search is wrong in the gitbeaker typings