From 1cc14fc2714eff11d7d4a3bd5042ad5e79acc781 Mon Sep 17 00:00:00 2001 From: Brian Ketelsen Date: Wed, 1 Apr 2026 03:15:07 +0000 Subject: [PATCH] refactor: consolidate duplicate queue category display constants into layout.ts Extract CATEGORY_DISPLAY from queue.ts and the equivalent CATEGORY_LABELS/CATEGORY_COLORS from repos.ts into a single shared constant in layout.ts, eliminating data duplication that required lockstep updates across two files. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/pages/layout.ts | 11 +++++++++++ src/pages/queue.ts | 12 +----------- src/pages/repos.ts | 27 ++++----------------------- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/pages/layout.ts b/src/pages/layout.ts index 5a14229..23146e7 100644 --- a/src/pages/layout.ts +++ b/src/pages/layout.ts @@ -1,7 +1,18 @@ import { GITHUB_OWNERS } from "../config.js"; +import type { QueueCategory } from "../github.js"; export type Theme = "dark" | "light" | "system"; +export const CATEGORY_DISPLAY: Record = { + "ready": { label: "Ready", color: "0e8a16" }, + "needs-refinement": { label: "Needs Refinement", color: "d876e3" }, + "refined": { label: "Refined", color: "0075ca" }, + "needs-review-addressing": { label: "Needs Review Addressing", color: "e4e669" }, + "auto-mergeable": { label: "Auto-Mergeable", color: "0e8a16" }, + "needs-triage": { label: "Needs Triage", color: "d73a49" }, + "needs-plan-review": { label: "Needs Plan Review", color: "c5def5" }, +}; + const LIGHT_THEME_VARS = ` --bg: #ffffff; --bg-secondary: #f6f8fa; diff --git a/src/pages/queue.ts b/src/pages/queue.ts index 4793dfb..a2242dc 100644 --- a/src/pages/queue.ts +++ b/src/pages/queue.ts @@ -1,17 +1,7 @@ import type { Theme } from "./layout.js"; -import { PAGE_CSS, escapeHtml, repoShortName, itemLogsUrl, formatRelativeTime, htmlOpenTag, buildNav, THEME_SCRIPT, TOAST_SCRIPT, siteTitle } from "./layout.js"; +import { PAGE_CSS, escapeHtml, repoShortName, itemLogsUrl, formatRelativeTime, htmlOpenTag, buildNav, THEME_SCRIPT, TOAST_SCRIPT, siteTitle, CATEGORY_DISPLAY } from "./layout.js"; import type { QueueItem, QueueCategory } from "../github.js"; -const CATEGORY_DISPLAY: Record = { - "ready": { label: "Ready", color: "0e8a16" }, - "needs-refinement": { label: "Needs Refinement", color: "d876e3" }, - "refined": { label: "Refined", color: "0075ca" }, - "needs-review-addressing": { label: "Needs Review Addressing", color: "e4e669" }, - "auto-mergeable": { label: "Auto-Mergeable", color: "0e8a16" }, - "needs-triage": { label: "Needs Triage", color: "d73a49" }, - "needs-plan-review": { label: "Needs Plan Review", color: "c5def5" }, -}; - const CATEGORY_PRIORITY: Record = { "needs-review-addressing": 0, "auto-mergeable": 1, diff --git a/src/pages/repos.ts b/src/pages/repos.ts index 4f5e936..01047d8 100644 --- a/src/pages/repos.ts +++ b/src/pages/repos.ts @@ -1,32 +1,13 @@ import type { Theme } from "./layout.js"; -import { PAGE_CSS, escapeHtml, htmlOpenTag, buildNav, THEME_SCRIPT, TOAST_SCRIPT, siteTitle, itemLogsUrl, formatRelativeTime } from "./layout.js"; +import { PAGE_CSS, escapeHtml, htmlOpenTag, buildNav, THEME_SCRIPT, TOAST_SCRIPT, siteTitle, itemLogsUrl, formatRelativeTime, CATEGORY_DISPLAY } from "./layout.js"; import type { QueueItem, QueueCategory } from "../github.js"; import type { Repo } from "../config.js"; import type { Task } from "../db.js"; -const CATEGORY_LABELS: Record = { - "ready": "Ready", - "needs-refinement": "Needs Refinement", - "refined": "Refined", - "needs-review-addressing": "Needs Review Addressing", - "auto-mergeable": "Auto-Mergeable", - "needs-triage": "Needs Triage", - "needs-plan-review": "Needs Plan Review", -}; - -const CATEGORY_COLORS: Record = { - "ready": "0e8a16", - "needs-refinement": "d876e3", - "refined": "0075ca", - "needs-review-addressing": "e4e669", - "auto-mergeable": "0e8a16", - "needs-triage": "d73a49", - "needs-plan-review": "c5def5", -}; - function statusBadge(category: QueueCategory): string { - const label = CATEGORY_LABELS[category] ?? category; - const color = CATEGORY_COLORS[category] ?? "30363d"; + const display = CATEGORY_DISPLAY[category] ?? { label: category, color: "30363d" }; + const label = display.label; + const color = display.color; const bg = `#${color}`; const text = parseInt(color, 16) > 0x7fffff ? "#000" : "#fff"; return `${escapeHtml(label)}`;