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 <otto.nordander@gmail.com>
This commit is contained in:
Otto Nordander
2021-07-13 15:43:50 +02:00
parent 7a6a3586ac
commit e77670bddd
3 changed files with 36 additions and 2 deletions
+5 -1
View File
@@ -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
@@ -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', () => {
@@ -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);