1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-27 11:02:16 +01:00
unleash.unleash/src/lib/addons/feature-event-formatter-md-events.ts
Thomas Heartman 6a7dcb9c46
fix(1-3247): remove explicit "in project" text from change request event text (#9091)
We got an event for a scheduled application success today that looked a
little something like this:

> Successfully applied the scheduled change request #1168 in the
production environment in project eg by gaston in project eg.

Notice that we're stating the project twice (once with a link (removed
here) and once without).

This PR removes the redundancy in CR events:


The project is already included in the `changeRequest` variable, which
is populated in `src/lib/addons/feature-event-formatter-md.ts` by
the `generateChangeRequestLink` function.

The (current) definition is:

```typescript
    generateChangeRequestLink(event: IEvent): string | undefined {
        const { preData, data, project, environment } = event;
        const changeRequestId =
            data?.changeRequestId || preData?.changeRequestId;
        if (project && changeRequestId) {
            const url = `${this.unleashUrl}/projects/${project}/change-requests/${changeRequestId}`;
            const text = `#${changeRequestId}`;
            const featureLink = this.generateFeatureLink(event);
            const featureText = featureLink
                ? ` for feature flag ${this.bold(featureLink)}`
                : '';
            const environmentText = environment
                ? ` in the ${this.bold(environment)} environment`
                : '';
            const projectLink = this.generateProjectLink(event);
            const projectText = project
                ? ` in project ${this.bold(projectLink)}`
                : '';
            if (this.linkStyle === LinkStyle.SLACK) {
                return `${this.bold(`<${url}|${text}>`)}${featureText}${environmentText}${projectText}`;
            } else {
                return `${this.bold(`[${text}](${url})`)}${featureText}${environmentText}${projectText}`;
            }
        }
    }
```

Which includes links, env, and project info already.
2025-01-14 09:54:19 +01:00

384 lines
17 KiB
TypeScript

import {
ADDON_CONFIG_CREATED,
ADDON_CONFIG_DELETED,
ADDON_CONFIG_UPDATED,
API_TOKEN_CREATED,
API_TOKEN_DELETED,
CHANGE_ADDED,
CHANGE_DISCARDED,
CHANGE_EDITED,
CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_APPROVAL_ADDED,
CHANGE_REQUEST_APPROVED,
CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_CREATED,
CHANGE_REQUEST_DISCARDED,
CHANGE_REQUEST_REJECTED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CONTEXT_FIELD_CREATED,
CONTEXT_FIELD_DELETED,
CONTEXT_FIELD_UPDATED,
FEATURE_ARCHIVED,
FEATURE_CREATED,
FEATURE_DELETED,
FEATURE_ENVIRONMENT_DISABLED,
FEATURE_ENVIRONMENT_ENABLED,
FEATURE_ENVIRONMENT_VARIANTS_UPDATED,
FEATURE_METADATA_UPDATED,
FEATURE_POTENTIALLY_STALE_ON,
FEATURE_PROJECT_CHANGE,
FEATURE_REVIVED,
FEATURE_STALE_OFF,
FEATURE_STALE_ON,
FEATURE_STRATEGY_ADD,
FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE,
FEATURE_TAGGED,
FEATURE_UNTAGGED,
GROUP_CREATED,
GROUP_DELETED,
GROUP_UPDATED,
BANNER_CREATED,
BANNER_DELETED,
BANNER_UPDATED,
PROJECT_CREATED,
PROJECT_DELETED,
SEGMENT_CREATED,
SEGMENT_DELETED,
SEGMENT_UPDATED,
SERVICE_ACCOUNT_CREATED,
SERVICE_ACCOUNT_DELETED,
SERVICE_ACCOUNT_UPDATED,
USER_CREATED,
USER_DELETED,
USER_UPDATED,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
FEATURE_COMPLETED,
PROJECT_ARCHIVED,
RELEASE_PLAN_ADDED,
RELEASE_PLAN_REMOVED,
RELEASE_PLAN_MILESTONE_STARTED,
} from '../types';
interface IEventData {
label: string;
action: string;
path?: string;
}
export const EVENT_MAP: Record<string, IEventData> = {
[ADDON_CONFIG_CREATED]: {
label: 'Integration configuration created',
action: '{{b}}{{user}}{{b}} created a new {{b}}{{event.data.provider}}{{b}} integration configuration',
path: '/integrations',
},
[ADDON_CONFIG_DELETED]: {
label: 'Integration configuration deleted',
action: '{{b}}{{user}}{{b}} deleted a {{b}}{{event.preData.provider}}{{b}} integration configuration',
path: '/integrations',
},
[ADDON_CONFIG_UPDATED]: {
label: 'Integration configuration updated',
action: '{{b}}{{user}}{{b}} updated a {{b}}{{event.preData.provider}}{{b}} integration configuration',
path: '/integrations',
},
[API_TOKEN_CREATED]: {
label: 'API token created',
action: '{{b}}{{user}}{{b}} created API token {{b}}{{event.data.username}}{{b}}',
path: '/admin/api',
},
[API_TOKEN_DELETED]: {
label: 'API token deleted',
action: '{{b}}{{user}}{{b}} deleted API token {{b}}{{event.preData.username}}{{b}}',
path: '/admin/api',
},
[CHANGE_ADDED]: {
label: 'Change added',
action: '{{b}}{{user}}{{b}} added a change to change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_DISCARDED]: {
label: 'Change discarded',
action: '{{b}}{{user}}{{b}} discarded a change in change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_EDITED]: {
label: 'Change edited',
action: '{{b}}{{user}}{{b}} edited a change in change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_APPLIED]: {
label: 'Change request applied',
action: '{{b}}{{user}}{{b}} applied change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_APPROVAL_ADDED]: {
label: 'Change request approval added',
action: '{{b}}{{user}}{{b}} added an approval to change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_APPROVED]: {
label: 'Change request approved',
action: '{{b}}{{user}}{{b}} approved change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_CANCELLED]: {
label: 'Change request cancelled',
action: '{{b}}{{user}}{{b}} cancelled change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_CREATED]: {
label: 'Change request created',
action: '{{b}}{{user}}{{b}} created change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_DISCARDED]: {
label: 'Change request discarded',
action: '{{b}}{{user}}{{b}} discarded change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_REJECTED]: {
label: 'Change request rejected',
action: '{{b}}{{user}}{{b}} rejected change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SENT_TO_REVIEW]: {
label: 'Change request sent to review',
action: '{{b}}{{user}}{{b}} sent to review change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULED]: {
label: 'Change request scheduled',
action: '{{b}}{{user}}{{b}} scheduled change request {{changeRequest}} to be applied at {{event.data.scheduledDate}}.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS]: {
label: 'Scheduled change request applied successfully',
action: '{{b}}Successfully{{b}} applied the scheduled change request {{changeRequest}} by {{b}}{{user}}{{b}}.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE]: {
label: 'Scheduled change request failed',
action: '{{b}}Failed{{b}} to apply the scheduled change request {{changeRequest}} by {{b}}{{user}}{{b}}.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULE_SUSPENDED]: {
label: 'Change request suspended',
action: 'Change request {{changeRequest}} was suspended for the following reason: {{event.data.reason}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CONTEXT_FIELD_CREATED]: {
label: 'Context field created',
action: '{{b}}{{user}}{{b}} created context field {{b}}{{event.data.name}}{{b}}',
path: '/context',
},
[CONTEXT_FIELD_DELETED]: {
label: 'Context field deleted',
action: '{{b}}{{user}}{{b}} deleted context field {{b}}{{event.preData.name}}{{b}}',
path: '/context',
},
[CONTEXT_FIELD_UPDATED]: {
label: 'Context field updated',
action: '{{b}}{{user}}{{b}} updated context field {{b}}{{event.preData.name}}{{b}}',
path: '/context',
},
[FEATURE_ARCHIVED]: {
label: 'Flag archived',
action: '{{b}}{{user}}{{b}} archived {{b}}{{event.featureName}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/archive',
},
[FEATURE_CREATED]: {
label: 'Flag created',
action: '{{b}}{{user}}{{b}} created {{b}}{{feature}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_DELETED]: {
label: 'Flag deleted',
action: '{{b}}{{user}}{{b}} deleted {{b}}{{event.featureName}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}',
},
[FEATURE_ENVIRONMENT_DISABLED]: {
label: 'Flag disabled',
action: '{{b}}{{user}}{{b}} disabled {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_ENVIRONMENT_ENABLED]: {
label: 'Flag enabled',
action: '{{b}}{{user}}{{b}} enabled {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_ENVIRONMENT_VARIANTS_UPDATED]: {
label: 'Flag variants updated',
action: '{{b}}{{user}}{{b}} updated variants for {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}/variants',
},
[FEATURE_METADATA_UPDATED]: {
label: 'Flag metadata updated',
action: '{{b}}{{user}}{{b}} updated {{b}}{{feature}}{{b}} metadata in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_COMPLETED]: {
label: 'Flag marked as completed',
action: '{{b}}{{feature}}{{b}} was marked as completed in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_POTENTIALLY_STALE_ON]: {
label: 'Flag potentially stale',
action: '{{b}}{{feature}}{{b}} was marked as potentially stale in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_PROJECT_CHANGE]: {
label: 'Flag moved to a new project',
action: '{{b}}{{user}}{{b}} moved {{b}}{{feature}}{{b}} from {{b}}{{event.data.oldProject}}{{b}} to {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_REVIVED]: {
label: 'Flag revived',
action: '{{b}}{{user}}{{b}} revived {{b}}{{feature}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_STALE_OFF]: {
label: 'Flag stale marking removed',
action: '{{b}}{{user}}{{b}} removed the stale marking on {{b}}{{feature}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_STALE_ON]: {
label: 'Flag marked as stale',
action: '{{b}}{{user}}{{b}} marked {{b}}{{feature}}{{b}} as stale in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_STRATEGY_ADD]: {
label: 'Flag strategy added',
action: '{{b}}{{user}}{{b}} added strategy {{b}}{{strategyTitle}}{{b}} to {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_STRATEGY_REMOVE]: {
label: 'Flag strategy removed',
action: '{{b}}{{user}}{{b}} removed strategy {{b}}{{strategyTitle}}{{b}} from {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_STRATEGY_UPDATE]: {
label: 'Flag strategy updated',
action: '{{b}}{{user}}{{b}} updated {{b}}{{feature}}{{b}} in project {{b}}{{project}}{{b}} {{strategyChangeText}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_TAGGED]: {
label: 'Flag tagged',
action: '{{b}}{{user}}{{b}} tagged {{b}}{{feature}}{{b}} with {{b}}{{event.data.type}}:{{event.data.value}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[FEATURE_UNTAGGED]: {
label: 'Flag untagged',
action: '{{b}}{{user}}{{b}} untagged {{b}}{{feature}}{{b}} with {{b}}{{event.preData.type}}:{{event.preData.value}}{{b}} in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[GROUP_CREATED]: {
label: 'Group created',
action: '{{b}}{{user}}{{b}} created group {{b}}{{event.data.name}}{{b}}',
path: '/admin/groups',
},
[GROUP_DELETED]: {
label: 'Group deleted',
action: '{{b}}{{user}}{{b}} deleted group {{b}}{{event.preData.name}}{{b}}',
path: '/admin/groups',
},
[GROUP_UPDATED]: {
label: 'Group updated',
action: '{{b}}{{user}}{{b}} updated group {{b}}{{event.preData.name}}{{b}}',
path: '/admin/groups',
},
[BANNER_CREATED]: {
label: 'Banner created',
action: '{{b}}{{user}}{{b}} created banner {{b}}{{event.data.message}}{{b}}',
path: '/admin/message-banners',
},
[BANNER_DELETED]: {
label: 'Banner deleted',
action: '{{b}}{{user}}{{b}} deleted banner {{b}}{{event.preData.message}}{{b}}',
path: '/admin/message-banners',
},
[BANNER_UPDATED]: {
label: 'Banner updated',
action: '{{b}}{{user}}{{b}} updated banner {{b}}{{event.preData.message}}{{b}}',
path: '/admin/message-banners',
},
[PROJECT_CREATED]: {
label: 'Project created',
action: '{{b}}{{user}}{{b}} created project {{b}}{{project}}{{b}}',
path: '/projects',
},
[PROJECT_ARCHIVED]: {
label: 'Project archived',
action: '{{b}}{{user}}{{b}} archived project {{b}}{{event.project}}{{b}}',
path: '/projects-archive',
},
[PROJECT_DELETED]: {
label: 'Project deleted',
action: '{{b}}{{user}}{{b}} deleted project {{b}}{{event.project}}{{b}}',
path: '/projects',
},
[SEGMENT_CREATED]: {
label: 'Segment created',
action: '{{b}}{{user}}{{b}} created segment {{b}}{{event.data.name}}{{b}}',
path: '/segments',
},
[SEGMENT_DELETED]: {
label: 'Segment deleted',
action: '{{b}}{{user}}{{b}} deleted segment {{b}}{{event.preData.name}}{{b}}',
path: '/segments',
},
[SEGMENT_UPDATED]: {
label: 'Segment updated',
action: '{{b}}{{user}}{{b}} updated segment {{b}}{{event.preData.name}}{{b}}',
path: '/segments',
},
[SERVICE_ACCOUNT_CREATED]: {
label: 'Service account created',
action: '{{b}}{{user}}{{b}} created service account {{b}}{{event.data.name}}{{b}}',
path: '/admin/service-accounts',
},
[SERVICE_ACCOUNT_DELETED]: {
label: 'Service account deleted',
action: '{{b}}{{user}}{{b}} deleted service account {{b}}{{event.preData.name}}{{b}}',
path: '/admin/service-accounts',
},
[SERVICE_ACCOUNT_UPDATED]: {
label: 'Service account updated',
action: '{{b}}{{user}}{{b}} updated service account {{b}}{{event.preData.name}}{{b}}',
path: '/admin/service-accounts',
},
[USER_CREATED]: {
label: 'User created',
action: '{{b}}{{user}}{{b}} created user {{b}}{{event.data.name}}{{b}}',
path: '/admin/users',
},
[USER_DELETED]: {
label: 'User deleted',
action: '{{b}}{{user}}{{b}} deleted user {{b}}{{event.preData.name}}{{b}}',
path: '/admin/users',
},
[USER_UPDATED]: {
label: 'User updated',
action: '{{b}}{{user}}{{b}} updated user {{b}}{{event.preData.name}}{{b}}',
path: '/admin/users',
},
[RELEASE_PLAN_ADDED]: {
label: 'Release plan added',
action: '{{b}}{{user}}{{b}} added release plan {{b}}{{event.data.name}}{{b}} to {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[RELEASE_PLAN_REMOVED]: {
label: 'Release plan removed',
action: '{{b}}{{user}}{{b}} removed release plan {{b}}{{event.preData.name}}{{b}} from {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
[RELEASE_PLAN_MILESTONE_STARTED]: {
label: 'Release plan milestone started',
action: '{{b}}{{user}}{{b}} started milestone {{b}}{{event.data.milestoneName}}{{b}} in release plan {{b}}{{event.data.name}}{{b}} for {{b}}{{feature}}{{b}} for the {{b}}{{event.environment}}{{b}} environment in project {{b}}{{project}}{{b}}',
path: '/projects/{{event.project}}/features/{{event.featureName}}',
},
};