Fixed a bug in gitlab:group:ensureExists where repos was always set as the root group.

Signed-off-by: Andreas Berger <andreas@berger-ecommerce.com>
This commit is contained in:
Andreas Berger
2023-07-06 09:08:32 +02:00
parent 06c88a8d30
commit dd367967e2
3 changed files with 15 additions and 8 deletions
+5
View File
@@ -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.
@@ -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',
},
]);
@@ -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<GroupSchema>; // recast since the return type for search is wrong in the gitbeaker typings