From b430b320188162496bc912f0e8656bbf8de418da Mon Sep 17 00:00:00 2001 From: Malik Hadjri <19805673+hadjri@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:01:03 -0400 Subject: [PATCH] EVG-20987 Add support for push level trigger links (#2098) --- src/components/CommitChartLabel/index.tsx | 19 ++++++++----- src/constants/routes.ts | 28 +++++++++++++++++++ src/gql/fragments/upstreamProject.graphql | 2 ++ src/gql/generated/types.ts | 12 ++++++++ .../InactiveCommits.stories.tsx | 2 ++ src/pages/commits/InactiveCommits/index.tsx | 16 ++++++----- src/pages/version/Metadata.tsx | 19 ++++++++----- src/types/triggers.ts | 1 + 8 files changed, 78 insertions(+), 21 deletions(-) diff --git a/src/components/CommitChartLabel/index.tsx b/src/components/CommitChartLabel/index.tsx index ebae349275..6f22f32c23 100644 --- a/src/components/CommitChartLabel/index.tsx +++ b/src/components/CommitChartLabel/index.tsx @@ -4,11 +4,10 @@ import { Body, BodyProps, InlineCode } from "@leafygreen-ui/typography"; import { Link } from "react-router-dom"; import ExpandedText from "components/ExpandedText"; import { StyledRouterLink } from "components/styles"; -import { getVersionRoute, getTaskRoute } from "constants/routes"; +import { getVersionRoute, getTriggerRoute } from "constants/routes"; import { size, zIndex } from "constants/tokens"; import { UpstreamProjectFragment, GitTag } from "gql/generated/types"; import { useSpruceConfig, useDateFormat } from "hooks"; -import { ProjectTriggerLevel } from "types/triggers"; import { shortenGithash } from "utils/string"; import { jiraLinkify } from "utils/string/jiraLinkify"; @@ -46,7 +45,10 @@ const CommitChartLabel: React.FC = ({ const spruceConfig = useSpruceConfig(); const jiraHost = spruceConfig?.jira?.host; const { + owner: upstreamOwner, project: upstreamProjectIdentifier, + repo: upstreamRepo, + revision: upstreamRevision, task: upstreamTask, triggerType, version: upstreamVersion, @@ -72,11 +74,14 @@ const CommitChartLabel: React.FC = ({ Triggered from:{" "} {upstreamProjectIdentifier} diff --git a/src/constants/routes.ts b/src/constants/routes.ts index 6f8305ea0e..92643e9044 100644 --- a/src/constants/routes.ts +++ b/src/constants/routes.ts @@ -1,6 +1,8 @@ +import { getGithubCommitUrl } from "constants/externalResources"; import { TestStatus, HistoryQueryParams } from "types/history"; import { PatchTab } from "types/patch"; import { PatchTasksQueryParams, TaskTab } from "types/task"; +import { ProjectTriggerLevel } from "types/triggers"; import { queryString, array } from "utils"; const { toArray } = array; @@ -310,3 +312,29 @@ export const getTaskHistoryRoute = ( selectedCommit ); }; + +interface GetTriggerRouteParams { + triggerType: string; + upstreamTask: any; + upstreamVersion: any; + upstreamRevision: string; + upstreamOwner: string; + upstreamRepo: string; +} + +export const getTriggerRoute = ({ + triggerType, + upstreamOwner, + upstreamRepo, + upstreamRevision, + upstreamTask, + upstreamVersion, +}: GetTriggerRouteParams) => { + if (triggerType === ProjectTriggerLevel.TASK) { + return getTaskRoute(upstreamTask.id); + } + if (triggerType === ProjectTriggerLevel.PUSH) { + return getGithubCommitUrl(upstreamOwner, upstreamRepo, upstreamRevision); + } + return getVersionRoute(upstreamVersion.id); +}; diff --git a/src/gql/fragments/upstreamProject.graphql b/src/gql/fragments/upstreamProject.graphql index e3d7ceed8d..86754ecbe1 100644 --- a/src/gql/fragments/upstreamProject.graphql +++ b/src/gql/fragments/upstreamProject.graphql @@ -1,7 +1,9 @@ fragment UpstreamProject on Version { upstreamProject { + owner project repo + revision task { execution id diff --git a/src/gql/generated/types.ts b/src/gql/generated/types.ts index bd327e9cbe..b7b565d995 100644 --- a/src/gql/generated/types.ts +++ b/src/gql/generated/types.ts @@ -4414,8 +4414,10 @@ export type UpstreamProjectFragment = { __typename?: "Version"; upstreamProject?: { __typename?: "UpstreamProject"; + owner: string; project: string; repo: string; + revision: string; triggerID: string; triggerType: string; task?: { __typename?: "Task"; execution: number; id: string } | null; @@ -6114,8 +6116,10 @@ export type MainlineCommitsForHistoryQuery = { }> | null; upstreamProject?: { __typename?: "UpstreamProject"; + owner: string; project: string; repo: string; + revision: string; triggerID: string; triggerType: string; task?: { __typename?: "Task"; execution: number; id: string } | null; @@ -6149,8 +6153,10 @@ export type MainlineCommitsForHistoryQuery = { }> | null; upstreamProject?: { __typename?: "UpstreamProject"; + owner: string; project: string; repo: string; + revision: string; triggerID: string; triggerType: string; task?: { __typename?: "Task"; execution: number; id: string } | null; @@ -6188,8 +6194,10 @@ export type MainlineCommitsQuery = { revision: string; upstreamProject?: { __typename?: "UpstreamProject"; + owner: string; project: string; repo: string; + revision: string; triggerID: string; triggerType: string; task?: { __typename?: "Task"; execution: number; id: string } | null; @@ -6245,8 +6253,10 @@ export type MainlineCommitsQuery = { } | null; upstreamProject?: { __typename?: "UpstreamProject"; + owner: string; project: string; repo: string; + revision: string; triggerID: string; triggerType: string; task?: { __typename?: "Task"; execution: number; id: string } | null; @@ -8819,8 +8829,10 @@ export type VersionQuery = { } | null; upstreamProject?: { __typename?: "UpstreamProject"; + owner: string; project: string; repo: string; + revision: string; triggerID: string; triggerType: string; task?: { __typename?: "Task"; execution: number; id: string } | null; diff --git a/src/pages/commits/InactiveCommits/InactiveCommits.stories.tsx b/src/pages/commits/InactiveCommits/InactiveCommits.stories.tsx index bcd30f817c..6b5dc941c4 100644 --- a/src/pages/commits/InactiveCommits/InactiveCommits.stories.tsx +++ b/src/pages/commits/InactiveCommits/InactiveCommits.stories.tsx @@ -23,6 +23,8 @@ const versions: CommitRolledUpVersions = [ revision: "4337c33fa4a0d5c747a1115f0853b5f70e46f112", ignored: false, upstreamProject: { + owner: "evergreen", + revision: "4337c33fa4a0d5c747a1115f0853b5f70e46f112", triggerID: "123", triggerType: "task", repo: "evergreen-ci", diff --git a/src/pages/commits/InactiveCommits/index.tsx b/src/pages/commits/InactiveCommits/index.tsx index 1e03188ad6..6e7528f4d6 100644 --- a/src/pages/commits/InactiveCommits/index.tsx +++ b/src/pages/commits/InactiveCommits/index.tsx @@ -7,11 +7,10 @@ import { useProjectHealthAnalytics } from "analytics/projectHealth/useProjectHea import { DisplayModal } from "components/DisplayModal"; import Icon from "components/Icon"; import { StyledRouterLink } from "components/styles"; -import { getVersionRoute, getTaskRoute } from "constants/routes"; +import { getVersionRoute, getTriggerRoute } from "constants/routes"; import { size, zIndex, fontSize } from "constants/tokens"; import { useSpruceConfig, useDateFormat } from "hooks"; import { CommitRolledUpVersions } from "types/commits"; -import { ProjectTriggerLevel } from "types/triggers"; import { Unpacked } from "types/utils"; import { string } from "utils"; import { jiraLinkify } from "utils/string/jiraLinkify"; @@ -157,11 +156,14 @@ const CommitCopy: React.FC = ({ isTooltip, v }) => { <> Triggered from:{" "} {v.upstreamProject.project} diff --git a/src/pages/version/Metadata.tsx b/src/pages/version/Metadata.tsx index cd3ee2c3f7..7249a00c7a 100644 --- a/src/pages/version/Metadata.tsx +++ b/src/pages/version/Metadata.tsx @@ -11,12 +11,11 @@ import { getGithubCommitUrl } from "constants/externalResources"; import { getCommitQueueRoute, getProjectPatchesRoute, - getTaskRoute, + getTriggerRoute, getVersionRoute, } from "constants/routes"; import { VersionQuery } from "gql/generated/types"; import { useDateFormat } from "hooks"; -import { ProjectTriggerLevel } from "types/triggers"; import { string } from "utils"; import { formatZeroIndexForDisplay } from "utils/numbers"; import ManifestBlob from "./ManifestBlob"; @@ -56,7 +55,10 @@ export const Metadata: React.FC = ({ loading, version }) => { const { commitQueuePosition } = patch || {}; const { makespan, timeTaken } = versionTiming || {}; const { + owner: upstreamOwner, project: upstreamProjectIdentifier, + repo: upstreamRepo, + revision: upstreamRevision, task: upstreamTask, triggerType, version: upstreamVersion, @@ -169,11 +171,14 @@ export const Metadata: React.FC = ({ loading, version }) => { Triggered from:{" "} {upstreamProjectIdentifier} diff --git a/src/types/triggers.ts b/src/types/triggers.ts index ad5396eb13..1ba9d1c51a 100644 --- a/src/types/triggers.ts +++ b/src/types/triggers.ts @@ -10,6 +10,7 @@ export enum ResourceType { export enum ProjectTriggerLevel { TASK = "task", BUILD = "build", + PUSH = "push", } export enum TriggerType {