Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

DEVPROD-2227: Remove family triggers from trigger definitions #2203

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cypress/integration/projectSettings/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("Notifications", () => {
cy.dataCy("add-button").contains("Add Subscription").should("be.visible");
cy.dataCy("add-button").click();
cy.dataCy("expandable-card").should("contain.text", "New Subscription");
cy.selectLGOption("Event", "Any Version Finishes");
cy.selectLGOption("Event", "Any version finishes");
cy.selectLGOption("Notification Method", "Email");
cy.getInputByLabel("Email").type("[email protected]");
cy.dataCy("save-settings-button").scrollIntoView();
Expand All @@ -43,7 +43,7 @@ describe("Notifications", () => {
cy.dataCy("expandable-card")
.should("be.visible")
.should("contain.text", "New Subscription");
cy.selectLGOption("Event", "Any Task Finishes");
cy.selectLGOption("Event", "Any task finishes");
cy.selectLGOption("Notification Method", "Comment on a JIRA issue");
cy.getInputByLabel("JIRA Issue").type("JIRA-123");
cy.contains("Subscription type not allowed for tasks in a project.").should(
Expand All @@ -58,7 +58,7 @@ describe("Notifications", () => {
cy.dataCy("expandable-card")
.should("be.visible")
.should("contain.text", "New Subscription");
cy.selectLGOption("Event", "Any Version Finishes");
cy.selectLGOption("Event", "Any version finishes");
cy.selectLGOption("Notification Method", "Email");
cy.getInputByLabel("Email").type("Not a real email");
cy.contains("Value should be a valid email.").should("be.visible");
Expand Down
8 changes: 4 additions & 4 deletions cypress/integration/subscription_modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe("Waterfall subscription modal", () => {
cy.dataCy("add-notification").click();
cy.dataCy(dataCyModal).should("be.visible");

cy.selectLGOption("Event", "Any Version Finishes");
cy.selectLGOption("Event", "Any version finishes");
cy.selectLGOption("Notification Method", "JIRA issue");

cy.dataCy("jira-comment-input").type("EVG-2000");
Expand All @@ -160,7 +160,7 @@ describe("Waterfall subscription modal", () => {
cy.dataCy("add-notification").click();
cy.dataCy(dataCyModal).should("be.visible");

cy.selectLGOption("Event", "Any Build Finishes");
cy.selectLGOption("Event", "Any build finishes");
cy.dataCy("add-button").click();
saveButtonEnabled(false);

Expand All @@ -179,7 +179,7 @@ describe("Waterfall subscription modal", () => {
cy.dataCy("add-notification").click();
cy.dataCy(dataCyModal).should("be.visible");

cy.selectLGOption("Event", "Any Version Finishes");
cy.selectLGOption("Event", "Any version finishes");
cy.dataCy("jira-comment-input").type("EVG-2000");
mockErrorResponse({
path: "SaveSubscription",
Expand Down Expand Up @@ -207,7 +207,7 @@ describe("Waterfall subscription modal", () => {
cy.dataCy("waterfall-menu").click();
cy.dataCy("add-notification").click();
cy.dataCy(dataCyModal).should("be.visible");
cy.contains("Any Build Fails").should("be.visible");
cy.contains("Any build fails").should("be.visible");
cy.contains("Slack").should("be.visible");

cy.clearCookie(subscriptionCookie);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Notifications/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("getGqlPayload", () => {
type: "email",
target: "[email protected]",
},
trigger: "family-outcome",
trigger: "outcome",
trigger_data: {},
});
});
Expand Down
65 changes: 32 additions & 33 deletions src/constants/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,19 @@ export const taskTriggers: Trigger = {
// VERSION TRIGGERS
export const versionTriggers: Trigger = {
[VersionTriggers.VERSION_FINISHES]: {
trigger: TriggerType.FAMILY_OUTCOME,
trigger: TriggerType.OUTCOME,
label: "This version finishes",
resourceType: ResourceType.Version,
payloadResourceIdKey: "id",
},
[VersionTriggers.VERSION_FAILS]: {
trigger: TriggerType.FAMILY_FAILURE,
trigger: TriggerType.FAILURE,
label: "This version fails",
resourceType: ResourceType.Version,
payloadResourceIdKey: "id",
},
[VersionTriggers.VERSION_SUCCEEDS]: {
trigger: TriggerType.FAMILY_SUCCESS,
trigger: TriggerType.SUCCESS,
label: "This version succeeds",
resourceType: ResourceType.Version,
payloadResourceIdKey: "id",
Expand Down Expand Up @@ -207,70 +207,70 @@ export const versionTriggers: Trigger = {

export const projectTriggers: Trigger = {
[ProjectTriggers.ANY_VERSION_FINISHES]: {
trigger: TriggerType.FAMILY_OUTCOME,
trigger: TriggerType.OUTCOME,
resourceType: ResourceType.Version,
label: "Any Version Finishes",
label: "Any version finishes",
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_VERSION_FAILS]: {
trigger: TriggerType.FAMILY_FAILURE,
trigger: TriggerType.FAILURE,
resourceType: ResourceType.Version,
label: "Any Version Fails",
label: "Any version fails",
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_BUILD_FINISHES]: {
trigger: TriggerType.OUTCOME,
resourceType: ResourceType.Build,
label: "Any Build Finishes",
label: "Any build finishes",
regexSelectors: buildRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_BUILD_FAILS]: {
trigger: TriggerType.FAILURE,
resourceType: ResourceType.Build,
label: "Any Build Fails",
label: "Any build fails",
regexSelectors: buildRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_TASK_FINISHES]: {
trigger: TriggerType.OUTCOME,
resourceType: ResourceType.Task,
label: "Any Task Finishes",
label: "Any task finishes",
regexSelectors: taskRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_TASK_FAILS]: {
trigger: TriggerType.FAILURE,
resourceType: ResourceType.Task,
label: "Any Task Fails",
label: "Any task fails",
regexSelectors: taskRegexSelectors,
extraFields: [failureTypeSubscriberConfig, requesterSubscriberConfig],
},
[ProjectTriggers.FIRST_FAILURE_VERSION]: {
trigger: TriggerType.FIRST_FAILURE_VERSION,
resourceType: ResourceType.Task,
label: "The First Failure In a Version Occurs",
label: "The first failure in a version occurs",
regexSelectors: taskRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.FIRST_FAILURE_BUILD]: {
trigger: TriggerType.FIRST_FAILURE_BUILD,
resourceType: ResourceType.Task,
label: "The First Failure In Each Build Occurs",
label: "The first failure in each build occurs",
regexSelectors: taskRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.FIRST_FAILURE_TASK]: {
trigger: TriggerType.FIRST_FAILURE_VERSION_NAME,
resourceType: ResourceType.Task,
label: "The First Failure In Each Version For Each Task Name Occurs",
label: "The first failure in each version for each task name occurs",
regexSelectors: taskRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.PREVIOUS_PASSING_TASK_FAILS]: {
trigger: TriggerType.REGRESSION,
resourceType: ResourceType.Task,
label: "A Previously Passing Task Fails",
label: "A previously passing task fails",
regexSelectors: taskRegexSelectors,
extraFields: [
{
Expand All @@ -286,7 +286,7 @@ export const projectTriggers: Trigger = {
[ProjectTriggers.PREVIOUS_PASSING_TEST_FAILS]: {
trigger: TriggerType.TEST_REGRESSION,
resourceType: ResourceType.Task,
label: "A Previously Passing Test In a Task Fails",
label: "A previously passing test in a task fails",
regexSelectors: taskRegexSelectors,
extraFields: [
{
Expand All @@ -309,7 +309,7 @@ export const projectTriggers: Trigger = {
[ProjectTriggers.SUCCESSFUL_TASK_EXCEEDS_DURATION]: {
trigger: TriggerType.SUCCESSFUL_EXCEEDS_DURATION,
resourceType: ResourceType.Task,
label: "The Runtime For a Successful Task Exceeds Some Duration",
label: "The runtime For a successful task exceeds some duration",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
label: "The runtime For a successful task exceeds some duration",
label: "The runtime for a successful task exceeds some duration",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you... 🥹

regexSelectors: taskRegexSelectors,
extraFields: [
{
Expand All @@ -324,7 +324,7 @@ export const projectTriggers: Trigger = {
[ProjectTriggers.TASK_EXCEEDS_DURATION]: {
trigger: TriggerType.EXCEEDS_DURATION,
resourceType: ResourceType.Task,
label: "The Runtime For Any Task Exceeds Some Duration",
label: "The runtime for any task exceeds some duration",
regexSelectors: taskRegexSelectors,
extraFields: [
{
Expand All @@ -339,7 +339,7 @@ export const projectTriggers: Trigger = {
[ProjectTriggers.SUCCESSFUL_TASK_RUNTIME_CHANGES]: {
trigger: TriggerType.RUNTIME_CHANGE,
resourceType: ResourceType.Task,
label: "The Runtime For a Successful Task Changes By Some Percentage",
label: "The runtime for a successful task changes by some percentage",
regexSelectors: taskRegexSelectors,
extraFields: [
{
Expand All @@ -355,41 +355,41 @@ export const projectTriggers: Trigger = {

export const waterfallTriggers: Trigger = {
[ProjectTriggers.ANY_VERSION_FINISHES]: {
trigger: TriggerType.FAMILY_OUTCOME,
trigger: TriggerType.OUTCOME,
resourceType: ResourceType.Version,
label: "Any Version Finishes",
label: "Any version finishes",
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_VERSION_FAILS]: {
trigger: TriggerType.FAMILY_FAILURE,
trigger: TriggerType.FAILURE,
resourceType: ResourceType.Version,
label: "Any Version Fails",
label: "Any version fails",
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_VERSION_SUCCEEDS]: {
trigger: TriggerType.FAMILY_SUCCESS,
trigger: TriggerType.SUCCESS,
resourceType: ResourceType.Version,
label: "Any Version Succeeds",
label: "Any version succeeds",
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_BUILD_FINISHES]: {
trigger: TriggerType.OUTCOME,
resourceType: ResourceType.Build,
label: "Any Build Finishes",
label: "Any build finishes",
regexSelectors: buildRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_BUILD_FAILS]: {
trigger: TriggerType.FAILURE,
resourceType: ResourceType.Build,
label: "Any Build Fails",
label: "Any build fails",
regexSelectors: buildRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
[ProjectTriggers.ANY_BUILD_SUCCEEDS]: {
trigger: TriggerType.SUCCESS,
resourceType: ResourceType.Build,
label: "Any Build Succeeds",
label: "Any build succeeds",
regexSelectors: buildRegexSelectors,
extraFields: [requesterSubscriberConfig],
},
Expand Down Expand Up @@ -418,24 +418,23 @@ export const triggerToCopy = {
[TriggerType.OUTCOME]: "Outcome",
[TriggerType.FAILURE]: "Failure",
[TriggerType.SUCCESS]: "Success",
[TriggerType.FAMILY_OUTCOME]: "Outcome",
[TriggerType.FAMILY_FAILURE]: "Failure",
[TriggerType.FAMILY_SUCCESS]: "Success",
[TriggerType.RUNTIME_CHANGE]: "Runtime changes by %",
[TriggerType.EXCEEDS_DURATION]: "Runtime exceeds duration",
[TriggerType.SUCCESSFUL_EXCEEDS_DURATION]: "Runtime exceeds duration",
[TriggerType.TASK_STARTED]: "Task started",
[TriggerType.TASK_FAILED_OR_BLOCKED]: "Task failed or blocked",
[TriggerType.REGRESSION]: "Regression",
[TriggerType.TEST_REGRESSION]: "Test regression",
[TriggerType.FIRST_FAILURE_BUILD]: "First failure",
[TriggerType.FIRST_FAILURE_BUILD]: "First failure in build",
[TriggerType.FIRST_FAILURE_VERSION]: "First failure in version",
[TriggerType.FIRST_FAILURE_VERSION_NAME]:
"First failure in version with name",
[TriggerType.FAMILY_OUTCOME]: "Outcome",
[TriggerType.FAMILY_FAILURE]: "Failure",
[TriggerType.FAMILY_SUCCESS]: "Success",
};

export const convertFamilyTrigger = (trigger: string) => {
export const fromFamilyTrigger = (trigger: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this function have a comment on why it's used?

Suggested change
export const fromFamilyTrigger = (trigger: string) => {
export const simplifyFamilyTrigger = (trigger: string) => {

switch (trigger) {
case TriggerType.FAMILY_OUTCOME:
return TriggerType.OUTCOME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useQuery } from "@apollo/client";
import styled from "@emotion/styled";
import { LeafyGreenTableRow } from "@leafygreen-ui/table";
import { size } from "constants/tokens";
import { convertFamilyTrigger } from "constants/triggers";
import { fromFamilyTrigger } from "constants/triggers";
import {
UserSubscriptionsQuery,
UserSubscriptionsQueryVariables,
Expand Down Expand Up @@ -61,7 +61,7 @@ const processSubscriptionData = (
// For this table's purposes, FAMILY_TRIGGER = TRIGGER. Convert all family triggers to their base type.
.map(({ trigger, ...subscription }) => ({
...subscription,
trigger: convertFamilyTrigger(trigger),
trigger: fromFamilyTrigger(trigger),
}))
// For subscriptions that contain regex selectors or additional trigger data, append an expandable section
.map((subscription) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("getGqlPayload", () => {
webhookSubscriber: undefined,
jiraIssueSubscriber: undefined,
},
trigger: "family-outcome",
trigger: "outcome",
trigger_data: { requester: "gitter_request" },
},
]);
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("getGqlPayload", () => {
webhookSubscriber: undefined,
jiraIssueSubscriber: undefined,
},
trigger: "family-failure",
trigger: "failure",
trigger_data: { requester: "ad_hoc" },
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("project data", () => {
jiraIssueSubscriber: undefined,
webhookSubscriber: undefined,
},
trigger: "family-outcome",
trigger: "outcome",
trigger_data: {
requester: "gitter_request",
},
Expand Down Expand Up @@ -143,7 +143,7 @@ describe("project data", () => {
},
webhookSubscriber: undefined,
},
trigger: "family-outcome",
trigger: "outcome",
trigger_data: {
requester: "gitter_request",
},
Expand Down Expand Up @@ -222,7 +222,7 @@ describe("project data", () => {
],
},
},
trigger: "family-outcome",
trigger: "outcome",
trigger_data: {
requester: "gitter_request",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProjectSettingsTabRoutes } from "constants/routes";
import { getSubscriberText } from "constants/subscription";
import { convertFamilyTrigger, projectTriggers } from "constants/triggers";
import { fromFamilyTrigger, projectTriggers } from "constants/triggers";
import {
BannerTheme,
ProjectInput,
Expand All @@ -16,7 +16,7 @@ type Tab = ProjectSettingsTabRoutes.Notifications;
const { toSentenceCase } = string;

const getTriggerText = (trigger: string, resourceType: string) => {
const convertedTrigger = convertFamilyTrigger(trigger);
const convertedTrigger = fromFamilyTrigger(trigger);
const triggerText =
resourceType && trigger
? `${toSentenceCase(resourceType)} ${convertedTrigger} `
Expand All @@ -25,9 +25,10 @@ const getTriggerText = (trigger: string, resourceType: string) => {
};

const getTriggerEnum = (trigger: string, resourceType: string) => {
const convertedTrigger = fromFamilyTrigger(trigger);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you improve the variable naming for convertedTrigger. The family conversion logic may also do well in the resolver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resolver is a good idea! I will file a ticket for it -- shouldn't be too difficult of a change!

const triggerEnum = Object.keys(projectTriggers).find(
(t) =>
projectTriggers[t].trigger === trigger &&
projectTriggers[t].trigger === convertedTrigger &&
projectTriggers[t].resourceType === resourceType
);
return triggerEnum;
Expand Down
Loading