diff --git a/.changeset/thick-hotels-enter.md b/.changeset/thick-hotels-enter.md new file mode 100644 index 0000000000..300586f570 --- /dev/null +++ b/.changeset/thick-hotels-enter.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Fix GitHub catalog entity provider branch matching on event processing. 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 4032e1d368..b9f69b5754 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts @@ -961,6 +961,33 @@ describe('GithubEntityProvider', () => { expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(1); }); + + it('should fail with incorrect branch matching', async () => { + const config = createSingleProviderConfig({ + providerConfig: { + catalogPath: '**/catalog-info.yaml', + }, + }); + const provider = createProviders(config)[0]; + + const entityProviderConnection: EntityProviderConnection = { + applyMutation: jest.fn(), + refresh: jest.fn(), + }; + await provider.connect(entityProviderConnection); + + const event = createPushEvent({ + catalogFile: { + action: 'added', + path: 'folder1/folder2/folder3/catalog-info.yaml', + }, + ref: 'refs/heads/my-main-branch', + }); + + await provider.onEvent(event); + + expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); + }); }); describe('on repository event', () => { diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts index 5f3c652cb9..dd8c16ef34 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts @@ -343,7 +343,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { const branch = this.config.filters.branch || event.repository.default_branch; - if (!event.ref.includes(branch)) { + if (event.ref !== `refs/heads/${branch}`) { this.logger.debug(`skipping push event from ref ${event.ref}`); return; }