1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: allow slack-app and webhook to listen to schedule suspended events (#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.
This commit is contained in:
Thomas Heartman 2024-01-10 15:14:31 +05:30 committed by GitHub
parent d770f624e6
commit 336eab9c5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 4 deletions

View File

@ -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`] = ` exports[`Should format specialised text for events when change request is scheduled 1`] = `
{ {
"text": "*user@company.com* 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": "*user@company.com* 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", "url": "unleashUrl/projects/my-other-project/change-requests/1",
} }
`; `;
@ -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`] = ` 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 *user@company.com* 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 *user@company.com* in project *my-other-project*.",
"url": "unleashUrl/projects/my-other-project/change-requests/1", "url": "unleashUrl/projects/my-other-project/change-requests/1",
} }
`; `;
exports[`Should format specialised text for events when scheduled change request succeeds 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 *user@company.com* 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 *user@company.com* in project *my-other-project*.",
"url": "unleashUrl/projects/my-other-project/change-requests/1", "url": "unleashUrl/projects/my-other-project/change-requests/1",
} }
`; `;

View File

@ -2,6 +2,7 @@ import {
CHANGE_REQUEST_SCHEDULED, CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE, CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS, CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
FEATURE_STRATEGY_ADD, FEATURE_STRATEGY_ADD,
FEATURE_STRATEGY_REMOVE, FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE, FEATURE_STRATEGY_UPDATE,
@ -552,6 +553,24 @@ const testCases: [string, IEvent][] = [
environment: 'production', environment: 'production',
}, },
], ],
[
'when a scheduled change request is suspended',
{
id: 921,
type: CHANGE_REQUEST_SCHEDULE_SUSPENDED,
createdBy: 'user@company.com',
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]) => testCases.forEach(([description, event]) =>

View File

@ -58,6 +58,7 @@ import {
CHANGE_REQUEST_SCHEDULED, CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS, CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE, CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
} from '../types'; } from '../types';
interface IEventData { interface IEventData {
@ -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}}*.', action: '*Failed* to apply the scheduled change request {{changeRequest}} by *{{user}}* in project *{{event.project}}*.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}', 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]: { [CONTEXT_FIELD_CREATED]: {
action: '*{{user}}* created context field *{{event.data.name}}*', action: '*{{user}}* created context field *{{event.data.name}}*',
path: '/context', path: '/context',
@ -327,7 +332,7 @@ export class FeatureEventFormatterMd implements FeatureEventFormatter {
? ` for feature toggle *${featureLink}*` ? ` for feature toggle *${featureLink}*`
: ''; : '';
const environmentText = environment const environmentText = environment
? ` in *${environment}* environment` ? ` in the *${environment}* environment`
: ''; : '';
const projectLink = this.generateProjectLink(event); const projectLink = this.generateProjectLink(event);
const projectText = project ? ` in project *${projectLink}*` : ''; const projectText = project ? ` in project *${projectLink}*` : '';

View File

@ -43,6 +43,7 @@ import {
CHANGE_REQUEST_CANCELLED, CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_SENT_TO_REVIEW, CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_APPLIED, CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
API_TOKEN_CREATED, API_TOKEN_CREATED,
API_TOKEN_DELETED, API_TOKEN_DELETED,
SERVICE_ACCOUNT_CREATED, SERVICE_ACCOUNT_CREATED,
@ -110,6 +111,7 @@ const slackAppDefinition: IAddonDefinition = {
CHANGE_REQUEST_SCHEDULED, CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS, CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE, CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
CONTEXT_FIELD_CREATED, CONTEXT_FIELD_CREATED,
CONTEXT_FIELD_DELETED, CONTEXT_FIELD_DELETED,
CONTEXT_FIELD_UPDATED, CONTEXT_FIELD_UPDATED,

View File

@ -28,6 +28,7 @@ import {
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS, CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE, CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULED, CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
} from '../types/events'; } from '../types/events';
import { IAddonDefinition } from '../types/model'; import { IAddonDefinition } from '../types/model';
@ -123,6 +124,7 @@ const webhookDefinition: IAddonDefinition = {
CHANGE_REQUEST_SCHEDULED, CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS, CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE, CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
FEATURE_POTENTIALLY_STALE_ON, FEATURE_POTENTIALLY_STALE_ON,
], ],
}; };