diff --git a/plugins/github-pr-status/ui/PullRequestRowMetadata.test.tsx b/plugins/github-pr-status/ui/PullRequestRowMetadata.test.tsx new file mode 100644 index 0000000000..4eebf84583 --- /dev/null +++ b/plugins/github-pr-status/ui/PullRequestRowMetadata.test.tsx @@ -0,0 +1,157 @@ +// @vitest-environment jsdom + +import { cleanup, render, screen } from "@testing-library/react"; +import { installTestPluginRuntime } from "@get-bb/plugin-sdk/testing/app"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import type { PullRequest } from "../contract"; +import { PullRequestBadge } from "./PullRequestRowMetadata"; + +const pullRequest: PullRequest = { + number: 73, + title: "Update branch", + url: "https://github.com/acme/example/pull/73", + state: "open", + baseRefName: "main", + headRefName: "update", + updatedAt: "2026-11-05T12:00:00Z", + autoMerge: false, + inMergeQueue: false, + checks: { + state: "passing", + totalCount: 1, + passedCount: 1, + failedCount: 0, + pendingCount: 0, + }, + review: { state: "approved", reviewRequestCount: 0 }, + mergeability: { + state: "mergeable", + mergeStateStatus: "CLEAN", + mergeable: "MERGEABLE", + }, + attention: "ready_to_merge", +}; + +beforeEach(() => { + vi.stubGlobal("__bbPluginRuntime", undefined); + installTestPluginRuntime(); +}); + +afterEach(() => { + cleanup(); + vi.unstubAllGlobals(); +}); + +describe("thread row pull request badge", () => { + it.each<{ + name: string; + state: PullRequest["state"]; + attention: PullRequest["attention"]; + checks: PullRequest["checks"]["state"]; + review: PullRequest["review"]["state"]; + className: string; + }>([ + { + name: "requested changes", + state: "open", + attention: "changes_requested", + checks: "passing", + review: "changes_requested", + className: "text-destructive-text", + }, + { + name: "failing checks", + state: "open", + attention: "checks_failed", + checks: "failing", + review: "approved", + className: "text-warning-text", + }, + { + name: "running checks", + state: "open", + attention: "checks_pending", + checks: "pending", + review: "approved", + className: "text-timeline-accent", + }, + { + name: "ready to merge", + state: "open", + attention: "ready_to_merge", + checks: "passing", + review: "approved", + className: "text-success-foreground", + }, + { + name: "draft with failing checks", + state: "draft", + attention: "draft", + checks: "failing", + review: "none", + className: "text-subtle-foreground", + }, + { + name: "merged with stale failure", + state: "merged", + attention: "merged", + checks: "failing", + review: "changes_requested", + className: "text-pr-merged", + }, + { + name: "closed with stale pending checks", + state: "closed", + attention: "closed", + checks: "pending", + review: "approved", + className: "text-destructive-text", + }, + { + name: "changes requested with running checks", + state: "open", + attention: "changes_requested", + checks: "pending", + review: "changes_requested", + className: "text-destructive-text", + }, + { + name: "conflicts with running checks", + state: "open", + attention: "conflicts", + checks: "pending", + review: "approved", + className: "text-destructive-text", + }, + { + name: "review requested with running checks", + state: "open", + attention: "review_requested", + checks: "pending", + review: "review_required", + className: "text-timeline-accent", + }, + ])( + "colors the PR number for $name", + ({ state, attention, checks, review, className }) => { + render( + , + ); + expect(screen.getByText("#73").className).toBe(className); + }, + ); +}); diff --git a/plugins/github-pr-status/ui/PullRequestRowMetadata.tsx b/plugins/github-pr-status/ui/PullRequestRowMetadata.tsx index bdbbb0261a..abda04e8d6 100644 --- a/plugins/github-pr-status/ui/PullRequestRowMetadata.tsx +++ b/plugins/github-pr-status/ui/PullRequestRowMetadata.tsx @@ -53,6 +53,26 @@ function AttentionGlyph({ kind }: { kind: "blocked" | "running" }) { ); } +function pullRequestNumberClassName(pullRequest: PullRequest): string { + if (pullRequest.state === "draft") return "text-subtle-foreground"; + const state = PULL_REQUEST_STATE_DISPLAY[pullRequest.state]; + if (pullRequest.state !== "open") return state.className; + switch (pullRequest.attention) { + case "changes_requested": + case "conflicts": + case "blocked": + return "text-destructive-text"; + } + switch (getPullRequestGithubCheckStatus(pullRequest)) { + case "failure": + return "text-warning-text"; + case "pending": + return "text-timeline-accent"; + default: + return state.className; + } +} + export function PullRequestBadge({ pullRequest, }: { @@ -87,13 +107,7 @@ export function PullRequestBadge({ className="flex shrink-0 items-center gap-1 text-xs leading-3.5 tabular-nums" onPointerEnter={hovered ? undefined : () => setHovered(true)} > - + #{pullRequest.number} {glyph === null ? null : }