fix gitlab search with multiple globs

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2025-11-04 10:58:32 +01:00
parent 2fa87f6d24
commit 91ab2eb9b7
3 changed files with 20 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
Fix a bug in the Gitlab URL reader where `search` did not handle multiple globs
@@ -670,6 +670,17 @@ describe('GitlabUrlReader', () => {
);
});
it('works when there are multiple globs', async () => {
const result = await gitlabProcessor.search(
'https://gitlab.com/backstage/mock/tree/main/**/docs/**/index.*',
);
expect(result.etag).toBe('sha123abc');
expect(result.files.length).toBe(1);
expect(result.files[0].url).toBe(
'https://gitlab.com/backstage/mock/tree/main/docs/index.md',
);
});
it('works for the naive case', async () => {
const result = await gitlabProcessor.search(
'https://gitlab.com/backstage/mock/tree/main/**/index.*',
@@ -319,14 +319,10 @@ export class GitlabUrlReader implements UrlReaderService {
*/
private getStaticPart(globPattern: string) {
const segments = globPattern.split('/');
let i = segments.length;
while (
i > 0 &&
new Minimatch(segments.slice(0, i).join('/')).match(globPattern)
) {
i--;
}
return segments.slice(0, i).join('/');
const globIndex = segments.findIndex(segment => segment.match(/[*?]/));
return globIndex === -1
? globPattern
: segments.slice(0, globIndex).join('/');
}
toString() {