feat(events,github): add support for EventsService, events at new backend
Adds optional support for the EventsService passed as argument to the factory method. For the new backend, the EventsService is used as dependency and passed on. Events support will be active always. The support for the deprecated EventBroker and its interfaces was kept for easier migration and will be removed as a separate follow-up change that could go into a following release. Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import { EntityProvider } from '@backstage/plugin-catalog-node';
|
||||
import { EntityProviderConnection } from '@backstage/plugin-catalog-node';
|
||||
import { EventBroker } from '@backstage/plugin-events-node';
|
||||
import { EventParams } from '@backstage/plugin-events-node';
|
||||
import { EventsService } from '@backstage/plugin-events-node';
|
||||
import { EventSubscriber } from '@backstage/plugin-events-node';
|
||||
import { GithubCredentialsProvider } from '@backstage/integration';
|
||||
import { GithubIntegrationConfig } from '@backstage/integration';
|
||||
@@ -88,6 +89,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
options: {
|
||||
events?: EventsService;
|
||||
logger: Logger;
|
||||
schedule?: TaskRunner;
|
||||
scheduler?: PluginTaskScheduler;
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
catalogAnalysisExtensionPoint,
|
||||
catalogProcessingExtensionPoint,
|
||||
} from '@backstage/plugin-catalog-node/alpha';
|
||||
import { eventsServiceRef } from '@backstage/plugin-events-node';
|
||||
import { GithubEntityProvider } from '../providers/GithubEntityProvider';
|
||||
import { GithubLocationAnalyzer } from '../analyzers/GithubLocationAnalyzer';
|
||||
|
||||
@@ -37,17 +38,19 @@ export const githubCatalogModule = createBackendModule({
|
||||
register(env) {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
catalog: catalogProcessingExtensionPoint,
|
||||
analyzers: catalogAnalysisExtensionPoint,
|
||||
auth: coreServices.auth,
|
||||
discovery: coreServices.discovery,
|
||||
catalog: catalogProcessingExtensionPoint,
|
||||
config: coreServices.rootConfig,
|
||||
discovery: coreServices.discovery,
|
||||
events: eventsServiceRef,
|
||||
logger: coreServices.logger,
|
||||
scheduler: coreServices.scheduler,
|
||||
},
|
||||
async init({
|
||||
catalog,
|
||||
config,
|
||||
events,
|
||||
logger,
|
||||
scheduler,
|
||||
analyzers,
|
||||
@@ -64,6 +67,7 @@ export const githubCatalogModule = createBackendModule({
|
||||
|
||||
catalog.addEntityProvider(
|
||||
GithubEntityProvider.fromConfig(config, {
|
||||
events,
|
||||
logger: loggerToWinstonLogger(logger),
|
||||
scheduler,
|
||||
}),
|
||||
|
||||
@@ -46,7 +46,11 @@ import {
|
||||
satisfiesVisibilityFilter,
|
||||
} from '../lib/util';
|
||||
|
||||
import { EventParams, EventSubscriber } from '@backstage/plugin-events-node';
|
||||
import {
|
||||
EventParams,
|
||||
EventsService,
|
||||
EventSubscriber,
|
||||
} from '@backstage/plugin-events-node';
|
||||
import { PushEvent, Commit } from '@octokit/webhooks-types';
|
||||
import { Minimatch } from 'minimatch';
|
||||
|
||||
@@ -73,6 +77,7 @@ type Repository = {
|
||||
*/
|
||||
export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
private readonly config: GithubEntityProviderConfig;
|
||||
private readonly events?: EventsService;
|
||||
private readonly logger: Logger;
|
||||
private readonly integration: GithubIntegrationConfig;
|
||||
private readonly scheduleFn: () => Promise<void>;
|
||||
@@ -82,6 +87,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
options: {
|
||||
events?: EventsService;
|
||||
logger: Logger;
|
||||
schedule?: TaskRunner;
|
||||
scheduler?: PluginTaskScheduler;
|
||||
@@ -118,6 +124,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
integration,
|
||||
options.logger,
|
||||
taskRunner,
|
||||
options.events,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -127,8 +134,10 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
integration: GithubIntegration,
|
||||
logger: Logger,
|
||||
taskRunner: TaskRunner,
|
||||
events?: EventsService,
|
||||
) {
|
||||
this.config = config;
|
||||
this.events = events;
|
||||
this.integration = integration.config;
|
||||
this.logger = logger.child({
|
||||
target: this.getProviderName(),
|
||||
@@ -146,6 +155,11 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
/** {@inheritdoc @backstage/plugin-catalog-backend#EntityProvider.connect} */
|
||||
async connect(connection: EntityProviderConnection): Promise<void> {
|
||||
this.connection = connection;
|
||||
await this.events?.subscribe({
|
||||
id: this.getProviderName(),
|
||||
topics: [TOPIC_REPO_PUSH],
|
||||
onEvent: params => this.onEvent(params),
|
||||
});
|
||||
return await this.scheduleFn();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user