fix(plugins/catalog-backend-module-github): support push events with catalogPath containing glob patterns
Signed-off-by: Thomas Cardonne <thomas.cardonne@adevinta.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-github': patch
|
||||
---
|
||||
|
||||
GitHub push events now schedule a refresh on entities that have a refresh_key matching the `catalogPath` config itself.
|
||||
This allows to support a `catalogPath` configuration that uses glob patterns.
|
||||
@@ -1074,6 +1074,77 @@ describe('GithubEntityProvider', () => {
|
||||
expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('apply refresh call on modified files from push event when catalogPath contains a glob pattern', async () => {
|
||||
const schedule = new PersistingTaskRunner();
|
||||
const config = new ConfigReader({
|
||||
catalog: {
|
||||
providers: {
|
||||
github: {
|
||||
organization: 'test-org',
|
||||
catalogPath: '**/catalog-info.yaml',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
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/main',
|
||||
repository: {
|
||||
name: 'teste-1',
|
||||
url: 'https://github.com/test-org/test-repo',
|
||||
default_branch: 'main',
|
||||
stargazers: 0,
|
||||
master_branch: 'main',
|
||||
organization: 'test-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);
|
||||
|
||||
expect(entityProviderConnection.refresh).toHaveBeenCalledTimes(1);
|
||||
expect(entityProviderConnection.refresh).toHaveBeenCalledWith({
|
||||
keys: [
|
||||
'url:https://github.com/test-org/test-repo/tree/main/catalog-info.yaml',
|
||||
'url:https://github.com/test-org/test-repo/blob/main/catalog-info.yaml',
|
||||
'url:https://github.com/test-org/test-repo/tree/main/**/catalog-info.yaml',
|
||||
],
|
||||
});
|
||||
expect(entityProviderConnection.applyMutation).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should process repository when match filters from push event', async () => {
|
||||
const schedule = new PersistingTaskRunner();
|
||||
const config = new ConfigReader({
|
||||
|
||||
@@ -374,16 +374,23 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
);
|
||||
|
||||
if (modified.length > 0) {
|
||||
const catalogPath = this.config.catalogPath.startsWith('/')
|
||||
? this.config.catalogPath.substring(1)
|
||||
: this.config.catalogPath;
|
||||
|
||||
await this.connection.refresh({
|
||||
keys: [
|
||||
...modified.map(
|
||||
filePath =>
|
||||
`url:${event.repository.url}/tree/${branch}/${filePath}`,
|
||||
),
|
||||
...modified.map(
|
||||
filePath =>
|
||||
`url:${event.repository.url}/blob/${branch}/${filePath}`,
|
||||
),
|
||||
...new Set([
|
||||
...modified.map(
|
||||
filePath =>
|
||||
`url:${event.repository.url}/tree/${branch}/${filePath}`,
|
||||
),
|
||||
...modified.map(
|
||||
filePath =>
|
||||
`url:${event.repository.url}/blob/${branch}/${filePath}`,
|
||||
),
|
||||
`url:${event.repository.url}/tree/${branch}/${catalogPath}`,
|
||||
]),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user