diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts index 4d16b824a3..8fb79bb20d 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.test.ts @@ -170,6 +170,68 @@ describe('GithubDiscoveryProcessor', () => { }); }); + it('output repositories with wildcards default branch option', async () => { + const location: LocationSpec = { + type: 'github-discovery', + target: 'https://github.com/backstage/techdocs-*/blob/-/catalog.yaml', + }; + mockGetOrganizationRepositories.mockResolvedValueOnce({ + repositories: [ + { + name: 'backstage', + url: 'https://github.com/backstage/backstage', + isArchived: false, + defaultBranchRef: { + name: 'master', + }, + }, + ], + }); + const emitter = jest.fn(); + + await processor.readLocation(location, false, emitter); + + expect(emitter).toHaveBeenCalledWith({ + type: 'location', + location: { + type: 'url', + target: 'https://github.com/backstage/blob/master/catalog.yaml', + }, + optional: true, + }); + }); + + it('output repositories with wildcards default branch option without catalog-info patch or branch match', async () => { + const location: LocationSpec = { + type: 'github-discovery', + target: 'https://github.com/backstage', + }; + mockGetOrganizationRepositories.mockResolvedValueOnce({ + repositories: [ + { + name: 'backstage', + url: 'https://github.com/backstage/backstage', + isArchived: false, + defaultBranchRef: { + name: 'master', + }, + }, + ], + }); + const emitter = jest.fn(); + + await processor.readLocation(location, false, emitter); + + expect(emitter).toHaveBeenCalledWith({ + type: 'location', + location: { + type: 'url', + target: 'https://github.com/backstage/blob/master/catalog-info.yaml', + }, + optional: true, + }); + }); + it('output repositories with wildcards', async () => { const location: LocationSpec = { type: 'github-discovery', @@ -206,7 +268,7 @@ describe('GithubDiscoveryProcessor', () => { name: 'techdocs-durp', url: 'https://github.com/backstage/techdocs-durp', isArchived: false, - defaultBranchRef: undefined, + defaultBranchRef: null, }, ], }); @@ -233,6 +295,7 @@ describe('GithubDiscoveryProcessor', () => { optional: true, }); }); + it('filter unrelated and archived repositories', async () => { const location: LocationSpec = { type: 'github-discovery', diff --git a/plugins/catalog-backend/src/ingestion/processors/github/github.ts b/plugins/catalog-backend/src/ingestion/processors/github/github.ts index 5ff3856f97..fbbe9b3470 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/github.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/github.ts @@ -60,9 +60,9 @@ export type Repository = { name: string; url: string; isArchived: boolean; - defaultBranchRef?: { + defaultBranchRef: { name: string; - }; + } | null; }; export type Connection = {