diff --git a/.changeset/tall-mugs-press.md b/.changeset/tall-mugs-press.md new file mode 100644 index 0000000000..2a0053e95d --- /dev/null +++ b/.changeset/tall-mugs-press.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Improved support for wildcards in `catalogPath` diff --git a/docs/integrations/github/discovery.md b/docs/integrations/github/discovery.md index 3b49644613..339a1e2ca3 100644 --- a/docs/integrations/github/discovery.md +++ b/docs/integrations/github/discovery.md @@ -74,6 +74,12 @@ catalog: filters: # optional filters branch: 'develop' # optional string repository: '.*' # optional Regex + wildcardProviderId: + organization: 'new-org' # string + catalogPath: '/groups/**/*.yaml' # this will search all folders for files that end in .yaml + filters: # optional filters + branch: 'develop' # optional string + repository: '.*' # optional Regex ``` This provider supports multiple organizations via unique provider IDs. @@ -84,7 +90,7 @@ This provider supports multiple organizations via unique provider IDs. - **`catalogPath`** _(optional)_: Default: `/catalog-info.yaml`. Path where to look for `catalog-info.yaml` files. - When started with `/`, it is an absolute path from the repo root. + You can use wildcards - `*` or `**` - to search the path and/or the filename - **filters** _(optional)_: - **branch** _(optional)_: String used to filter results based on the branch name. diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts b/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts index 0bda258b6e..a40ab4eb5c 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.test.ts @@ -153,7 +153,7 @@ describe('GitHubEntityProvider', () => { expect(taskDef.id).toEqual('github-provider:myProvider:refresh'); await (taskDef.fn as () => Promise)(); - const url = `https://github.com/test-org/test-repo/blob/main/catalog-custom.yaml`; + const url = `https://github.com/test-org/test-repo/blob/main/custom/path/catalog-custom.yaml`; const expectedEntities = [ { entity: { @@ -164,7 +164,7 @@ describe('GitHubEntityProvider', () => { 'backstage.io/managed-by-location': `url:${url}`, 'backstage.io/managed-by-origin-location': `url:${url}`, }, - name: 'generated-21936a3d1e926b8bb3b00ac4398dc9a8dbb90b45', + name: 'generated-5e4b9498097f15434e88c477cfba6c079aa8ca7f', }, spec: { presence: 'optional', diff --git a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts index 43c01e8f7c..991b380112 100644 --- a/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GitHubEntityProvider.ts @@ -195,9 +195,9 @@ export class GitHubEntityProvider implements EntityProvider { private createLocationUrl(repository: Repository): string { const branch = this.config.filters?.branch || repository.defaultBranchRef?.name || '-'; - const catalogFile = this.config.catalogPath.substring( - this.config.catalogPath.lastIndexOf('/') + 1, - ); + const catalogFile = this.config.catalogPath.startsWith('/') + ? this.config.catalogPath.substring(1) + : this.config.catalogPath; return `${repository.url}/blob/${branch}/${catalogFile}`; }