From e77670bdddc8929b53912e0d78e20b1af68c09b6 Mon Sep 17 00:00:00 2001 From: Otto Nordander Date: Tue, 13 Jul 2021 15:43:50 +0200 Subject: [PATCH 1/2] Add default catalogPath value if missing. Currently the following target would give an empty catalogPath: https://bitbucket.mycompany.com/projects/*/repos/*/ However it's convenient to have a default catalog value, and it would expand as such: https://bitbucket.mycompany.com/projects/project-a/repos/repo-b/catalog-info.yaml Signed-off-by: Otto Nordander --- docs/integrations/bitbucket/discovery.md | 6 +++- .../BitbucketDiscoveryProcessor.test.ts | 28 +++++++++++++++++++ .../processors/BitbucketDiscoveryProcessor.ts | 4 ++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/docs/integrations/bitbucket/discovery.md b/docs/integrations/bitbucket/discovery.md index fadb7c9f06..1538806e39 100644 --- a/docs/integrations/bitbucket/discovery.md +++ b/docs/integrations/bitbucket/discovery.md @@ -38,7 +38,11 @@ The target is composed of four parts: repositories prefixed with `service-`. - The path within each repository to find the catalog YAML file. This will usually be `/catalog-info.yaml` or a similar variation for catalog files - stored in the root directory of each repository. + stored in the root directory of each repository. If omitted, the default value + `catalog-info.yaml` will be used. E.g. given that `my-project`and `service-a` + exists, `https://bitbucket.mycompany.com/projects/my-project/repos/service-*/` + will result in: + `https://bitbucket.mycompany.com/projects/my-project/repos/service-a/catalog-info.yaml`. ## Custom repository processing diff --git a/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.test.ts index d33ea7ab26..e2b295e7ff 100644 --- a/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.test.ts @@ -225,6 +225,34 @@ describe('BitbucketDiscoveryProcessor', () => { optional: true, }); }); + + it.each` + target + ${'https://bitbucket.mycompany.com/projects/backstage/repos/*'} + ${'https://bitbucket.mycompany.com/projects/backstage/repos/*/'} + ${'https://bitbucket.mycompany.com/projects/backstage/repos/techdocs-*/'} + `("target '$target' adds default path to catalog", async ({ target }) => { + setupStubs([{ key: 'backstage', repos: ['techdocs-cli'] }]); + + const location: LocationSpec = { + type: 'bitbucket-discovery', + target: target, + }; + + const emitter = jest.fn(); + await processor.readLocation(location, false, emitter); + + expect(emitter).toHaveBeenCalledTimes(1); + expect(emitter).toHaveBeenCalledWith({ + type: 'location', + location: { + type: 'url', + target: + 'https://bitbucket.mycompany.com/projects/backstage/repos/techdocs-cli/browse/catalog-info.yaml', + }, + optional: true, + }); + }); }); describe('Custom repository parser', () => { diff --git a/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.ts index 877cd08a3e..9d53b7e5b5 100644 --- a/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/BitbucketDiscoveryProcessor.ts @@ -84,13 +84,15 @@ export class BitbucketDiscoveryProcessor implements CatalogProcessor { this.logger.info(`Reading Bitbucket repositories from ${location.target}`); const { catalogPath } = parseUrl(location.target); + const expandedCatalogPath = + catalogPath === '/' ? '/catalog-info.yaml' : catalogPath; const result = await readBitbucketOrg(client, location.target); for (const repository of result.matches) { for await (const entity of this.parser({ integration: integration, - target: `${repository.links.self[0].href}${catalogPath}`, + target: `${repository.links.self[0].href}${expandedCatalogPath}`, logger: this.logger, })) { emit(entity); From 8bfc0571ce6fc4fd8a498307776177b627ddf45b Mon Sep 17 00:00:00 2001 From: Otto Nordander Date: Wed, 14 Jul 2021 08:30:37 +0200 Subject: [PATCH 2/2] Add changeset for default catalog value Signed-off-by: Otto Nordander --- .changeset/fifty-walls-grin.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .changeset/fifty-walls-grin.md diff --git a/.changeset/fifty-walls-grin.md b/.changeset/fifty-walls-grin.md new file mode 100644 index 0000000000..cd71574322 --- /dev/null +++ b/.changeset/fifty-walls-grin.md @@ -0,0 +1,17 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +Add a default catalog value for BitBucketDiscoveryProcessor. This allows to have a target like so: https://bitbucket.mycompany.com/projects/backstage/repos/service-* +which will be expanded to https://bitbucket.mycompany.com/projects/backstage/repos/service-a/catalog-info.yaml given that repository 'service-a' exists. + +## Migration + +If you are using a custom [Bitbucket parser](https://backstage.io/docs/integrations/bitbucket/discovery#custom-repository-processing) and your `bitbucket-discovery` target (e.g. in your app-config.yaml) omits the catalog path in any of the following ways: + +- https://bitbucket.mycompany.com/projects/backstage/repos/service-* +- https://bitbucket.mycompany.com/projects/backstage/repos/* +- https://bitbucket.mycompany.com/projects/backstage/repos/*/ + +then you will be affected by this change. +The 'target' input to your parser before this commit would be '/', and after this commit it will be '/catalog-info.yaml', and as such needs to be handled to maintain the same functionality.