Skip to content

Commit

Permalink
feat: Handle scheduled request events in addons (#5403)
Browse files Browse the repository at this point in the history
- Create 2 new events to replace the SCHEDULED_CHANGE_REQUEST_EXECUTED
event
- Handle the 3 events in slack-app and webhook addon definitions

3 events handled:
- CHANGE_REQUEST_SCHEDULED
- CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS
- CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE

Closes #
[1-1555](https://linear.app/unleash/issue/1-1555/update-change-request-scheduled-and-scheduled-change-request-executed)

Note: SCHEDULED_CHANGE_REQUEST_EXECUTED will be removed in follow up PR
not to break current enterprise build

---------

Signed-off-by: andreas-unleash <[email protected]>
  • Loading branch information
andreas-unleash authored Nov 23, 2023
1 parent 916e4c9 commit 2e17909
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ exports[`Should format specialised text for events when IPs changed 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*",
"url": "unleashUrl/projects/my-other-project/change-requests/1",
}
`;

exports[`Should format specialised text for events when constraints and rollout percentage and stickiness changed 1`] = `
{
"text": "*[email protected]* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production* stickiness from default to random; rollout from 67% to 32%; constraints from empty set of constraints to [appName is one of (x,y)]",
Expand Down Expand Up @@ -154,6 +161,20 @@ 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*.",
"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*.",
"url": "unleashUrl/projects/my-other-project/change-requests/1",
}
`;

exports[`Should format specialised text for events when stickiness changed 1`] = `
{
"text": "*[email protected]* updated *[new-feature](unleashUrl/projects/my-other-project/features/new-feature)* in project *[my-other-project](unleashUrl/projects/my-other-project)* by updating strategy *flexibleRollout* in *production* stickiness from default to random",
Expand Down
54 changes: 54 additions & 0 deletions src/lib/addons/feature-event-formatter-md.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
FEATURE_STRATEGY_ADD,
FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE,
Expand Down Expand Up @@ -481,6 +484,57 @@ const testCases: [string, IEvent][] = [
environment: 'production',
},
],
[
'when change request is scheduled',
{
id: 920,
type: CHANGE_REQUEST_SCHEDULED,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
changeRequestId: 1,
},
preData: {},
tags: [],
featureName: 'new-feature',
project: 'my-other-project',
environment: 'production',
},
],
[
'when scheduled change request succeeds ',
{
id: 920,
type: CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
changeRequestId: 1,
},
preData: {},
tags: [],
featureName: 'new-feature',
project: 'my-other-project',
environment: 'production',
},
],
[
'when scheduled change request fails ',
{
id: 920,
type: CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
createdBy: '[email protected]',
createdAt: new Date('2022-06-01T10:03:11.549Z'),
data: {
changeRequestId: 1,
},
preData: {},
tags: [],
featureName: 'new-feature',
project: 'my-other-project',
environment: 'production',
},
],
];

testCases.forEach(([description, event]) =>
Expand Down
15 changes: 15 additions & 0 deletions src/lib/addons/feature-event-formatter-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ import {
USER_CREATED,
USER_DELETED,
USER_UPDATED,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
} from '../types';

interface IEventData {
Expand Down Expand Up @@ -140,6 +143,18 @@ const EVENT_MAP: Record<string, IEventData> = {
action: '*{{user}}* sent to review change request {{changeRequest}}',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULED]: {
action: '*{{user}}* scheduled change request {{changeRequest}} to be applied at {{event.data.scheduledDate}} in project *{{event.project}}*',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS]: {
action: '*Successfully* applied the scheduled change request {{changeRequest}} by *{{user}}* in project *{{event.project}}*.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE]: {
action: '*Failed* to apply the scheduled change request {{changeRequest}} by *{{user}}* in project *{{event.project}}*.',
path: '/projects/{{event.project}}/change-requests/{{event.data.changeRequestId}}',
},
[CONTEXT_FIELD_CREATED]: {
action: '*{{user}}* created context field *{{event.data.name}}*',
path: '/context',
Expand Down
6 changes: 6 additions & 0 deletions src/lib/addons/slack-app-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ import {
BANNER_CREATED,
BANNER_UPDATED,
BANNER_DELETED,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
} from '../types/events';
import { IAddonDefinition } from '../types/model';

Expand Down Expand Up @@ -104,6 +107,9 @@ const slackAppDefinition: IAddonDefinition = {
CHANGE_REQUEST_DISCARDED,
CHANGE_REQUEST_REJECTED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CONTEXT_FIELD_CREATED,
CONTEXT_FIELD_DELETED,
CONTEXT_FIELD_UPDATED,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/addons/webhook-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_APPLIED,
FEATURE_POTENTIALLY_STALE_ON,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULED,
} from '../types/events';
import { IAddonDefinition } from '../types/model';

Expand Down Expand Up @@ -117,6 +120,9 @@ const webhookDefinition: IAddonDefinition = {
CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
FEATURE_POTENTIALLY_STALE_ON,
],
};
Expand Down
8 changes: 7 additions & 1 deletion src/lib/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ export const CHANGE_REQUEST_SENT_TO_REVIEW =
'change-request-sent-to-review' as const;
export const CHANGE_REQUEST_APPLIED = 'change-request-applied' as const;
export const SCHEDULED_CHANGE_REQUEST_EXECUTED =
'scheduled-change-request-executed' as const;
'scheduled-change-request-executed' as const; //This will be removed in follow up PR
export const CHANGE_REQUEST_SCHEDULED = 'change-request-scheduled' as const;
export const CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS =
'change-request-scheduled-application-success' as const;
export const CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE =
'change-request-scheduled-application-failure' as const;

export const API_TOKEN_CREATED = 'api-token-created' as const;
export const API_TOKEN_UPDATED = 'api-token-updated' as const;
Expand Down Expand Up @@ -252,6 +256,8 @@ export const IEventTypes = [
SCHEDULED_CHANGE_REQUEST_EXECUTED,
CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
API_TOKEN_CREATED,
API_TOKEN_UPDATED,
API_TOKEN_DELETED,
Expand Down

0 comments on commit 2e17909

Please sign in to comment.