chore: set a default schedule for the GithubEntityProvider

Signed-off-by: djamaile <rdjamaile@gmail.com>
This commit is contained in:
djamaile
2024-11-21 05:51:44 +01:00
parent c5bfddd7ea
commit 468bbcccfc
5 changed files with 27 additions and 32 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-github': patch
---
Pass in a default shedule to the `GithubEntityProvider` if none is provided
@@ -621,22 +621,6 @@ describe('GithubEntityProvider', () => {
).toThrow('Either schedule or scheduler must be provided');
});
it('fail with scheduler but no schedule config', () => {
const scheduler = {
createScheduledTaskRunner: (_: any) => jest.fn(),
} as unknown as SchedulerService;
const config = createSingleProviderConfig();
expect(() =>
GithubEntityProvider.fromConfig(config, {
logger,
scheduler,
}),
).toThrow(
'No schedule provided neither via code nor config for github-provider:myProvider',
);
});
it('single simple provider config with schedule in config', async () => {
const schedule = new PersistingTaskRunner();
const scheduler = {
@@ -126,12 +126,6 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
);
}
if (!options.schedule && !providerConfig.schedule) {
throw new Error(
`No schedule provided neither via code nor config for github-provider:${providerConfig.id}.`,
);
}
const taskRunner =
options.schedule ??
options.scheduler!.createScheduledTaskRunner(providerConfig.schedule!);
@@ -15,7 +15,10 @@
*/
import { ConfigReader } from '@backstage/config';
import { readProviderConfigs } from './GithubEntityProviderConfig';
import {
readProviderConfigs,
DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
} from './GithubEntityProviderConfig';
describe('readProviderConfigs', () => {
afterEach(() => jest.resetAllMocks());
@@ -124,7 +127,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[1]).toEqual({
@@ -142,7 +145,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[2]).toEqual({
@@ -160,7 +163,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[3]).toEqual({
@@ -178,7 +181,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[4]).toEqual({
@@ -196,7 +199,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[5]).toEqual({
@@ -214,7 +217,7 @@ describe('readProviderConfigs', () => {
},
visibility: undefined,
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[6]).toEqual({
@@ -232,7 +235,7 @@ describe('readProviderConfigs', () => {
},
visibility: ['public', 'internal'],
},
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
validateLocationsExist: false,
});
expect(providerConfigs[7]).toEqual({
@@ -251,7 +254,7 @@ describe('readProviderConfigs', () => {
visibility: undefined,
},
validateLocationsExist: false,
schedule: undefined,
schedule: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE,
});
expect(providerConfigs[8]).toEqual({
id: 'providerWithSchedule',
@@ -23,6 +23,15 @@ import { Config } from '@backstage/config';
const DEFAULT_CATALOG_PATH = '/catalog-info.yaml';
const DEFAULT_PROVIDER_ID = 'default';
export const DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE = {
frequency: {
hours: 3,
},
timeout: {
hours: 1,
},
};
export type GithubEntityProviderConfig = {
id: string;
catalogPath: string;
@@ -99,7 +108,7 @@ function readProviderConfig(
? readSchedulerServiceTaskScheduleDefinitionFromConfig(
config.getConfig('schedule'),
)
: undefined;
: DEFAULT_GITHUB_ENTITY_PROVIDER_CONFIG_SCHEDULE;
return {
id,