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

Commit

Permalink
Merge branch 'main' of https://github.com/evergreen-ci/spruce into EV…
Browse files Browse the repository at this point in the history
  • Loading branch information
sophstad committed Oct 19, 2023
2 parents 04b47fd + 26d091e commit 6963256
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spruce",
"version": "3.0.158",
"version": "3.0.159",
"private": true,
"scripts": {
"bootstrap-logkeeper": "./scripts/bootstrap-logkeeper.sh",
Expand Down
15 changes: 8 additions & 7 deletions src/analytics/task/useTaskAnalytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from "@apollo/client";
import { useParams, useLocation } from "react-router-dom";
import { useParams } from "react-router-dom";
import { useAnalyticsRoot } from "analytics/useAnalyticsRoot";
import {
SaveSubscriptionForUserMutationVariables,
Expand All @@ -9,11 +9,9 @@ import {
TestSortCategory,
} from "gql/generated/types";
import { TASK } from "gql/queries";
import { useQueryParam } from "hooks/useQueryParam";
import { CommitType } from "pages/task/actionButtons/previousCommits/types";
import { RequiredQueryParams, LogTypes } from "types/task";
import { queryString } from "utils";

const { parseQueryString } = queryString;

type LogViewer = "raw" | "html" | "parsley" | "lobster";
type Action =
Expand Down Expand Up @@ -61,16 +59,19 @@ type Action =
| { name: "Click Display Task Link" }
| { name: "Click Project Link" }
| { name: "Click See History Button" }
| {
name: "Click Task File Link";
parsleyAvailable: boolean;
fileName: string;
}
| { name: "Click Trace Link" }
| { name: "Click Trace Metrics Link" }
| { name: "Submit Previous Commit Selector"; type: CommitType };

export const useTaskAnalytics = () => {
const { id } = useParams<{ id: string }>();
const location = useLocation();

const parsed = parseQueryString(location.search);
const execution = Number(parsed[RequiredQueryParams.Execution]);
const [execution] = useQueryParam(RequiredQueryParams.Execution, 0);
const { data: eventData } = useQuery<TaskQuery, TaskQueryVariables>(TASK, {
variables: { taskId: id, execution },
fetchPolicy: "cache-first",
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export const GithubCommitQueueTab: React.FC<TabProps> = ({
<>
{!githubWebhooksEnabled && (
<Banner data-cy="disabled-webhook-banner" variant="warning">
GitHub features are disabled because webhooks are not enabled.
Webhooks are enabled after saving with a valid owner and repository.
GitHub features are disabled because the Evergreen GitHub App is not
installed on the saved owner/repo. Contact IT to install the App and
enable GitHub features.
</Banner>
)}
<BaseTab
Expand Down
21 changes: 18 additions & 3 deletions src/pages/task/taskTabs/FileTable/GroupedFileTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useRef } from "react";
import { useMemo, useRef } from "react";
import styled from "@emotion/styled";
import { useLeafyGreenTable, LGColumnDef } from "@leafygreen-ui/table/new";
import { Subtitle } from "@leafygreen-ui/typography";
import { useTaskAnalytics } from "analytics";
import { StyledLink } from "components/styles";
import { BaseTable } from "components/Table/BaseTable";
import { size } from "constants/tokens";
Expand All @@ -10,7 +11,9 @@ import { GroupedFiles } from "../types";

type GroupedFilesFile = Unpacked<GroupedFiles["files"]>;

const columns: LGColumnDef<GroupedFilesFile>[] = [
const columns = (
taskAnalytics: ReturnType<typeof useTaskAnalytics>
): LGColumnDef<GroupedFilesFile>[] => [
{
accessorKey: "name",
header: "Name",
Expand All @@ -21,6 +24,13 @@ const columns: LGColumnDef<GroupedFilesFile>[] = [
href={value.row.original.link}
data-cy="file-link"
target="_blank"
onClick={() => {
taskAnalytics.sendEvent({
name: "Click Task File Link",
parsleyAvailable: false,
fileName: value.getValue() as GroupedFilesFile["name"],
});
}}
>
{value.getValue()}
</StyledLink>
Expand All @@ -37,11 +47,16 @@ const GroupedFileTable: React.FC<GroupedFileTableProps> = ({
taskName,
}) => {
const tableContainerRef = useRef<HTMLDivElement>(null);
const taskAnalytics = useTaskAnalytics();

const memoizedColumns = useMemo(
() => columns(taskAnalytics),
[taskAnalytics]
);
const table = useLeafyGreenTable<GroupedFilesFile>({
containerRef: tableContainerRef,
data: files,
columns,
columns: memoizedColumns,
});

return (
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 6963256

Please sign in to comment.