diff --git a/packages/backend/package.json b/packages/backend/package.json index fd8ec82d91..a83929a15d 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -40,6 +40,7 @@ "@backstage/plugin-azure-sites-backend": "workspace:^", "@backstage/plugin-badges-backend": "workspace:^", "@backstage/plugin-catalog-backend": "workspace:^", + "@backstage/plugin-catalog-backend-module-github": "workspace:^", "@backstage/plugin-catalog-node": "workspace:^", "@backstage/plugin-code-coverage-backend": "workspace:^", "@backstage/plugin-entity-feedback-backend": "workspace:^", diff --git a/plugins/catalog-backend/src/catalog/types.ts b/plugins/catalog-backend/src/catalog/types.ts index 404b816d4f..76841af260 100644 --- a/plugins/catalog-backend/src/catalog/types.ts +++ b/plugins/catalog-backend/src/catalog/types.ts @@ -311,3 +311,29 @@ export type Cursor = { */ totalItems?: number; }; + +/** + * The details of the conflicting entity. + */ +export type CatalogConflictEventPayload = { + /** + * The new conflicting entity + */ + entity: Entity; + /** + * The new conflicting entity's ref + */ + entityRef: string; + /** + * The location key of this new conflicting entity + */ + newLocationKey: string; + /** + * The location key of the entity already in the catalog that shares the same name and namespace as this entity + */ + existingLocationKey: string; + /** + * The datetime that the conflict was processed at + */ + lastConflictAt: string; +}; diff --git a/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts b/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts index e634d18c4a..fe61cc694e 100644 --- a/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts +++ b/plugins/catalog-backend/src/database/DefaultProcessingDatabase.ts @@ -44,9 +44,10 @@ import { checkLocationKeyConflict } from './operations/refreshState/checkLocatio import { insertUnprocessedEntity } from './operations/refreshState/insertUnprocessedEntity'; import { updateUnprocessedEntity } from './operations/refreshState/updateUnprocessedEntity'; import { generateStableHash } from './util'; -import { EventBroker } from '@backstage/plugin-events-node'; +import { EventBroker, EventParams } from '@backstage/plugin-events-node'; import { DateTime } from 'luxon'; import { CATALOG_CONFLICTS_TOPIC } from '../constants'; +import { CatalogConflictEventPayload } from '../catalog/types'; // 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 @@ -360,8 +361,8 @@ export class DefaultProcessingDatabase implements ProcessingDatabase { this.options.logger.warn( `Detected conflicting entityRef ${entityRef} already referenced by ${conflictingKey} and now also ${locationKey}`, ); - if (this.options.eventBroker) { - await this.options.eventBroker?.publish({ + if (this.options.eventBroker && locationKey) { + const eventParams: EventParams = { topic: CATALOG_CONFLICTS_TOPIC, eventPayload: { entity, @@ -370,7 +371,8 @@ export class DefaultProcessingDatabase implements ProcessingDatabase { existingLocationKey: conflictingKey, lastConflictAt: DateTime.now().toISO(), }, - }); + }; + await this.options.eventBroker?.publish(eventParams); } } } diff --git a/yarn.lock b/yarn.lock index db64dfc04e..d9b937d457 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5142,7 +5142,7 @@ __metadata: languageName: unknown linkType: soft -"@backstage/plugin-catalog-backend-module-github@workspace:plugins/catalog-backend-module-github": +"@backstage/plugin-catalog-backend-module-github@workspace:^, @backstage/plugin-catalog-backend-module-github@workspace:plugins/catalog-backend-module-github": version: 0.0.0-use.local resolution: "@backstage/plugin-catalog-backend-module-github@workspace:plugins/catalog-backend-module-github" dependencies: @@ -23482,6 +23482,7 @@ __metadata: "@backstage/plugin-azure-sites-backend": "workspace:^" "@backstage/plugin-badges-backend": "workspace:^" "@backstage/plugin-catalog-backend": "workspace:^" + "@backstage/plugin-catalog-backend-module-github": "workspace:^" "@backstage/plugin-catalog-node": "workspace:^" "@backstage/plugin-code-coverage-backend": "workspace:^" "@backstage/plugin-entity-feedback-backend": "workspace:^"