Skip to content

Commit

Permalink
feat: allow slack-app and webhook to listen to schedule suspended eve…
Browse files Browse the repository at this point in the history
…nts (#5821)

This PR adds the schedule suspended event to the slack-app and webhook
definitions.

It also slightly tweaks the markdown formatting of change requests to
add a definite article. This means the snapshot also needs to be
updated.
  • Loading branch information
thomasheartman authored Jan 10, 2024
1 parent d770f62 commit 336eab9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ exports[`Should format specialised text for events when IPs changed 1`] = `
}
`;

exports[`Should format specialised text for events when a scheduled change request is suspended 1`] = `
{
"text": "Change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* was suspended for the following reason: The user who scheduled this change request (user id: 6) has been deleted from this Unleash instance.",
"url": "unleashUrl/projects/my-other-project/change-requests/1",
}
`;

exports[`Should format specialised text for events when change request is scheduled 1`] = `
{
"text": "*[email protected]* scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature toggle *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* to be applied at in project *my-other-project*",
"text": "*[email protected]* scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature toggle *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* to be applied at in project *my-other-project*",
"url": "unleashUrl/projects/my-other-project/change-requests/1",
}
`;
Expand Down Expand Up @@ -163,14 +170,14 @@ exports[`Should format specialised text for events when rollout percentage chang

exports[`Should format specialised text for events when scheduled change request fails 1`] = `
{
"text": "*Failed* to apply the scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature toggle *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* by *[email protected]* in project *my-other-project*.",
"text": "*Failed* to apply the scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature toggle *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* by *[email protected]* in project *my-other-project*.",
"url": "unleashUrl/projects/my-other-project/change-requests/1",
}
`;

exports[`Should format specialised text for events when scheduled change request succeeds 1`] = `
{
"text": "*Successfully* applied the scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature toggle *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* by *[email protected]* in project *my-other-project*.",
"text": "*Successfully* applied the scheduled change request *[#1](unleashUrl/projects/my-other-project/change-requests/1)* for feature toggle *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in the *production* environment in project *[my-other-project](unleashUrl/projects/my-other-project)* by *[email protected]* in project *my-other-project*.",
"url": "unleashUrl/projects/my-other-project/change-requests/1",
}
`;
Expand Down
19 changes: 19 additions & 0 deletions src/lib/addons/feature-event-formatter-md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
FEATURE_STRATEGY_ADD,
FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE,
Expand Down Expand Up @@ -552,6 +553,24 @@ const testCases: [string, IEvent][] = [
environment: 'production',
},
],
[
'when a scheduled change request is suspended',
{
id: 921,
type: CHANGE_REQUEST_SCHEDULE_SUSPENDED,
createdBy: '[email protected]',
createdByUserId: SYSTEM_USER_ID,
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
changeRequestId: 1,
reason: 'The user who scheduled this change request (user id: 6) has been deleted from this Unleash instance.',
},
preData: {},
tags: [],
project: 'my-other-project',
environment: 'production',
},
],
];

testCases.forEach(([description, event]) =>
Expand Down
7 changes: 6 additions & 1 deletion src/lib/addons/feature-event-formatter-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
} from '../types';

interface IEventData {
Expand Down Expand Up @@ -155,6 +156,10 @@ const EVENT_MAP: Record<string, IEventData> = {
action: '*Failed* to apply the scheduled change request {{changeRequest}} by *{{user}}* in project *{{event.project}}*.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULE_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]: {
action: '*{{user}}* created context field *{{event.data.name}}*',
path: '/context',
Expand Down Expand Up @@ -327,7 +332,7 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter {
? ` for feature toggle *${featureLink}*`
: '';
const environmentText = environment
? ` in *${environment}* environment`
? ` in the *${environment}* environment`
: '';
const projectLink = this.generateProjectLink(event);
const projectText = project ? ` in project *${projectLink}*` : '';
Expand Down
2 changes: 2 additions & 0 deletions src/lib/addons/slack-app-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
API_TOKEN_CREATED,
API_TOKEN_DELETED,
SERVICE_ACCOUNT_CREATED,
Expand Down Expand Up @@ -110,6 +111,7 @@ const slackAppDefinition: IAddonDefinition = {
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
CONTEXT_FIELD_CREATED,
CONTEXT_FIELD_DELETED,
CONTEXT_FIELD_UPDATED,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/addons/webhook-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
} from '../types/events';
import { IAddonDefinition } from '../types/model';

Expand Down Expand Up @@ -123,6 +124,7 @@ const webhookDefinition: IAddonDefinition = {
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
FEATURE_POTENTIALLY_STALE_ON,
],
};
Expand Down

0 comments on commit 336eab9

Please sign in to comment.