feat: bound task status and session traffic (#2148)

This commit is contained in:
Carlos Florêncio
2026-08-02 16:06:14 +01:00
committed by GitHub
parent af764a227f
commit 554c33f24d
120 changed files with 8084 additions and 627 deletions
+31 -13
View File
@@ -1,6 +1,7 @@
import { describe, it, expect } from "vitest";
import {
aggregatePRStatusColor,
getPRAggregateStatusColor,
areAllOpenPRsReadyToMerge,
getPRStatusColor,
getPRTooltip,
@@ -12,6 +13,14 @@ import {
} from "./pr-task-icon";
import type { TaskPR } from "@/lib/types/github";
const SKY_400 = "text-sky-400";
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 PURPLE_500 = "text-purple-500";
const MUTED_FOREGROUND = "text-muted-foreground";
function makePR(overrides: Partial<TaskPR> = {}): TaskPR {
return {
id: "id",
@@ -45,10 +54,19 @@ function makePR(overrides: Partial<TaskPR> = {}): TaskPR {
};
}
const SKY_400 = "text-sky-400";
const RED_500 = "text-red-500";
const YELLOW_500 = "text-yellow-500";
const MUTED_FOREGROUND = "text-muted-foreground";
describe("getPRAggregateStatusColor", () => {
it.each([
["failure", RED_500],
["pending", YELLOW_500],
["awaiting_review", SKY_400],
["ready", EMERALD_400],
["passing", GREEN_500],
["merged", PURPLE_500],
["open", MUTED_FOREGROUND],
])("maps %s to %s", (state, color) => {
expect(getPRAggregateStatusColor(state)).toBe(color);
});
});
describe("isPRReadyToMerge", () => {
it("is true when open + approved + success + clean", () => {
@@ -241,7 +259,7 @@ describe("getPRStatusColor", () => {
checks_state: "success",
mergeable_state: "clean",
});
expect(getPRStatusColor(pr)).toBe("text-emerald-400");
expect(getPRStatusColor(pr)).toBe(EMERALD_400);
});
it("returns muted for approved+success but mergeable_state blocked (branch protection)", () => {
@@ -293,7 +311,7 @@ describe("getPRStatusColor", () => {
checks_state: "success",
mergeable_state: "",
});
expect(getPRStatusColor(pr)).toBe("text-green-500");
expect(getPRStatusColor(pr)).toBe(GREEN_500);
});
it("returns sky-400 when CI passed but review is pending", () => {
@@ -326,7 +344,7 @@ describe("getPRStatusColor", () => {
mergeable_state: "clean",
pending_review_count: 0,
});
expect(getPRStatusColor(pr)).toBe("text-emerald-400");
expect(getPRStatusColor(pr)).toBe(EMERALD_400);
});
it("returns red for changes_requested regardless of mergeable_state", () => {
@@ -345,7 +363,7 @@ describe("getPRStatusColor", () => {
});
it("returns purple for merged", () => {
expect(getPRStatusColor(makePR({ state: "merged" }))).toBe("text-purple-500");
expect(getPRStatusColor(makePR({ state: "merged" }))).toBe(PURPLE_500);
});
});
@@ -359,7 +377,7 @@ describe("getPRStatusColor — aggregate checks", () => {
checks_passing: 5,
mergeable_state: "",
});
expect(getPRStatusColor(pr)).toBe("text-green-500");
expect(getPRStatusColor(pr)).toBe(GREEN_500);
});
it("treats aggregate all-green counts as passed when no reviews are required", () => {
@@ -372,7 +390,7 @@ describe("getPRStatusColor — aggregate checks", () => {
checks_passing: 5,
mergeable_state: "",
});
expect(getPRStatusColor(pr)).toBe("text-green-500");
expect(getPRStatusColor(pr)).toBe(GREEN_500);
});
});
@@ -402,7 +420,7 @@ describe("getPRStatusColor — mergeability", () => {
it("ignores dirty/behind mergeable_state on terminal (merged) PRs", () => {
expect(getPRStatusColor(makePR({ state: "merged", mergeable_state: "dirty" }))).toBe(
"text-purple-500",
PURPLE_500,
);
});
});
@@ -514,7 +532,7 @@ describe("aggregatePRStatusColor", () => {
checks_state: "success",
mergeable_state: "clean",
});
expect(aggregatePRStatusColor([ready, ready])).toBe("text-emerald-400");
expect(aggregatePRStatusColor([ready, ready])).toBe(EMERALD_400);
});
it("yellow CI pending beats merged purple", () => {
@@ -546,7 +564,7 @@ describe("aggregatePRStatusColor", () => {
// so the result depends on which terminal state is present. Merged ranks
// 0 (purple), closed ranks 5 (red) — both paths need a guard.
const merged = makePR({ state: "merged" });
expect(aggregatePRStatusColor([merged, merged])).toBe("text-purple-500");
expect(aggregatePRStatusColor([merged, merged])).toBe(PURPLE_500);
const closed = makePR({ state: "closed" });
expect(aggregatePRStatusColor([closed, closed])).toBe(RED_500);
});
+46 -15
View File
@@ -7,16 +7,47 @@ import { useAppStore } from "@/components/state-provider";
import type { TaskPR } from "@/lib/types/github";
const MUTED_FOREGROUND = "text-muted-foreground";
const PURPLE_500 = "text-purple-500";
const RED_500 = "text-red-500";
const YELLOW_500 = "text-yellow-500";
const SKY_400 = "text-sky-400";
const EMERALD_400 = "text-emerald-400";
const GREEN_500 = "text-green-500";
/** Maps the task-level PR projection to the same visual language as live PRs. */
export function getPRAggregateStatusColor(state: string | null | undefined): string {
switch (state?.toLowerCase()) {
case "merged":
return PURPLE_500;
case "closed":
case "failure":
return RED_500;
case "pending":
return YELLOW_500;
case "awaiting_review":
return SKY_400;
case "ready":
return EMERALD_400;
case "passing":
return GREEN_500;
case "draft":
case "blocked":
case "neutral":
case "open":
default:
return MUTED_FOREGROUND;
}
}
const STATUS_RANK: Record<string, number> = {
// Higher = more attention-worthy. Drives the aggregated icon color when a
// task has multiple PRs (we surface the worst state).
"text-red-500": 5,
"text-yellow-500": 4,
"text-sky-400": 3,
"text-emerald-400": 2,
"text-green-500": 1,
"text-purple-500": 0,
[RED_500]: 5,
[YELLOW_500]: 4,
[SKY_400]: 3,
[EMERALD_400]: 2,
[GREEN_500]: 1,
[PURPLE_500]: 0,
[MUTED_FOREGROUND]: 0,
};
@@ -97,16 +128,16 @@ export function isPRWaitingOnBranchProtection(pr: TaskPR): boolean {
// awaiting-review, so an outstanding review still reads as sky.)
function openMergeBlockerColor(pr: TaskPR): string | null {
if (pr.state !== "open") return null;
if (pr.mergeable_state === "dirty") return "text-red-500";
if (pr.mergeable_state === "behind") return "text-yellow-500";
if (pr.mergeable_state === "dirty") return RED_500;
if (pr.mergeable_state === "behind") return YELLOW_500;
return null;
}
export function getPRStatusColor(pr: TaskPR): string {
if (pr.state === "merged") return "text-purple-500";
if (pr.state === "closed") return "text-red-500";
if (pr.state === "merged") return PURPLE_500;
if (pr.state === "closed") return RED_500;
if (pr.review_state === "changes_requested" || pr.checks_state === "failure") {
return "text-red-500";
return RED_500;
}
if (isPRDraft(pr)) {
return MUTED_FOREGROUND;
@@ -114,12 +145,12 @@ export function getPRStatusColor(pr: TaskPR): string {
const blockerColor = openMergeBlockerColor(pr);
if (blockerColor) return blockerColor;
if (isPRReadyToMerge(pr)) {
return "text-emerald-400";
return EMERALD_400;
}
// Check awaiting-review before the plain-green fallback so an approved PR
// with pending reviewers (1 of N required) doesn't read as fully approved.
if (isPRAwaitingReview(pr)) {
return "text-sky-400";
return SKY_400;
}
// Branch protection can be a normal repository-rule wait after CI has passed.
// Keep it muted so it doesn't read like a failure.
@@ -127,10 +158,10 @@ export function getPRStatusColor(pr: TaskPR): string {
return MUTED_FOREGROUND;
}
if (hasPRChecksPassedWithoutReviewWaitForDisplay(pr)) {
return "text-green-500";
return GREEN_500;
}
if (hasPRChecksInProgressForDisplay(pr) || pr.review_state === "pending") {
return "text-yellow-500";
return YELLOW_500;
}
return MUTED_FOREGROUND;
}