import { formatDuration, shortSha } from "@/lib/format"; import type { Run } from "@/lib/runs"; /** How long something ran (or has been running), or null if it hasn't started. */ export function runDuration(item: { startedAt: number | null; finishedAt: number | null }) { if (!item.startedAt) return null; return formatDuration((item.finishedAt ?? Date.now()) - item.startedAt); } /** What started a run: "Commit 1a2b3c4 pushed by ana", "Manually run by ana". */ export function triggerText(run: Run) { const by = run.actor ? ` by ${run.actor}` : ""; return run.event === "workflow_dispatch" ? `Manually run${by}` : `Commit ${shortSha(run.sha)} pushed${by}`; } export const refName = (ref: string) => ref.replace(/^refs\/(heads|tags)\//, "");