From 3e3235ea10e2430a47013691ae15be3cf5a7f646 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Fri, 14 Jun 2024 16:42:10 +0300 Subject: [PATCH] fix: project to lifecycle events (#7400) We need project for those events to filter it out in webhook configuration. --- .../feature-lifecycle/feature-lifecycle-controller.ts | 8 +++++--- .../feature-lifecycle/feature-lifecycle-service.ts | 9 ++++++++- src/lib/types/events.ts | 10 ++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/lib/features/feature-lifecycle/feature-lifecycle-controller.ts b/src/lib/features/feature-lifecycle/feature-lifecycle-controller.ts index 0d926520e89f..9f6cd5b47c54 100644 --- a/src/lib/features/feature-lifecycle/feature-lifecycle-controller.ts +++ b/src/lib/features/feature-lifecycle/feature-lifecycle-controller.ts @@ -143,12 +143,13 @@ export default class FeatureLifecycleController extends Controller { if (!this.flagResolver.isEnabled('featureLifecycle')) { throw new NotFoundError('Feature lifecycle is disabled.'); } - const { featureName } = req.params; + const { featureName, projectId } = req.params; const status = req.body; await this.featureLifecycleService.featureCompleted( featureName, + projectId, status, req.audit, ); @@ -163,10 +164,11 @@ export default class FeatureLifecycleController extends Controller { if (!this.flagResolver.isEnabled('featureLifecycle')) { throw new NotFoundError('Feature lifecycle is disabled.'); } - const { featureName } = req.params; + const { featureName, projectId } = req.params; - await this.featureLifecycleService.featureUnCompleted( + await this.featureLifecycleService.featureUncompleted( featureName, + projectId, req.audit, ); diff --git a/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts b/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts index 78867cb27b01..dff3717c7d2b 100644 --- a/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts +++ b/src/lib/features/feature-lifecycle/feature-lifecycle-service.ts @@ -180,6 +180,7 @@ export class FeatureLifecycleService extends EventEmitter { public async featureCompleted( feature: string, + projectId: string, status: FeatureLifecycleCompletedSchema, auditUser: IAuditUser, ) { @@ -193,6 +194,7 @@ export class FeatureLifecycleService extends EventEmitter { ]); await this.eventService.storeEvent( new FeatureCompletedEvent({ + project: projectId, featureName: feature, data: status, auditUser, @@ -200,13 +202,18 @@ export class FeatureLifecycleService extends EventEmitter { ); } - public async featureUnCompleted(feature: string, auditUser: IAuditUser) { + public async featureUncompleted( + feature: string, + projectId: string, + auditUser: IAuditUser, + ) { await this.featureLifecycleStore.deleteStage({ feature, stage: 'completed', }); await this.eventService.storeEvent( new FeatureUncompletedEvent({ + project: projectId, featureName: feature, auditUser, }), diff --git a/src/lib/types/events.ts b/src/lib/types/events.ts index 7f729f27313e..593a4d21d6ee 100644 --- a/src/lib/types/events.ts +++ b/src/lib/types/events.ts @@ -722,29 +722,35 @@ export class FeatureTagImport extends BaseEvent { export class FeatureCompletedEvent extends BaseEvent { readonly featureName: string; readonly data: FeatureLifecycleCompletedSchema; + readonly project: string; constructor(p: { + project: string; featureName: string; data: FeatureLifecycleCompletedSchema; auditUser: IAuditUser; }) { super(FEATURE_COMPLETED, p.auditUser); - const { featureName, data } = p; + const { featureName, data, project } = p; this.featureName = featureName; this.data = data; + this.project = project; } } export class FeatureUncompletedEvent extends BaseEvent { readonly featureName: string; + readonly project: string; constructor(p: { featureName: string; auditUser: IAuditUser; + project: string; }) { super(FEATURE_UNCOMPLETED, p.auditUser); - const { featureName } = p; + const { featureName, project } = p; this.featureName = featureName; + this.project = project; } }