Merge pull request #13016 from awanlin/topic/github-provider-wildcards

GitHub Entity Provider - Improved support for wildcards in `catalogPath`
This commit is contained in:
Patrik Oldsberg
2022-08-08 17:13:01 +02:00
committed by GitHub
4 changed files with 17 additions and 6 deletions
@@ -153,7 +153,7 @@ describe('GitHubEntityProvider', () => {
expect(taskDef.id).toEqual('github-provider:myProvider:refresh');
await (taskDef.fn as () => Promise<void>)();
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',
@@ -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}`;
}