From 468bbcccfcf498bfcea15e4686c514638bd85daf Mon Sep 17 00:00:00 2001 From: djamaile Date: Thu, 21 Nov 2024 05:51:44 +0100 Subject: [PATCH] chore: set a default schedule for the GithubEntityProvider Signed-off-by: djamaile --- .changeset/cuddly-schools-scream.md | 5 +++++ .../providers/GithubEntityProvider.test.ts | 16 -------------- .../src/providers/GithubEntityProvider.ts | 6 ------ .../GithubEntityProviderConfig.test.ts | 21 +++++++++++-------- .../providers/GithubEntityProviderConfig.ts | 11 +++++++++- 5 files changed, 27 insertions(+), 32 deletions(-) create mode 100644 .changeset/cuddly-schools-scream.md diff --git a/.changeset/cuddly-schools-scream.md b/.changeset/cuddly-schools-scream.md new file mode 100644 index 0000000000..bea1d7d020 --- /dev/null +++ b/.changeset/cuddly-schools-scream.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-github': patch +--- + +Pass in a default shedule to the `GithubEntityProvider` if none is provided 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 624deaa38e..b7df19c296 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.test.ts @@ -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 = { diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts index 5c6dc75e48..a18846b157 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProvider.ts @@ -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!); diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts index 296cbc12df..d00cbc888c 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.test.ts @@ -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', diff --git a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts index 073c92701f..2e2592b70a 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubEntityProviderConfig.ts @@ -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,