Skip to content

Commit

Permalink
EVG-20987 Add support for push level trigger links (evergreen-ci#2098)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadjri authored Oct 18, 2023
1 parent 4616497 commit b430b32
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 21 deletions.
19 changes: 12 additions & 7 deletions src/components/CommitChartLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -46,7 +45,10 @@ const CommitChartLabel: React.FC<Props> = ({
const spruceConfig = useSpruceConfig();
const jiraHost = spruceConfig?.jira?.host;
const {
owner: upstreamOwner,
project: upstreamProjectIdentifier,
repo: upstreamRepo,
revision: upstreamRevision,
task: upstreamTask,
triggerType,
version: upstreamVersion,
Expand All @@ -72,11 +74,14 @@ const CommitChartLabel: React.FC<Props> = ({
Triggered from:{" "}
<StyledRouterLink
onClick={onClickUpstreamProject}
to={
triggerType === ProjectTriggerLevel.TASK
? getTaskRoute(upstreamTask.id)
: getVersionRoute(upstreamVersion.id)
}
to={getTriggerRoute({
triggerType,
upstreamTask,
upstreamVersion,
upstreamRevision,
upstreamOwner,
upstreamRepo,
})}
>
{upstreamProjectIdentifier}
</StyledRouterLink>
Expand Down
28 changes: 28 additions & 0 deletions src/constants/routes.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
};
2 changes: 2 additions & 0 deletions src/gql/fragments/upstreamProject.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
fragment UpstreamProject on Version {
upstreamProject {
owner
project
repo
revision
task {
execution
id
Expand Down
12 changes: 12 additions & 0 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/commits/InactiveCommits/InactiveCommits.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const versions: CommitRolledUpVersions = [
revision: "4337c33fa4a0d5c747a1115f0853b5f70e46f112",
ignored: false,
upstreamProject: {
owner: "evergreen",
revision: "4337c33fa4a0d5c747a1115f0853b5f70e46f112",
triggerID: "123",
triggerType: "task",
repo: "evergreen-ci",
Expand Down
16 changes: 9 additions & 7 deletions src/pages/commits/InactiveCommits/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -157,11 +156,14 @@ const CommitCopy: React.FC<CommitCopyProps> = ({ isTooltip, v }) => {
<>
Triggered from:{" "}
<StyledRouterLink
to={
v.upstreamProject.triggerType === ProjectTriggerLevel.TASK
? getTaskRoute(v.upstreamProject.task.id)
: getVersionRoute(v.upstreamProject.version.id)
}
to={getTriggerRoute({
upstreamOwner: v.upstreamProject.owner,
upstreamRepo: v.upstreamProject.repo,
triggerType: v.upstreamProject.triggerType,
upstreamRevision: v.upstreamProject.revision,
upstreamTask: v.upstreamProject.task,
upstreamVersion: v.upstreamProject.version,
})}
>
{v.upstreamProject.project}
</StyledRouterLink>
Expand Down
19 changes: 12 additions & 7 deletions src/pages/version/Metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -56,7 +55,10 @@ export const Metadata: React.FC<Props> = ({ loading, version }) => {
const { commitQueuePosition } = patch || {};
const { makespan, timeTaken } = versionTiming || {};
const {
owner: upstreamOwner,
project: upstreamProjectIdentifier,
repo: upstreamRepo,
revision: upstreamRevision,
task: upstreamTask,
triggerType,
version: upstreamVersion,
Expand Down Expand Up @@ -169,11 +171,14 @@ export const Metadata: React.FC<Props> = ({ loading, version }) => {
<MetadataItem>
Triggered from:{" "}
<StyledRouterLink
to={
triggerType === ProjectTriggerLevel.TASK
? getTaskRoute(upstreamTask.id)
: getVersionRoute(upstreamVersion.id)
}
to={getTriggerRoute({
triggerType,
upstreamTask,
upstreamVersion,
upstreamRevision,
upstreamOwner,
upstreamRepo,
})}
>
{upstreamProjectIdentifier}
</StyledRouterLink>
Expand Down
1 change: 1 addition & 0 deletions src/types/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum ResourceType {
export enum ProjectTriggerLevel {
TASK = "task",
BUILD = "build",
PUSH = "push",
}

export enum TriggerType {
Expand Down

0 comments on commit b430b32

Please sign in to comment.