fix: update onRepoPush to drop events from different organizations Close #15878:

Signed-off-by: Rogerio Angeliski <angeliski@hotmail.com>
This commit is contained in:
Rogerio Angeliski
2023-06-21 11:51:19 +00:00
parent cb91dac435
commit b01b869d71
3 changed files with 81 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-github': patch
---
fixed event handler to respect configured organization
@@ -1212,4 +1212,73 @@ describe('GithubEntityProvider', () => {
expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(0);
expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0);
});
it("should skip process when didn't match org from push event", async () => {
const schedule = new PersistingTaskRunner();
const config = new ConfigReader({
catalog: {
providers: {
github: {
organization: 'test-org',
filters: {
branch: 'my-special-branch',
repository: 'test-repo',
},
},
},
},
});
const provider = GithubEntityProvider.fromConfig(config, {
logger,
schedule,
})[0];
const entityProviderConnection: EntityProviderConnection = {
applyMutation: jest.fn(),
refresh: jest.fn(),
};
await provider.connect(entityProviderConnection);
const event: EventParams = {
topic: 'github.push',
metadata: {
'x-github-event': 'push',
},
eventPayload: {
ref: 'refs/heads/my-special-branch',
repository: {
name: 'test-repo',
url: 'https://github.com/test-org/test-repo',
default_branch: 'main',
stargazers: 0,
master_branch: 'main',
organization: 'other-org',
topics: [],
},
created: true,
deleted: false,
forced: false,
commits: [
{
added: ['new-file.yaml'],
removed: [],
modified: [],
},
{
added: [],
removed: [],
modified: ['catalog-info.yaml'],
},
],
},
};
await provider.onEvent(event);
await provider.onEvent(event);
expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(0);
expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0);
});
});
@@ -296,6 +296,13 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
throw new Error('Not initialized');
}
if (this.config.organization !== event.repository.organization) {
this.logger.debug(
`skipping push event from organization ${event.repository.organization}`,
);
return;
}
const repoName = event.repository.name;
const repoUrl = event.repository.url;
this.logger.debug(`handle github:push event for ${repoName} - ${repoUrl}`);