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

DEVPROD-4166 Add breaking commits option in previous commits dropdown #2254

Merged
merged 24 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0e412ab
build: add to gql query
ZackarySantana Feb 9, 2024
1dfaa64
feat: add breaking commit in to selector
ZackarySantana Feb 9, 2024
e66d46e
fix: add last passing task condition
ZackarySantana Feb 9, 2024
347ca0d
refactor: rename previous commits to relevant commits
ZackarySantana Feb 9, 2024
86d2080
fix: revert update
ZackarySantana Feb 13, 2024
4fa8c5d
refactor: baseStatus -> status
ZackarySantana Feb 20, 2024
c1d95e0
doc: last breaking task query
ZackarySantana Feb 20, 2024
190bbe9
fix: use task order rather than version
ZackarySantana Feb 20, 2024
7435611
fix: tests
ZackarySantana Feb 20, 2024
81abcc0
feat: add some tests
ZackarySantana Feb 21, 2024
7018fcb
fix: switch status check to be not failed
ZackarySantana Feb 23, 2024
a546058
refactor: add permalink to comment
ZackarySantana Feb 27, 2024
b4ee498
refactor: capitalize relevant commits
ZackarySantana Feb 27, 2024
3edc9bd
fix: github link to backend code
ZackarySantana Feb 27, 2024
e0885c3
refactor: previous commit data tag
ZackarySantana Feb 27, 2024
77d27e5
fix: redo pre commit hook
ZackarySantana Feb 27, 2024
f1865c9
fix: revert precommit
ZackarySantana Feb 27, 2024
a34965f
fix: revert it no history
ZackarySantana Feb 27, 2024
718962d
refactor: rename files
ZackarySantana Feb 27, 2024
42bdc5d
Merge branch 'main' into DEVPROD-4166
ZackarySantana Feb 27, 2024
e4af068
fix: skip order number in test
ZackarySantana Feb 28, 2024
a13877b
fix: test cases
ZackarySantana Feb 28, 2024
ef76d29
fix: test
ZackarySantana Feb 29, 2024
c71b07f
Merge branch 'main' into DEVPROD-4166
ZackarySantana Feb 29, 2024
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
2 changes: 1 addition & 1 deletion src/analytics/task/useTaskAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "gql/generated/types";
import { TASK } from "gql/queries";
import { useQueryParam } from "hooks/useQueryParam";
import { CommitType } from "pages/task/actionButtons/previousCommits/types";
import { CommitType } from "pages/task/actionButtons/relevantCommits/types";
import { RequiredQueryParams, LogTypes } from "types/task";

type LogViewer = "raw" | "html" | "parsley";
Expand Down
2 changes: 2 additions & 0 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5406,6 +5406,7 @@ export type BaseVersionAndTaskQuery = {
execution: number;
id: string;
projectIdentifier?: string | null;
status: string;
baseTask?: {
__typename?: "Task";
execution: number;
Expand Down Expand Up @@ -6170,6 +6171,7 @@ export type LastMainlineCommitQuery = {
__typename?: "Task";
execution: number;
id: string;
order: number;
status: string;
} | null> | null;
} | null> | null;
Expand Down
1 change: 1 addition & 0 deletions src/gql/queries/base-version-and-task.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ query BaseVersionAndTask($taskId: String!) {
execution
id
projectIdentifier
status
versionMetadata {
baseVersion {
id
Expand Down
1 change: 1 addition & 0 deletions src/gql/queries/last-mainline-commit.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ query LastMainlineCommit(
tasks {
execution
id
order
status
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/task/ActionButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
import { useLGButtonRouterLink } from "hooks/useLGButtonRouterLink";
import { useQueryParam } from "hooks/useQueryParam";
import { TaskStatus } from "types/task";
import { PreviousCommits } from "./actionButtons/previousCommits";
import { RelevantCommits } from "./actionButtons/relevantCommits";
import { TaskNotificationModal } from "./actionButtons/TaskNotificationModal";

interface Props {
Expand Down Expand Up @@ -254,7 +254,7 @@ export const ActionButtons: React.FC<Props> = ({
<PageButtonRow>
{!isExecutionTask && (
<>
<PreviousCommits taskId={taskId} />
<RelevantCommits taskId={taskId} />
<Button
size="small"
data-cy="task-history"
Expand Down
9 changes: 0 additions & 9 deletions src/pages/task/actionButtons/previousCommits/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import {
import { BASE_VERSION_AND_TASK, LAST_MAINLINE_COMMIT } from "gql/queries";
import { renderWithRouterMatch, screen, userEvent, waitFor } from "test_utils";
import { ApolloMock } from "types/gql";
import { PreviousCommits } from ".";
import { RelevantCommits } from ".";

describe("previous commits", () => {
describe("relevant commits", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add a test in here for the new "breaking commit" button? :0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added to the existing tests instead of a new one and added some data! I think it makes sense to test it like the others but I am new to testing and if you feel otherwise I can switch it up

// Patch and mainline commit behavior only have a significant difference when it comes to determining
// the base or previous task. Patch gets the base task directly from BASE_VERSION_AND_TASK, while
// mainline commits needs to run another query LAST_MAINLINE_COMMIT to get previous task.
describe("patch specific", () => {
it("the button is disabled when there is no base task", async () => {
const { Component } = RenderFakeToastContext(
<MockedProvider mocks={[getPatchTaskWithNoBaseTask]}>
<PreviousCommits taskId="t1" />
<RelevantCommits taskId="t1" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);
await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});
Expand All @@ -37,14 +37,14 @@ describe("previous commits", () => {
<MockedProvider
mocks={[getMainlineTaskWithBaseVersion, getNullParentTask]}
>
<PreviousCommits taskId="t4" />
<RelevantCommits taskId="t4" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});
Expand All @@ -54,14 +54,14 @@ describe("previous commits", () => {
<MockedProvider
mocks={[getMainlineTaskWithBaseVersion, getParentTaskWithError]}
>
<PreviousCommits taskId="t4" />
<RelevantCommits taskId="t4" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});
Expand All @@ -70,19 +70,19 @@ describe("previous commits", () => {
it("the button is disabled when no base version exists", async () => {
const { Component } = RenderFakeToastContext(
<MockedProvider mocks={[getPatchTaskWithNoBaseVersion]}>
<PreviousCommits taskId="t3" />
<RelevantCommits taskId="t3" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await waitFor(() => {
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "true");
});
});

it("when base task is passing, all dropdown items generate the same link", async () => {
it("when base task is passing, last passing, base commit, and last executed dropdown items generate the same link and breaking commit is disabled", async () => {
const user = userEvent.setup();
const { Component } = RenderFakeToastContext(
<MockedProvider
Expand All @@ -92,16 +92,16 @@ describe("previous commits", () => {
getLastExecutedVersion,
]}
>
<PreviousCommits taskId="t1" />
<RelevantCommits taskId="t1" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await screen.findByRole("button", { name: "Previous commits" });
await screen.findByRole("button", { name: "Relevant commits" });
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "false");
await user.click(screen.getByRole("button", { name: "Previous commits" }));
await user.click(screen.getByRole("button", { name: "Relevant commits" }));
await waitFor(() => {
expect(screen.getByRole("menu")).toBeVisible();
});
Expand All @@ -115,24 +115,27 @@ describe("previous commits", () => {
expect(
screen.getByRole("menuitem", { name: "Go to last executed version" }),
).toHaveAttribute("href", baseTaskHref);
expect(
screen.getByRole("menuitem", { name: "Go to breaking commit" }),
).toHaveAttribute("aria-disabled", "true");
});

it("when base task is failing, 'Go to base commit' and 'Go to last executed' dropdown items generate the same link and 'Go to last passing version' will be different.", async () => {
it("when base task is failing, 'Go to base commit' and 'Go to last executed' dropdown items generate the same link and 'Go to last passing version' will be different and 'Go to breaking commit' will be disabled", async () => {
const user = userEvent.setup();
const { Component } = RenderFakeToastContext(
<MockedProvider
mocks={[getPatchTaskWithFailingBaseTask, getLastPassingVersion]}
>
<PreviousCommits taskId="t1" />
<RelevantCommits taskId="t1" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await screen.findByRole("button", { name: "Previous commits" });
await screen.findByRole("button", { name: "Relevant commits" });
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "false");
await user.click(screen.getByRole("button", { name: "Previous commits" }));
await user.click(screen.getByRole("button", { name: "Relevant commits" }));
await waitFor(() => {
expect(screen.getByRole("menu")).toBeVisible();
});
Expand All @@ -146,28 +149,32 @@ describe("previous commits", () => {
expect(
screen.getByRole("menuitem", { name: "Go to last executed version" }),
).toHaveAttribute("href", baseTaskHref);
expect(
screen.getByRole("menuitem", { name: "Go to breaking commit" }),
).toHaveAttribute("aria-disabled", "true");
});

it("when base task is not in a finished state, the last executed & passing task is not the same as the base commit", async () => {
it("when base task is not in a finished state, the last executed, passing task, and breaking task is not the same as the base commit", async () => {
const user = userEvent.setup();
const { Component } = RenderFakeToastContext(
<MockedProvider
mocks={[
getPatchTaskWithRunningBaseTask,
getLastPassingVersion,
getLastExecutedVersion,
getBreakingCommit,
]}
>
<PreviousCommits taskId="t3" />
<RelevantCommits taskId="t3" />
</MockedProvider>,
);
renderWithRouterMatch(<Component />);

await screen.findByRole("button", { name: "Previous commits" });
await screen.findByRole("button", { name: "Relevant commits" });
expect(
screen.getByRole("button", { name: "Previous commits" }),
screen.getByRole("button", { name: "Relevant commits" }),
).toHaveAttribute("aria-disabled", "false");
await user.click(screen.getByRole("button", { name: "Previous commits" }));
await user.click(screen.getByRole("button", { name: "Relevant commits" }));
await waitFor(() => {
expect(screen.getByRole("menu")).toBeVisible();
});
Expand All @@ -181,6 +188,9 @@ describe("previous commits", () => {
expect(
screen.getByRole("menuitem", { name: "Go to last executed version" }),
).toHaveAttribute("href", "/task/last_executed_task");
expect(
screen.getByRole("menuitem", { name: "Go to breaking commit" }),
).toHaveAttribute("href", "/task/breaking_commit");
});
});

Expand All @@ -206,6 +216,7 @@ const getPatchTaskWithSuccessfulBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -246,6 +257,7 @@ const getPatchTaskWithRunningBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "started",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -286,6 +298,7 @@ const getPatchTaskWithFailingBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -326,6 +339,7 @@ const getPatchTaskWithNoBaseVersion: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: null,
id: "versionMetadataId",
Expand All @@ -339,6 +353,54 @@ const getPatchTaskWithNoBaseVersion: ApolloMock<
},
};

const getBreakingCommit: ApolloMock<
LastMainlineCommitQuery,
LastMainlineCommitQueryVariables
> = {
request: {
query: LAST_MAINLINE_COMMIT,
variables: {
projectIdentifier: "evergreen",
skipOrderNumber: 3678,
buildVariantOptions: {
tasks: ["^lint-agent$"],
variants: ["^lint$"],
statuses: ["failed"],
},
},
},
result: {
data: {
mainlineCommits: {
versions: [
{
version: {
id: "evergreen_44110b57c6977bf3557009193628c9389772163f2",
buildVariants: [
{
tasks: [
{
id: "breaking_commit",
execution: 0,
order: 3677,
status: "failed",
__typename: "Task",
},
],
__typename: "GroupedBuildVariant",
},
],
__typename: "Version",
},
__typename: "MainlineCommitVersion",
},
],
__typename: "MainlineCommits",
},
},
},
};

const getLastPassingVersion: ApolloMock<
LastMainlineCommitQuery,
LastMainlineCommitQueryVariables
Expand Down Expand Up @@ -368,6 +430,7 @@ const getLastPassingVersion: ApolloMock<
{
id: "last_passing_task",
execution: 0,
order: 3676,
status: "success",
__typename: "Task",
},
Expand Down Expand Up @@ -425,6 +488,7 @@ const getLastExecutedVersion: ApolloMock<
{
id: "last_executed_task",
execution: 0,
order: 3676,
status: "failed",
__typename: "Task",
},
Expand Down Expand Up @@ -462,6 +526,7 @@ const getPatchTaskWithNoBaseTask: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down Expand Up @@ -498,6 +563,7 @@ const getMainlineTaskWithBaseVersion: ApolloMock<
displayName: "lint-agent",
buildVariant: "lint",
projectIdentifier: "evergreen",
status: "success",
versionMetadata: {
baseVersion: {
id: "baseVersion",
Expand Down
Loading
Loading