Case-insensitive match organization on Github events.

Signed-off-by: Charlie Crawford <char507@gmail.com>
This commit is contained in:
Charlie Crawford
2025-06-11 09:02:20 -04:00
parent 30287b8e21
commit 7c0dfb0d11
3 changed files with 70 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-github': minor
---
GitHub organization now matches in a case-insensitive manner when processing events.
@@ -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', () => {
@@ -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}`,
);