From 5559d3f4d4adf21818c2e667139af9afa395d1b1 Mon Sep 17 00:00:00 2001 From: ElaineDeMattosSilvaB Date: Mon, 9 Feb 2026 21:50:50 +0100 Subject: [PATCH 1/3] fix: code search scope from blob to blobs Signed-off-by: ElaineDeMattosSilvaB --- plugins/catalog-backend-module-gitlab/src/lib/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.ts index 4f220deb68..c04585142d 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.ts @@ -185,7 +185,7 @@ export class GitLabClient { `/groups/${encodeURIComponent(options?.group)}/search`, { ...options, - scope: 'blob', + scope: 'blobs', }, ); } From 004ad4389e4f9b4d6764588dd04736b9a94c853b Mon Sep 17 00:00:00 2001 From: ElaineDeMattosSilvaB Date: Mon, 9 Feb 2026 21:52:34 +0100 Subject: [PATCH 2/3] fix: prevent scope from being mixed up again Signed-off-by: ElaineDeMattosSilvaB --- .../src/__testUtils__/handlers.ts | 8 ++- .../src/lib/client.test.ts | 61 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts b/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts index 16adb01c10..e5b9b39ecd 100644 --- a/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts +++ b/plugins/catalog-backend-module-gitlab/src/__testUtils__/handlers.ts @@ -201,7 +201,13 @@ const httpGroupFindByEncodedPathDynamic = all_groups_response.flatMap(group => [ const httpSearchFilesInGroupDynamic = all_groups_response.map(group => { return rest.get( `${apiBaseUrl}/groups/${encodeURIComponent(group.full_path)}/search`, - (_, res, ctx) => { + (req, res, ctx) => { + const scope = req.url.searchParams.get('scope'); + + if (scope !== 'blobs') { + return res(ctx.status(400), ctx.text('400 Bad Request')); + } + const searchResults = projects_with_catalog_info_yaml .filter(project => project.path_with_namespace?.startsWith(group.full_path), diff --git a/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts b/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts index 60974d2d0f..5e10fbffd6 100644 --- a/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts +++ b/plugins/catalog-backend-module-gitlab/src/lib/client.test.ts @@ -280,6 +280,67 @@ describe('GitLabClient', () => { }); }); + describe('listFiles', () => { + it('should call group search API with correct scope parameter', async () => { + const client = new GitLabClient({ + config: readGitLabIntegrationConfig( + new ConfigReader(mock.config_self_managed), + ), + logger: mockServices.logger.mock(), + }); + + const pagedRequestSpy = jest.spyOn(client as any, 'pagedRequest'); + + await client.listFiles({ + group: 'group1', + search: 'filename:catalog-info.yaml', + page: 1, + per_page: 50, + }); + + expect(pagedRequestSpy).toHaveBeenCalledWith( + '/groups/group1/search', + expect.objectContaining({ + group: 'group1', + search: 'filename:catalog-info.yaml', + scope: 'blobs', + page: 1, + per_page: 50, + }), + ); + }); + + it('should return empty items when group is missing', async () => { + const client = new GitLabClient({ + config: readGitLabIntegrationConfig( + new ConfigReader(mock.config_self_managed), + ), + logger: mockServices.logger.mock(), + }); + + const result = await client.listFiles({ + search: 'filename:catalog-info.yaml', + }); + + expect(result.items).toEqual([]); + }); + + it('should return empty items when search is missing', async () => { + const client = new GitLabClient({ + config: readGitLabIntegrationConfig( + new ConfigReader(mock.config_self_managed), + ), + logger: mockServices.logger.mock(), + }); + + const result = await client.listFiles({ + group: 'my-group', + }); + + expect(result.items).toEqual([]); + }); + }); + describe('get gitlab.com users', () => { it('gets all users under group', async () => { const client = new GitLabClient({ From 7e6b5e5e0777c482a9a2dd25d37df2c68dce6c17 Mon Sep 17 00:00:00 2001 From: ElaineDeMattosSilvaB Date: Mon, 9 Feb 2026 21:59:26 +0100 Subject: [PATCH 3/3] fix: add changelog Signed-off-by: ElaineDeMattosSilvaB --- .changeset/small-shirts-lose.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/small-shirts-lose.md diff --git a/.changeset/small-shirts-lose.md b/.changeset/small-shirts-lose.md new file mode 100644 index 0000000000..2fe3d6c414 --- /dev/null +++ b/.changeset/small-shirts-lose.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-gitlab': patch +--- + +Fixed GitLab search API scope parameter from `'blob'` to `'blobs'`, resolving 400 errors in discovery provider.