From 7c0dfb0d115488af4fec72902e6746f670612093 Mon Sep 17 00:00:00 2001 From: Charlie Crawford Date: Wed, 11 Jun 2025 09:02:20 -0400 Subject: [PATCH] Case-insensitive match organization on Github events. Signed-off-by: Charlie Crawford --- .changeset/rich-tires-battle.md | 5 ++ .../providers/GithubEntityProvider.test.ts | 51 +++++++++++++++++++ .../src/providers/GithubEntityProvider.ts | 16 +++++- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .changeset/rich-tires-battle.md diff --git a/.changeset/rich-tires-battle.md b/.changeset/rich-tires-battle.md new file mode 100644 index 0000000000..0d1355f123 --- /dev/null +++ b/.changeset/rich-tires-battle.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': minor +--- + +GitHub organization now matches in a case-insensitive manner when processing events. 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 b7df19c296..4032e1d368 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts @@ -940,6 +940,27 @@ describe('GithubEntityProvider', () => { expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(0); expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0); }); + + it('should process when orgs case-insensitive match', async () => { + const config = createSingleProviderConfig({ + providerConfig: { + organization: 'test-org', + }, + }); + const provider = createProviders(config)[0]; + + const entityProviderConnection: EntityProviderConnection = { + applyMutation: jest.fn(), + refresh: jest.fn(), + }; + await provider.connect(entityProviderConnection); + + const event = createPushEvent({ org: 'Test-Org' }); + + await provider.onEvent(event); + + expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(1); + }); }); describe('on repository event', () => { @@ -1189,6 +1210,36 @@ describe('GithubEntityProvider', () => { 0, ); }); + + it('applies update when orgs case-insensitive match', async () => { + const config = createSingleProviderConfig({ + providerConfig: { + organization: 'test-org', + filters: { + topic: { + include: ['backstage-include'], + }, + }, + }, + }); + + const provider = createProviders(config)[0]; + + const entityProviderConnection: EntityProviderConnection = { + applyMutation: jest.fn(), + refresh: jest.fn(), + }; + await provider.connect(entityProviderConnection); + + const event = createRepoEvent('edited'); + event.eventPayload.organization!.login = 'Test-Org'; + + await provider.onEvent(event); + + expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes( + 1, + ); + }); }); describe('on repository privatized event', () => { diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts index 131237c581..5f3c652cb9 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts @@ -323,7 +323,13 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { } private async onPush(event: PushEvent) { - if (this.config.organization !== event.organization?.login) { + const configOrganization = this.config.organization; + const eventOrganization = event.organization?.login; + + if ( + configOrganization.toLocaleLowerCase('en-US') !== + eventOrganization?.toLocaleLowerCase('en-US') + ) { this.logger.debug( `skipping push event from organization ${event.organization?.login}`, ); @@ -406,7 +412,13 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber { } private async onRepoChange(event: RepositoryEvent) { - if (this.config.organization !== event.organization?.login) { + const configOrganization = this.config.organization; + const eventOrganization = event.organization?.login; + + if ( + configOrganization.toLocaleLowerCase('en-US') !== + eventOrganization?.toLocaleLowerCase('en-US') + ) { this.logger.debug( `skipping repository event from organization ${event.organization?.login}`, );