From 4db039ad7fb83d4545ba1e971b9c4378d99e95f6 Mon Sep 17 00:00:00 2001 From: Hghtwr Date: Thu, 13 Feb 2025 20:18:51 +0100 Subject: [PATCH 1/3] fix: encode group path for getGroupByPath (#28826) Signed-off-by: Hghtwr --- .changeset/sour-kids-nail.md | 5 +++++ plugins/catalog-backend-module-gitlab/src/lib/client.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/sour-kids-nail.md diff --git a/.changeset/sour-kids-nail.md b/.changeset/sour-kids-nail.md new file mode 100644 index 0000000000..591f13123a --- /dev/null +++ b/.changeset/sour-kids-nail.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': patch +--- + +Fix GitlabOrgDiscoveryEntityProvider group path not being encoded causing 404 when using a subgroup in config.group diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.ts index 561f38634b..f5ed760b21 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.ts @@ -174,7 +174,10 @@ export class GitLabClient { groupPath: string, options?: CommonListOptions, ): Promise { - return this.nonPagedRequest(`/groups/${groupPath}`, options); + return this.nonPagedRequest( + `/groups/${encodeURIComponent(groupPath)}`, + options, + ); } async listDescendantGroups( From 15dc2abaadc7d1578a12d411d0f3e3f22508810a Mon Sep 17 00:00:00 2001 From: Hghtwr Date: Thu, 13 Feb 2025 20:32:35 +0100 Subject: [PATCH 2/3] fix: adopt tests to use encoded url for group full_path Signed-off-by: Hghtwr --- .../src/__testUtils__/handlers.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts b/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts index 041aa5b835..9ffb43a53d 100644 --- a/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts +++ b/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts @@ -139,17 +139,27 @@ const httpHandlers = [ // https://docs.gitlab.com/ee/api/groups.html#list-group-details supports encoded path and id const httpGroupFindByEncodedPathDynamic = all_groups_response.flatMap(group => [ // Handler for apiBaseUrl - rest.get(`${apiBaseUrl}/groups/${group.full_path}`, (_, res, ctx) => { - return res( - ctx.json(all_groups_response.find(g => g.full_path === group.full_path)), - ); - }), + rest.get( + `${apiBaseUrl}/groups/${encodeURIComponent(group.full_path)}`, + (_, res, ctx) => { + return res( + ctx.json( + all_groups_response.find(g => g.full_path === group.full_path), + ), + ); + }, + ), // Handler for apiSaaSBaseUrl - rest.get(`${apiBaseUrlSaas}/groups/${group.full_path}`, (_, res, ctx) => { - return res( - ctx.json(all_groups_response.find(g => g.full_path === group.full_path)), - ); - }), + rest.get( + `${apiBaseUrlSaas}/groups/${encodeURIComponent(group.full_path)}`, + (_, res, ctx) => { + return res( + ctx.json( + all_groups_response.find(g => g.full_path === group.full_path), + ), + ); + }, + ), ]); const httpGroupFindByIdDynamic = all_groups_response.map(group => { From 0b1d5b17cd7fa4458b367bb210a29bc6174ec176 Mon Sep 17 00:00:00 2001 From: Vincenzo Scamporlino Date: Mon, 17 Feb 2025 13:31:27 +0100 Subject: [PATCH 3/3] Update .changeset/sour-kids-nail.md Signed-off-by: Vincenzo Scamporlino --- .changeset/sour-kids-nail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/sour-kids-nail.md b/.changeset/sour-kids-nail.md index 591f13123a..769a4602c4 100644 --- a/.changeset/sour-kids-nail.md +++ b/.changeset/sour-kids-nail.md @@ -2,4 +2,4 @@ '@backstage/plugin-catalog-backend-module-gitlab': patch --- -Fix GitlabOrgDiscoveryEntityProvider group path not being encoded causing 404 when using a subgroup in config.group +Fix `GitlabOrgDiscoveryEntityProvider` group path not being encoded causing 404 when using a subgroup in `config.group`