Skip to content

Commit

Permalink
fix: project to lifecycle events (#7400)
Browse files Browse the repository at this point in the history
We need project for those events to filter it out in webhook
configuration.
  • Loading branch information
sjaanus committed Jun 14, 2024
1 parent f0ecc18 commit 3e3235e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand All @@ -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,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class FeatureLifecycleService extends EventEmitter {

public async featureCompleted(
feature: string,
projectId: string,
status: FeatureLifecycleCompletedSchema,
auditUser: IAuditUser,
) {
Expand All @@ -193,20 +194,26 @@ export class FeatureLifecycleService extends EventEmitter {
]);
await this.eventService.storeEvent(
new FeatureCompletedEvent({
project: projectId,
featureName: feature,
data: status,
auditUser,
}),
);
}

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,
}),
Expand Down
10 changes: 8 additions & 2 deletions src/lib/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 3e3235e

Please sign in to comment.