feat(catalog/github): use schedule from config at backend module
Also, it removed `GithubEntityProviderCatalogModuleOptions` in favor of config-only for the backend module setup like at other similar modules. Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend-module-github': patch
|
||||
---
|
||||
|
||||
Use schedule from config at backend module.
|
||||
|
||||
Also, it removes `GithubEntityProviderCatalogModuleOptions`
|
||||
in favor of config-only for the backend module setup
|
||||
like at other similar modules.
|
||||
@@ -20,7 +20,6 @@ import { PluginTaskScheduler } from '@backstage/backend-tasks';
|
||||
import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { ScmLocationAnalyzer } from '@backstage/plugin-catalog-backend';
|
||||
import { TaskRunner } from '@backstage/backend-tasks';
|
||||
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
|
||||
|
||||
// @public
|
||||
export class GithubDiscoveryProcessor implements CatalogProcessor {
|
||||
@@ -68,14 +67,9 @@ export class GitHubEntityProvider implements EntityProvider {
|
||||
|
||||
// @alpha
|
||||
export const githubEntityProviderCatalogModule: (
|
||||
options?: GithubEntityProviderCatalogModuleOptions | undefined,
|
||||
options?: undefined,
|
||||
) => BackendFeature;
|
||||
|
||||
// @alpha
|
||||
export type GithubEntityProviderCatalogModuleOptions = {
|
||||
schedule?: TaskScheduleDefinition;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export class GitHubLocationAnalyzer implements ScmLocationAnalyzer {
|
||||
constructor(options: GitHubLocationAnalyzerOptions);
|
||||
|
||||
@@ -20,14 +20,13 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export { GitHubLocationAnalyzer } from './analyzers/GitHubLocationAnalyzer';
|
||||
export type { GitHubLocationAnalyzerOptions } from './analyzers/GitHubLocationAnalyzer';
|
||||
export type { GithubMultiOrgConfig } from './lib';
|
||||
export { GithubDiscoveryProcessor } from './processors/GithubDiscoveryProcessor';
|
||||
export { GithubMultiOrgReaderProcessor } from './processors/GithubMultiOrgReaderProcessor';
|
||||
export { GithubOrgReaderProcessor } from './processors/GithubOrgReaderProcessor';
|
||||
export { GitHubEntityProvider } from './providers/GitHubEntityProvider';
|
||||
export { GitHubOrgEntityProvider } from './providers/GitHubOrgEntityProvider';
|
||||
export type { GitHubOrgEntityProviderOptions } from './providers/GitHubOrgEntityProvider';
|
||||
export type { GithubMultiOrgConfig } from './lib';
|
||||
export { githubEntityProviderCatalogModule } from './module';
|
||||
export type { GithubEntityProviderCatalogModuleOptions } from './module';
|
||||
export { GitHubLocationAnalyzer } from './analyzers/GitHubLocationAnalyzer';
|
||||
export type { GitHubLocationAnalyzerOptions } from './analyzers/GitHubLocationAnalyzer';
|
||||
export { githubEntityProviderCatalogModule } from './service/GithubEntityProviderCatalogModule';
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
configServiceRef,
|
||||
loggerServiceRef,
|
||||
schedulerServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
PluginTaskScheduler,
|
||||
TaskScheduleDefinition,
|
||||
} from '@backstage/backend-tasks';
|
||||
import { startTestBackend } from '@backstage/backend-test-utils';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';
|
||||
import { Duration } from 'luxon';
|
||||
import { githubEntityProviderCatalogModule } from './GithubEntityProviderCatalogModule';
|
||||
import { GitHubEntityProvider } from '../providers/GitHubEntityProvider';
|
||||
|
||||
describe('githubEntityProviderCatalogModule', () => {
|
||||
it('should register provider at the catalog extension point', async () => {
|
||||
let addedProviders: Array<GitHubEntityProvider> | undefined;
|
||||
let usedSchedule: TaskScheduleDefinition | undefined;
|
||||
|
||||
const extensionPoint = {
|
||||
addEntityProvider: (providers: any) => {
|
||||
addedProviders = providers;
|
||||
},
|
||||
};
|
||||
const runner = jest.fn();
|
||||
const scheduler = {
|
||||
createScheduledTaskRunner: (schedule: TaskScheduleDefinition) => {
|
||||
usedSchedule = schedule;
|
||||
return runner;
|
||||
},
|
||||
} as unknown as PluginTaskScheduler;
|
||||
|
||||
const config = new ConfigReader({
|
||||
catalog: {
|
||||
providers: {
|
||||
github: {
|
||||
organization: 'module-test',
|
||||
schedule: {
|
||||
frequency: 'P1M',
|
||||
timeout: 'PT3M',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await startTestBackend({
|
||||
extensionPoints: [[catalogProcessingExtensionPoint, extensionPoint]],
|
||||
services: [
|
||||
[configServiceRef, config],
|
||||
[loggerServiceRef, getVoidLogger()],
|
||||
[schedulerServiceRef, scheduler],
|
||||
],
|
||||
features: [githubEntityProviderCatalogModule()],
|
||||
});
|
||||
|
||||
expect(usedSchedule?.frequency).toEqual(Duration.fromISO('P1M'));
|
||||
expect(usedSchedule?.timeout).toEqual(Duration.fromISO('PT3M'));
|
||||
expect(addedProviders?.length).toEqual(1);
|
||||
expect(addedProviders?.pop()?.getProviderName()).toEqual(
|
||||
'github-provider:default',
|
||||
);
|
||||
expect(runner).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+5
-21
@@ -21,18 +21,8 @@ import {
|
||||
loggerServiceRef,
|
||||
schedulerServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { TaskScheduleDefinition } from '@backstage/backend-tasks';
|
||||
import { catalogProcessingExtensionPoint } from '@backstage/plugin-catalog-node';
|
||||
import { GitHubEntityProvider } from './providers/GitHubEntityProvider';
|
||||
|
||||
/**
|
||||
* Options for {@link githubEntityProviderCatalogModule}.
|
||||
*
|
||||
* @alpha
|
||||
*/
|
||||
export type GithubEntityProviderCatalogModuleOptions = {
|
||||
schedule?: TaskScheduleDefinition;
|
||||
};
|
||||
import { GitHubEntityProvider } from '../providers/GitHubEntityProvider';
|
||||
|
||||
/**
|
||||
* Registers the GitHubEntityProvider with the catalog processing extension point.
|
||||
@@ -42,25 +32,19 @@ export type GithubEntityProviderCatalogModuleOptions = {
|
||||
export const githubEntityProviderCatalogModule = createBackendModule({
|
||||
pluginId: 'catalog',
|
||||
moduleId: 'githubEntityProvider',
|
||||
register(env, options?: GithubEntityProviderCatalogModuleOptions) {
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
config: configServiceRef,
|
||||
catalog: catalogProcessingExtensionPoint,
|
||||
config: configServiceRef,
|
||||
logger: loggerServiceRef,
|
||||
scheduler: schedulerServiceRef,
|
||||
},
|
||||
async init({ config, catalog, logger, scheduler }) {
|
||||
const scheduleDef = options?.schedule ?? {
|
||||
frequency: { seconds: 600 },
|
||||
timeout: { seconds: 900 },
|
||||
initialDelay: { seconds: 3 },
|
||||
};
|
||||
|
||||
async init({ catalog, config, logger, scheduler }) {
|
||||
catalog.addEntityProvider(
|
||||
GitHubEntityProvider.fromConfig(config, {
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
schedule: scheduler.createScheduledTaskRunner(scheduleDef),
|
||||
scheduler,
|
||||
}),
|
||||
);
|
||||
},
|
||||
Reference in New Issue
Block a user