feat(github): surface pull request merge queue status (#2928)

This commit is contained in:
Carlos Florêncio
2026-08-22 19:51:59 +00:00
committed by GitHub
parent 26ef699b00
commit 690a1ec3fe
51 changed files with 2306 additions and 166 deletions
@@ -9,6 +9,8 @@ import type { PRFeedback, TaskPR } from "@/lib/types/github";
import { getPRFeedback } from "@/lib/api/domains/github-api";
import { PRDetailPanelComponent } from "./pr-detail-panel";
const BOT_COMMENTS_LABEL = "Bot comments (1)";
vi.mock("@/lib/api/domains/github-api", async (importOriginal) => {
const actual = await importOriginal<typeof import("@/lib/api/domains/github-api")>();
return {
@@ -58,14 +60,14 @@ function makePR(overrides: Partial<TaskPR> = {}): TaskPR {
};
}
function makeFeedback(pr: TaskPR, botCommentBody: string): PRFeedback {
function makeFeedback(pr: TaskPR, botCommentBody: string, state = "open"): PRFeedback {
return {
pr: {
number: pr.pr_number,
title: pr.pr_title,
url: pr.pr_url,
html_url: pr.pr_url,
state: "open",
state,
head_branch: pr.head_branch,
base_branch: pr.base_branch,
author_login: pr.author_login,
@@ -161,8 +163,8 @@ describe("PRDetailPanelComponent — task switch on the singleton legacy panel",
const { getStoreApi } = renderPanel(taskState("task-1", "session-1", [pr1]));
// Task 1: expand the bot-comments disclosure.
await waitFor(() => expect(screen.getByText("Bot comments (1)")).toBeTruthy());
fireEvent.click(screen.getByText("Bot comments (1)"));
await waitFor(() => expect(screen.getByText(BOT_COMMENTS_LABEL)).toBeTruthy());
fireEvent.click(screen.getByText(BOT_COMMENTS_LABEL));
await waitFor(() => expect(screen.getByText("PR 1 bot comment")).toBeTruthy());
// Switch to a different task whose PR also has exactly one bot comment —
@@ -175,10 +177,24 @@ describe("PRDetailPanelComponent — task switch on the singleton legacy panel",
}));
});
await waitFor(() => expect(screen.getByText("Bot comments (1)")).toBeTruthy());
await waitFor(() => expect(screen.getByText(BOT_COMMENTS_LABEL)).toBeTruthy());
// Task 2's bot comment must stay collapsed by default, not inherit task 1's
// expanded disclosure state.
expect(screen.queryByText("PR 2 bot comment")).toBeNull();
expect(screen.queryByText("PR 1 bot comment")).toBeNull();
});
it("does not show a stale queue notice after live feedback closes the PR", async () => {
const pr = makePR({
merge_queue_state: "queued",
merge_queue_position: 2,
merge_queue_estimated_time_to_merge_seconds: 120,
});
vi.mocked(getPRFeedback).mockResolvedValue(makeFeedback(pr, "Closed PR", "closed"));
renderPanel(taskState("task-1", "session-1", [pr]));
await waitFor(() => expect(screen.getByText(BOT_COMMENTS_LABEL)).toBeTruthy());
expect(screen.queryByTestId("pr-merge-queue-status")).toBeNull();
});
});
+15 -9
View File
@@ -22,6 +22,7 @@ import { submitPRReview } from "@/lib/api/domains/github-pr-api";
import type { TaskPR, PRFeedback } from "@/lib/types/github";
import { PRMergeButton } from "./pr-merge-button";
import { PRMergeabilityNotice, buildConflictResolutionMessage } from "./pr-mergeability-notice";
import { hasActiveMergeQueueEntry, PRMergeQueueStatus } from "./pr-merge-queue-status";
import { usePRScopedReviewRequest } from "./use-pr-scoped-review-request";
// --- Dockview panel wrapper ---
@@ -426,6 +427,7 @@ export function PRDetailContent({ taskPR, sessionId }: { taskPR: TaskPR; session
const isDraft = feedback?.pr.draft ?? false;
const isMergeable = feedback?.pr.mergeable ?? true;
const mergeableState = feedback?.pr.mergeable_state ?? taskPR.mergeable_state;
const displayPR = { ...taskPR, state: liveState };
return (
<ChangeRequestDetail
@@ -449,15 +451,19 @@ export function PRDetailContent({ taskPR, sessionId }: { taskPR: TaskPR; session
</>
}
notice={
<PRMergeabilityNotice
state={mergeableState}
mergeable={isMergeable}
isDraft={isDraft}
prState={liveState}
baseBranch={taskPR.base_branch}
onResolveConflicts={onResolveConflicts}
resolveDisabled={conflictQueued}
/>
hasActiveMergeQueueEntry(displayPR) ? (
<PRMergeQueueStatus pr={displayPR} />
) : (
<PRMergeabilityNotice
state={mergeableState}
mergeable={isMergeable}
isDraft={isDraft}
prState={liveState}
baseBranch={taskPR.base_branch}
onResolveConflicts={onResolveConflicts}
resolveDisabled={conflictQueued}
/>
)
}
/>
);
@@ -0,0 +1,156 @@
import { afterEach, describe, expect, it } from "vitest";
import { cleanup, render } from "@testing-library/react";
import type { TaskPR } from "@/lib/types/github";
import { aggregatePRStatusColor, getPRStatusColor } from "./pr-task-icon";
import {
describeMergeQueueEstimate,
getMergeQueueSummaryStatus,
PRMergeQueueStatus,
} from "./pr-merge-queue-status";
const QUEUE_STATUS_TEST_ID = "pr-merge-queue-status";
function makePR(overrides: Partial<TaskPR> = {}): TaskPR {
return {
id: "id",
task_id: "task-1",
owner: "acme",
repo: "demo",
pr_number: 42,
pr_url: "",
pr_title: "Queued PR",
head_branch: "feature",
base_branch: "main",
author_login: "alice",
state: "open",
review_state: "",
checks_state: "success",
mergeable_state: "blocked",
review_count: 0,
pending_review_count: 0,
comment_count: 0,
unresolved_review_threads: 0,
checks_total: 1,
checks_passing: 1,
additions: 0,
deletions: 0,
created_at: "",
merged_at: null,
closed_at: null,
last_synced_at: null,
updated_at: "",
...overrides,
};
}
afterEach(() => cleanup());
describe("merge queue estimate formatting", () => {
it.each([
[undefined, { kind: "none" }],
[null, { kind: "none" }],
[0, { kind: "sub_minute" }],
[59, { kind: "sub_minute" }],
[60, { kind: "minutes", minutes: 1 }],
[61, { kind: "minutes", minutes: 2 }],
[3600, { kind: "minutes", minutes: 60 }],
])("describes %s seconds without exposing raw provider units", (seconds, expected) => {
expect(describeMergeQueueEstimate(seconds)).toEqual(expected);
});
});
describe("merge queue status", () => {
it.each([
["queued", "queue_queued"],
["awaiting_checks", "queue_awaiting_checks"],
["mergeable", "queue_mergeable"],
["unmergeable", "queue_unmergeable"],
["locked", "queue_locked"],
["future_state", "queue_queued"],
])("maps %s to %s", (state, expected) => {
expect(getMergeQueueSummaryStatus(state)).toBe(expected);
});
it("uses generic queued copy for a future provider state", () => {
const { getByTestId } = render(
<PRMergeQueueStatus pr={makePR({ merge_queue_state: "future_state" })} />,
);
expect(getByTestId(QUEUE_STATUS_TEST_ID).textContent).toContain("Merge queue: Queued");
});
it("renders queue state, one-based position, and an available estimate", () => {
const { getByTestId } = render(
<PRMergeQueueStatus
pr={makePR({
merge_queue_state: "queued",
merge_queue_position: 4,
merge_queue_estimated_time_to_merge_seconds: 61,
})}
/>,
);
const notice = getByTestId(QUEUE_STATUS_TEST_ID);
expect(notice.textContent).toContain("Merge queue: Queued");
expect(notice.textContent).toContain("Position 4");
expect(notice.textContent).toContain("2 minutes");
});
it("renders a localized sub-minute estimate", () => {
const { getByTestId } = render(
<PRMergeQueueStatus
pr={makePR({
merge_queue_state: "awaiting_checks",
merge_queue_position: 1,
merge_queue_estimated_time_to_merge_seconds: 59,
})}
/>,
);
expect(getByTestId(QUEUE_STATUS_TEST_ID).textContent).toContain("less than a minute");
});
it("renders nothing for an empty or terminal queue state", () => {
const empty = render(<PRMergeQueueStatus pr={makePR()} />);
expect(empty.queryByTestId(QUEUE_STATUS_TEST_ID)).toBeNull();
empty.unmount();
const terminal = render(
<PRMergeQueueStatus pr={makePR({ state: "closed", merge_queue_state: "queued" })} />,
);
expect(terminal.queryByTestId(QUEUE_STATUS_TEST_ID)).toBeNull();
});
it("keeps terminal colors ahead of a stale queue entry", () => {
expect(getPRStatusColor(makePR({ state: "merged", merge_queue_state: "queued" }))).toBe(
"text-purple-500",
);
expect(getPRStatusColor(makePR({ state: "closed", merge_queue_state: "queued" }))).toBe(
"text-red-500",
);
});
it("keeps queue color ahead of other non-terminal PR states", () => {
const overrides: Array<Partial<TaskPR>> = [
{ checks_state: "failure" },
{ review_state: "changes_requested" },
{ mergeable_state: "dirty" },
{ mergeable_state: "behind" },
{ mergeable_state: "draft" },
];
for (const override of overrides) {
expect(getPRStatusColor(makePR({ merge_queue_state: "queued", ...override }))).toBe(
"text-[#966600]",
);
}
});
it("lets a failing sibling outrank a queued PR in the aggregate", () => {
expect(
aggregatePRStatusColor([
makePR({ merge_queue_state: "queued" }),
makePR({ pr_number: 2, checks_state: "failure" }),
]),
).toBe("text-red-500");
});
});
@@ -0,0 +1,122 @@
"use client";
import { IconClockHour4 } from "@tabler/icons-react";
import { useTranslation } from "react-i18next";
import type { ChangeRequestTaskSummaryRowDetail } from "@/components/integrations/change-request-task-status-summary";
import type { TaskPR } from "@/lib/types/github";
export type MergeQueueSummaryStatus =
| "queue_queued"
| "queue_awaiting_checks"
| "queue_mergeable"
| "queue_unmergeable"
| "queue_locked";
export type MergeQueueEstimateDescription =
| { kind: "none" }
| { kind: "sub_minute" }
| { kind: "minutes"; minutes: number };
const KNOWN_QUEUE_STATES: Record<string, MergeQueueSummaryStatus> = {
queued: "queue_queued",
awaiting_checks: "queue_awaiting_checks",
mergeable: "queue_mergeable",
unmergeable: "queue_unmergeable",
locked: "queue_locked",
};
const QUEUE_STATE_LABEL_KEYS: Record<MergeQueueSummaryStatus, string> = {
queue_queued: "github:mergeQueueStateQueued",
queue_awaiting_checks: "github:mergeQueueStateAwaitingChecks",
queue_mergeable: "github:mergeQueueStateMergeable",
queue_unmergeable: "github:mergeQueueStateUnmergeable",
queue_locked: "github:mergeQueueStateLocked",
};
export function normalizeMergeQueueState(state: string | null | undefined): string {
return state?.trim().toLowerCase() ?? "";
}
export function getMergeQueueSummaryStatus(
state: string | null | undefined,
): MergeQueueSummaryStatus {
return KNOWN_QUEUE_STATES[normalizeMergeQueueState(state)] ?? "queue_queued";
}
export function describeMergeQueueEstimate(
seconds: number | null | undefined,
): MergeQueueEstimateDescription {
if (seconds == null || !Number.isFinite(seconds) || seconds < 0) {
return { kind: "none" };
}
if (seconds < 60) return { kind: "sub_minute" };
return { kind: "minutes", minutes: Math.ceil(seconds / 60) };
}
function validQueuePosition(position: number | null | undefined): number | null {
if (position == null || !Number.isInteger(position) || position < 1) return null;
return position;
}
export function getMergeQueueSummaryDetail(
position: number | null | undefined,
estimateSeconds: number | null | undefined,
): ChangeRequestTaskSummaryRowDetail | undefined {
const queuePosition = validQueuePosition(position);
const estimate = describeMergeQueueEstimate(estimateSeconds);
if (queuePosition != null) {
if (estimate.kind === "sub_minute") {
return {
key: "github:mergeQueuePositionAndSubMinuteEstimate",
values: { position: queuePosition },
};
}
if (estimate.kind === "minutes") {
return {
key: "github:mergeQueuePositionAndEstimate",
values: { position: queuePosition, count: estimate.minutes },
};
}
return { key: "github:mergeQueuePosition", values: { position: queuePosition } };
}
if (estimate.kind === "sub_minute") {
return { key: "github:mergeQueueSubMinuteEstimate" };
}
if (estimate.kind === "minutes") {
return { key: "github:mergeQueueEstimate", values: { count: estimate.minutes } };
}
return undefined;
}
export function hasActiveMergeQueueEntry(pr: Pick<TaskPR, "state" | "merge_queue_state">): boolean {
return pr.state === "open" && normalizeMergeQueueState(pr.merge_queue_state) !== "";
}
export function PRMergeQueueStatus({ pr }: { pr: TaskPR }) {
const { t } = useTranslation();
if (!hasActiveMergeQueueEntry(pr)) return null;
const status = getMergeQueueSummaryStatus(pr.merge_queue_state);
const stateLabel = t(QUEUE_STATE_LABEL_KEYS[status]);
const detail = getMergeQueueSummaryDetail(
pr.merge_queue_position,
pr.merge_queue_estimated_time_to_merge_seconds,
);
return (
<div
data-testid="pr-merge-queue-status"
className="flex items-start gap-1.5 px-1 py-1 text-xs text-[#966600]"
>
<IconClockHour4 className="mt-0.5 h-3.5 w-3.5 shrink-0" aria-hidden="true" />
<div className="min-w-0">
<div className="font-medium">{t("github:mergeQueueStatus", { state: stateLabel })}</div>
{detail && (
<p className="text-[11px] leading-snug text-muted-foreground">
{t(detail.key, detail.values)}
</p>
)}
</div>
</div>
);
}
@@ -9,6 +9,8 @@ import type { AppState } from "@/lib/state/store";
import type { MergeableState, TaskPR } from "@/lib/types/github";
const SESSION_ID = "sess-1";
const QUEUE_STATUS_TEST_ID = "pr-merge-queue-status";
const CONFLICT_BANNER_TEST_ID = "pr-conflict-banner";
function makePR(overrides: Partial<TaskPR> = {}): TaskPR {
return {
@@ -71,7 +73,7 @@ afterEach(() => cleanup());
describe("PRMergeabilityRow", () => {
it("shows the conflict banner with a Resolve conflicts CTA for a dirty PR", () => {
const { queryByTestId } = renderRow(makePR({ mergeable_state: "dirty" }));
expect(queryByTestId("pr-conflict-banner")).not.toBeNull();
expect(queryByTestId(CONFLICT_BANNER_TEST_ID)).not.toBeNull();
expect(queryByTestId("pr-resolve-conflicts-button")).not.toBeNull();
});
@@ -79,7 +81,7 @@ describe("PRMergeabilityRow", () => {
const { container, queryByTestId } = renderRow(
makePR({ mergeable_state: "blocked", checks_state: "failure" }),
);
expect(queryByTestId("pr-conflict-banner")).toBeNull();
expect(queryByTestId(CONFLICT_BANNER_TEST_ID)).toBeNull();
expect(queryByTestId("pr-blocked-note")).not.toBeNull();
expect(queryByTestId("pr-blocked-shield-icon")).not.toBeNull();
expect(container.textContent).toContain("Blocked by branch protection");
@@ -147,11 +149,49 @@ describe("PRMergeabilityRow", () => {
it("hides the Resolve conflicts CTA when there is no active session", () => {
const { queryByTestId } = renderRow(makePR({ mergeable_state: "dirty" }), null);
// Banner still surfaces the conflict, but the CTA needs a session to target.
expect(queryByTestId("pr-conflict-banner")).not.toBeNull();
expect(queryByTestId(CONFLICT_BANNER_TEST_ID)).not.toBeNull();
expect(queryByTestId("pr-resolve-conflicts-button")).toBeNull();
});
});
describe("PRMergeabilityRow queue state", () => {
it("replaces mergeability with queue state and metadata for an active entry", () => {
const { getByTestId, queryByTestId, container } = renderRow(
makePR({
merge_queue_state: "mergeable",
merge_queue_position: 2,
merge_queue_estimated_time_to_merge_seconds: 120,
mergeable_state: "dirty",
}),
);
expect(getByTestId(QUEUE_STATUS_TEST_ID)).not.toBeNull();
expect(container.textContent).toContain("Merge queue: Mergeable");
expect(container.textContent).toContain("Position 2");
expect(container.textContent).toContain("2 minutes");
expect(queryByTestId(CONFLICT_BANNER_TEST_ID)).toBeNull();
});
it("keeps queue state visible when position and estimate are absent", () => {
const { getByTestId, container } = renderRow(
makePR({ merge_queue_state: "locked", mergeable_state: "blocked" }),
);
expect(getByTestId(QUEUE_STATUS_TEST_ID)).not.toBeNull();
expect(container.textContent).toContain("Merge queue: Locked");
expect(container.textContent).not.toContain("Position");
});
it("does not show a stale queue entry after a terminal transition", () => {
const { queryByTestId, getByTestId } = renderRow(
makePR({ state: "merged", merge_queue_state: "queued" }),
);
expect(queryByTestId(QUEUE_STATUS_TEST_ID)).toBeNull();
expect(getByTestId("row-host").childElementCount).toBe(0);
});
});
describe("blockedReason", () => {
it("names the approval shortfall when required reviews aren't met", () => {
expect(blockedReason(makePR({ required_reviews: 2, review_count: 0 }), t)).toContain(
@@ -12,6 +12,7 @@ import {
import type { TaskPR } from "@/lib/types/github";
import { isPRAwaitingReview, isPRWaitingOnBranchProtection } from "./pr-task-icon";
import { PRMergeabilityNotice, buildConflictResolutionMessage } from "./pr-mergeability-notice";
import { hasActiveMergeQueueEntry, PRMergeQueueStatus } from "./pr-merge-queue-status";
import { useTranslation } from "react-i18next";
/**
@@ -78,6 +79,7 @@ function useResolveConflicts(pr: TaskPR): {
export function PRMergeabilityRow({ pr }: { pr: TaskPR }) {
const { t } = useTranslation();
const { onResolveConflicts, conflictQueued } = useResolveConflicts(pr);
if (hasActiveMergeQueueEntry(pr)) return <PRMergeQueueStatus pr={pr} />;
// "blocked" gets a richer note than the bare chip: it explains *why* the
// merge is gated. But when the block is only an outstanding requested review,
// stay silent — the review row above already conveys that and the
@@ -582,6 +582,37 @@ describe("aggregateChipStatus", () => {
const failing = makePR({ id: "fail", checks_state: "failure" });
expect(aggregateChipStatus([conflict, failing])).toBe("failed");
});
it("uses the dedicated queued chip status", () => {
expect(aggregateChipStatus([makePR({ merge_queue_state: "queued" })])).toBe("queued");
});
it("keeps queued status ahead of dirty mergeability", () => {
expect(
aggregateChipStatus([makePR({ merge_queue_state: "queued", mergeable_state: "dirty" })]),
).toBe("queued");
});
it("keeps queued status ahead of failure on the same PR", () => {
expect(
aggregateChipStatus([
makePR({
merge_queue_state: "queued",
checks_state: "failure",
review_state: "changes_requested",
}),
]),
).toBe("queued");
});
it("lets a failing sibling retain chip priority over a queued PR", () => {
expect(
aggregateChipStatus([
makePR({ merge_queue_state: "queued" }),
makePR({ pr_number: 2, checks_state: "failure" }),
]),
).toBe("failed");
});
});
describe("PRStatusChip — multiple PRs", () => {
+16 -1
View File
@@ -27,6 +27,7 @@ import {
isPRDraft,
isPRAwaitingReview,
isPRReadyToMerge,
isPRQueued,
isPRWaitingOnBranchProtection,
pickDefaultPR,
} from "@/components/github/pr-task-icon";
@@ -60,6 +61,7 @@ type ChipStatus =
| "behind"
| "draft"
| "waiting"
| "queued"
| "in_progress"
| "neutral";
type TriggerRef = { current: HTMLButtonElement | null };
@@ -83,13 +85,17 @@ function focusAfterCollapse(triggerRef?: TriggerRef) {
}
function chipStatus(pr: TaskPR): ChipStatus {
// Terminal PRs are filtered before this helper. For active PRs, queue
// membership is the authoritative non-terminal state, so stale failure,
// draft, or mergeability fields cannot override the queue indicator.
if (isPRQueued(pr)) return "queued";
if (pr.review_state === "changes_requested" || pr.checks_state === "failure") return "failed";
if (isPRDraft(pr)) return "draft";
// Merge conflicts / behind-base block the merge even when CI is green — the
// chip must never read as a passed check in that case. Mirrors
// getPRStatusColor + PRStatusIcon (dirty = red, behind = amber).
if (pr.mergeable_state === "dirty") return "conflict";
if (pr.mergeable_state === "behind") return "behind";
if (isPRDraft(pr)) return "draft";
// Pending checks / pending review must beat checks_state === "success" so a
// PR with all checks green but reviewers still outstanding renders as
// in-progress, not passed. Without this order, the chip flips to green the
@@ -114,6 +120,7 @@ const CHIP_STATUS_RANK: Record<ChipStatus, number> = {
conflict: 5,
blocked: 4,
behind: 3,
queued: 2.5,
draft: 0.5,
in_progress: 2,
waiting: 1.5,
@@ -450,6 +457,14 @@ function ChipStatusGlyph({ status }: { status: ChipStatus }) {
return <IconAlertTriangleFilled className="h-3.5 w-3.5 text-red-500" aria-hidden="true" />;
case "behind":
return <IconAlertTriangleFilled className="h-3.5 w-3.5 text-yellow-500" aria-hidden="true" />;
case "queued":
return (
<IconClock
data-testid="pr-status-glyph-queued"
className="h-3.5 w-3.5 text-[#966600]"
aria-hidden="true"
/>
);
case "draft":
return <IconPointFilled className="h-3.5 w-3.5 text-muted-foreground" aria-hidden="true" />;
case "blocked":
@@ -18,6 +18,7 @@ const RED_500 = "text-red-500";
const YELLOW_500 = "text-yellow-500";
const EMERALD_400 = "text-emerald-400";
const GREEN_500 = "text-green-500";
const QUEUED = "text-[#966600]";
const PURPLE_500 = "text-purple-500";
const MUTED_FOREGROUND = "text-muted-foreground";
@@ -60,12 +61,25 @@ describe("getPRAggregateStatusColor", () => {
["pending", YELLOW_500],
["awaiting_review", SKY_400],
["ready", EMERALD_400],
["queued", QUEUED],
["passing", GREEN_500],
["merged", PURPLE_500],
["open", MUTED_FOREGROUND],
])("maps %s to %s", (state, color) => {
expect(getPRAggregateStatusColor(state)).toBe(color);
});
it("uses the dedicated merge-queue color for an open queued PR", () => {
expect(
getPRStatusColor(
makePR({
merge_queue_state: "queued",
checks_state: "success",
mergeable_state: "blocked",
}),
),
).toBe(QUEUED);
});
});
describe("isPRReadyToMerge", () => {
@@ -20,6 +20,7 @@ const RED_500 = CHANGE_REQUEST_STATUS_COLORS.danger;
const YELLOW_500 = CHANGE_REQUEST_STATUS_COLORS.warning;
const SKY_400 = CHANGE_REQUEST_STATUS_COLORS.review;
const EMERALD_400 = CHANGE_REQUEST_STATUS_COLORS.ready;
const QUEUED = CHANGE_REQUEST_STATUS_COLORS.queued;
const GREEN_500 = CHANGE_REQUEST_STATUS_COLORS.passing;
/** Maps the task-level PR projection to the same visual language as live PRs. */
@@ -86,6 +87,14 @@ export function isPRDraft(pr: TaskPR): boolean {
return pr.state === "open" && pr.mergeable_state === "draft";
}
export function isPRQueued(pr: TaskPR): boolean {
return (
pr.state === "open" &&
typeof pr.merge_queue_state === "string" &&
pr.merge_queue_state.trim() !== ""
);
}
// CI passed but the PR is still waiting on human review (reviewers requested
// or pending review state). Distinct from yellow "CI running". An approved
// PR with extra reviewers still pending also counts — GitHub's
@@ -126,6 +135,10 @@ function openMergeBlockerColor(pr: TaskPR): string | null {
export function getPRStatusColor(pr: TaskPR): string {
if (pr.state === "merged") return PURPLE_500;
if (pr.state === "closed") return RED_500;
// An active queue entry is the authoritative non-terminal state. Queue
// membership must remain visible while provider checks or mergeability
// fields hydrate, even when those fields still describe an earlier state.
if (isPRQueued(pr)) return QUEUED;
if (pr.review_state === "changes_requested" || pr.checks_state === "failure") {
return RED_500;
}
@@ -134,3 +134,60 @@ describe("structured PR task status summary", () => {
expect(summary.rows).toEqual([{ kind: "merge", status: "draft", tone: "muted" }]);
});
});
describe("queued PR task status summaries", () => {
it("replaces mergeability with queue semantics and metadata", () => {
const summary = derivePRTaskStatusSummary(
makePR({
merge_queue_state: "awaiting_checks",
merge_queue_position: 3,
merge_queue_estimated_time_to_merge_seconds: 61,
mergeable_state: "dirty",
}),
false,
);
expect(summary.rows.at(-1)).toEqual({
kind: "merge",
status: "queue_awaiting_checks",
tone: "queued",
detail: {
key: "github:mergeQueuePositionAndEstimate",
values: { position: 3, count: 2 },
},
});
});
it("uses generic queued copy for an unknown provider enum", () => {
const summary = derivePRTaskStatusSummary(
makePR({
merge_queue_state: "future_provider_state",
merge_queue_position: 1,
}),
false,
);
expect(summary.rows.at(-1)).toEqual({
kind: "merge",
status: "queue_queued",
tone: "queued",
detail: {
key: "github:mergeQueuePosition",
values: { position: 1 },
},
});
});
it("does not surface queue metadata for a terminal PR", () => {
const summary = derivePRTaskStatusSummary(
makePR({
state: "merged",
merge_queue_state: "queued",
merge_queue_position: 1,
}),
false,
);
expect(summary.rows).not.toContainEqual(expect.objectContaining({ tone: "queued" }));
});
});
@@ -1,6 +1,11 @@
"use client";
import type { TaskPR } from "@/lib/types/github";
import {
getMergeQueueSummaryDetail,
getMergeQueueSummaryStatus,
hasActiveMergeQueueEntry,
} from "./pr-merge-queue-status";
import {
ChangeRequestTaskStatusSummary,
type ChangeRequestTaskStatusSummaryData,
@@ -53,6 +58,17 @@ function deriveCIRow(checksState: string): PRTaskSummaryRow | null {
function deriveMergeRow(pr: TaskPR, readyToMerge: boolean): PRTaskSummaryRow | null {
if (pr.state !== "open") return null;
if (hasActiveMergeQueueEntry(pr)) {
return {
kind: "merge",
status: getMergeQueueSummaryStatus(pr.merge_queue_state),
tone: "queued",
detail: getMergeQueueSummaryDetail(
pr.merge_queue_position,
pr.merge_queue_estimated_time_to_merge_seconds,
),
};
}
if (pr.mergeable_state === "draft") {
return { kind: "merge", status: "draft", tone: "muted" };
}