feat(backend-defaults): use isGlob in GithubUrlReader to match glob patterns

Signed-off-by: Thomas Cardonne <t.cardonne@gmail.com>
This commit is contained in:
Thomas Cardonne
2025-05-08 12:14:05 +02:00
parent 1398391596
commit 1e06afd80c
6 changed files with 26 additions and 2 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/backend-defaults': patch
---
`GithubUrlReader`'s search detects glob-patterns supported by `minimatch`, instead of just detecting
`*` and `?` characters.
For example, this allows to search for patterns like `{C,c}atalog-info.yaml`.
+1 -1
View File
@@ -148,7 +148,7 @@ If you do so, `default` will be used as provider ID.
- **`catalogPath`** _(optional)_:
Default: `/catalog-info.yaml`.
Path where to look for `catalog-info.yaml` files.
You can use wildcards - `*` or `**` - to search the path and/or the filename.
You can use wildcards - `*`, `**` or a glob pattern supported by [`minimatch`](https://github.com/isaacs/minimatch) - to search the path and/or the filename.
Wildcards cannot be used if the `validateLocationsExist` option is set to `true`.
- **`filters`** _(optional)_:
- **`branch`** _(optional)_:
+2
View File
@@ -163,6 +163,7 @@
"fs-extra": "^11.2.0",
"git-url-parse": "^15.0.0",
"helmet": "^6.0.0",
"is-glob": "^4.0.3",
"jose": "^5.0.0",
"keyv": "^5.2.1",
"knex": "^3.0.0",
@@ -200,6 +201,7 @@
"@types/compression": "^1.7.5",
"@types/concat-stream": "^2.0.0",
"@types/http-errors": "^2.0.0",
"@types/is-glob": "^4.0.2",
"@types/node-forge": "^1.3.0",
"@types/pg-format": "^1.0.5",
"@types/yauzl": "^2.10.0",
@@ -923,6 +923,17 @@ describe('GithubUrlReader', () => {
await expect(r5.files[0].content()).resolves.toEqual(
Buffer.from('# Test\n'),
);
const r6 = await reader.search(
`${baseUrl}/backstage/mock/tree/main/{M,m}kdocs.yml`,
);
expect(r6.files.length).toBe(1);
expect(r6.files[0].url).toBe(
`${baseUrl}/backstage/mock/tree/main/mkdocs.yml`,
);
await expect(r6.files[0].content()).resolves.toEqual(
Buffer.from('site_name: Test\n'),
);
}
// eslint-disable-next-line jest/expect-expect
@@ -45,6 +45,7 @@ import {
import { ReadTreeResponseFactory, ReaderFactory } from './types';
import { ReadUrlResponseFactory } from './ReadUrlResponseFactory';
import { parseLastModified } from './util';
import isGlob from 'is-glob';
export type GhRepoResponse =
RestEndpointMethodTypes['repos']['get']['response']['data'];
@@ -186,7 +187,7 @@ export class GithubUrlReader implements UrlReaderService {
const { filepath } = parseGitUrl(url);
// If it's a direct URL we use readUrl instead
if (!filepath?.match(/[*?]/)) {
if (!isGlob(filepath)) {
try {
const data = await this.readUrl(url, options);
+2
View File
@@ -3587,6 +3587,7 @@ __metadata:
"@types/cors": "npm:^2.8.6"
"@types/express": "npm:^4.17.6"
"@types/http-errors": "npm:^2.0.0"
"@types/is-glob": "npm:^4.0.2"
"@types/node-forge": "npm:^1.3.0"
"@types/pg-format": "npm:^1.0.5"
"@types/yauzl": "npm:^2.10.0"
@@ -3605,6 +3606,7 @@ __metadata:
git-url-parse: "npm:^15.0.0"
helmet: "npm:^6.0.0"
http-errors: "npm:^2.0.0"
is-glob: "npm:^4.0.3"
jose: "npm:^5.0.0"
keyv: "npm:^5.2.1"
knex: "npm:^3.0.0"