diff --git a/packages/backend/src/plugins/catalog.ts b/packages/backend/src/plugins/catalog.ts index f6fe25f86a..8cf44f9722 100644 --- a/packages/backend/src/plugins/catalog.ts +++ b/packages/backend/src/plugins/catalog.ts @@ -19,14 +19,30 @@ import { EntityProvider } from '@backstage/plugin-catalog-node'; import { ScaffolderEntitiesProcessor } from '@backstage/plugin-scaffolder-backend'; import { Router } from 'express'; import { PluginEnvironment } from '../types'; +import { GithubEntityProvider } from '@backstage/plugin-catalog-backend-module-github'; export default async function createPlugin( env: PluginEnvironment, providers?: Array, ): Promise { const builder = await CatalogBuilder.create(env); + const githubEntityProviders = GithubEntityProvider.fromConfig(env.config, { + logger: env.logger, + // optional: alternatively, use scheduler with schedule defined in app-config.yaml + schedule: env.scheduler.createScheduledTaskRunner({ + frequency: { minutes: 5 }, + timeout: { minutes: 3 }, + }), + scheduler: env.scheduler, + }); + builder.addEntityProvider(githubEntityProviders); builder.addProcessor(new ScaffolderEntitiesProcessor()); builder.addEntityProvider(providers ?? []); + // const conflictBroker = new InMemoryEventBroker(env.logger); + // conflictBroker.subscribe( + // new ConflictEventSubscriber(env.logger, ['conflicts']), + // ); + // builder.setConflictEventBroker(conflictBroker); const { processingEngine, router } = await builder.build(); await processingEngine.start(); return router; diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index eae8c0b9e4..1317481046 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -167,6 +167,9 @@ export class CatalogBuilder { export type CatalogCollatorEntityTransformer = CatalogCollatorEntityTransformer_2; +// @public (undocumented) +export const catalogConflictsTopic = 'catalog.conflict'; + // @public (undocumented) export type CatalogEnvironment = { logger: Logger; diff --git a/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts b/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts index 2a51227983..4b701758ec 100644 --- a/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts +++ b/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts @@ -46,6 +46,7 @@ import { updateUnprocessedEntity } from './operations/refreshState/updateUnproce import { generateStableHash } from './util'; import { EventBroker } from '@backstage/plugin-events-node'; import { DateTime } from 'luxon'; +import { catalogConflictsTopic } from '../service'; // The number of items that are sent per batch to the database layer, when // doing .batchInsert calls to knex. This needs to be low enough to not cause @@ -361,7 +362,7 @@ export class DefaultProcessingDatabase implements ProcessingDatabase { ); if (this.options.eventBroker) { await this.options.eventBroker?.publish({ - topic: 'catalog.conflicts', + topic: catalogConflictsTopic, eventPayload: { entity, entityRef, diff --git a/plugins/catalog-backend/src/service/CatalogBuilder.ts b/plugins/catalog-backend/src/service/CatalogBuilder.ts index c0d5c7acc7..39a40c95de 100644 --- a/plugins/catalog-backend/src/service/CatalogBuilder.ts +++ b/plugins/catalog-backend/src/service/CatalogBuilder.ts @@ -118,6 +118,9 @@ export type CatalogEnvironment = { permissions: PermissionEvaluator | PermissionAuthorizer; }; +/** @public */ +export const catalogConflictsTopic = 'catalog.conflict'; + /** * A builder that helps wire up all of the component parts of the catalog. * diff --git a/plugins/catalog-backend/src/service/index.ts b/plugins/catalog-backend/src/service/index.ts index 44645d39fe..70c65cf08f 100644 --- a/plugins/catalog-backend/src/service/index.ts +++ b/plugins/catalog-backend/src/service/index.ts @@ -18,4 +18,4 @@ export type { CatalogEnvironment, CatalogPermissionRuleInput, } from './CatalogBuilder'; -export { CatalogBuilder } from './CatalogBuilder'; +export { CatalogBuilder, catalogConflictsTopic } from './CatalogBuilder';