fix gitlab search with multiple globs
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user