From 97f0a37378d9db4ede917b9bac9391be4f5e9ebe Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Mon, 8 Aug 2022 08:22:56 -0500 Subject: [PATCH 1/3] Support catalogPath wildcards Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .changeset/tall-mugs-press.md | 5 +++++ .../src/providers/GitHubEntityProvider.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changeset/tall-mugs-press.md 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/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}`; } From 68d492d2fcdcd4ad3f817a256a370589fd21cdb7 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Mon, 8 Aug 2022 09:35:21 -0500 Subject: [PATCH 2/3] Fixed failing test Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .../src/providers/GitHubEntityProvider.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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', From e983631c5e2daad22b9eae56ca2eebacd2ebb022 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Mon, 8 Aug 2022 09:42:04 -0500 Subject: [PATCH 3/3] Updated documentation Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- docs/integrations/github/discovery.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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.