Swadhin Biswas feat(web): add repo insights, packages, releases, and review UIs · 3/6/2026
a4239f1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import { useEffect, useMemo, useState } from "react";
import {
CartesianGrid,
Legend,
Line,
LineChart,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from "recharts";
type MergeFrequencyPoint = {
date?: string;
week?: string;
mergeCount: number;
};
type MergeFrequencyResponse = {
success: boolean;
data?: {
bucket: "day" | "week";
days: number;
points: MergeFrequencyPoint[];
forecastPoints?: number;
forecast?: MergeFrequencyPoint[];
forecastMethod?: string;
};
};
type Props = {
owner: string;
repo: string;
};
export function MergeFrequencyPanel({ owner, repo }: Props) {
const [bucket, setBucket] = useState<"day" | "week">("week");
const [days, setDays] = useState<number>(84);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string>("");
const [points, setPoints] = useState<MergeFrequencyPoint[]>([]);
const [forecast, setForecast] = useState<MergeFrequencyPoint[]>([]);
useEffect(() => {
const controller = new AbortController();
async function load() {
setLoading(true);
setError("");
try {
const response = await fetch(
`/api/repos/${owner}/${repo}/analytics/merge-frequency?bucket=${bucket}&days=${days}&forecastPoints=6`,
{ signal: controller.signal }
);
if (!response.ok) {
throw new Error("Failed to load merge frequency analytics");
}
const payload = (await response.json()) as MergeFrequencyResponse;
setPoints(payload.data?.points || []);
setForecast(payload.data?.forecast || []);
} catch (err) {
if ((err as Error).name === "AbortError") return;
setError("Unable to load merge frequency data");
} finally {
setLoading(false);
}
}
load();
return () => controller.abort();
}, [owner, repo, bucket, days]);
const chartData = useMemo(() => {
const historical = points.map((point) => ({
label: point.date || point.week || "",
merged: point.mergeCount,
forecast: null as number | null,
segment: "historical",
}));
if (!forecast.length) {
return historical;
}
const bridgeLabel = forecast[0]?.date || forecast[0]?.week || "";
const bridgeValue = historical.length ? historical[historical.length - 1]?.merged : null;
const forecastRows = forecast.map((point, index) => ({
label: point.date || point.week || `future-${index}`,
merged: null as number | null,
forecast: point.mergeCount,
segment: "forecast",
}));
// Add an overlap point so dashed line starts from last historical value.
if (bridgeValue !== null && bridgeLabel) {
forecastRows.unshift({
label: bridgeLabel,
merged: null,
forecast: bridgeValue,
segment: "forecast",
});
}
return [...historical, ...forecastRows];
}, [points, forecast]);
const avgMergeCount = useMemo(() => {
if (!points.length) return 0;
const total = points.reduce((sum, point) => sum + point.mergeCount, 0);
return Math.round((total / points.length) * 100) / 100;
}, [points]);
return (
<section className="rounded-lg border bg-card p-6 shadow-sm">
<div className="mb-4 flex flex-wrap items-center justify-between gap-3">
<div>
<h3 className="text-lg font-semibold">Merge Frequency Trend</h3>
<p className="text-sm text-muted-foreground">
Historical merge cadence with short-range forecast.
</p>
</div>
<div className="flex items-center gap-2">
<select
className="rounded border border-border bg-background px-2 py-1 text-sm"
value={bucket}
onChange={(event) => setBucket(event.target.value as "day" | "week")}
>
<option value="day">Daily</option>
<option value="week">Weekly</option>
</select>
<select
className="rounded border border-border bg-background px-2 py-1 text-sm"
value={days}
onChange={(event) => setDays(Number(event.target.value))}
>
<option value={30}>30d</option>
<option value={84}>84d</option>
<option value={180}>180d</option>
</select>
</div>
</div>
<div className="mb-4 grid gap-3 sm:grid-cols-3">
<div className="rounded border border-border bg-muted/30 p-3">
<div className="text-xs text-muted-foreground">Average merged</div>
<div className="text-lg font-semibold">{avgMergeCount}</div>
</div>
<div className="rounded border border-border bg-muted/30 p-3">
<div className="text-xs text-muted-foreground">Last period</div>
<div className="text-lg font-semibold">{points[points.length - 1]?.mergeCount ?? 0}</div>
</div>
<div className="rounded border border-border bg-muted/30 p-3">
<div className="text-xs text-muted-foreground">Forecast horizon</div>
<div className="text-lg font-semibold">{forecast.length ? `${forecast.length} ${bucket}s` : "0"}</div>
</div>
</div>
<div className="h-[320px] w-full">
{loading ? (
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">Loading merge frequency...</div>
) : error ? (
<div className="flex h-full items-center justify-center text-sm text-red-600">{error}</div>
) : (
<ResponsiveContainer width="100%" height="100%">
<LineChart data={chartData} margin={{ top: 5, right: 20, bottom: 5, left: 0 }}>
<CartesianGrid strokeDasharray="3 3" opacity={0.1} />
<XAxis
dataKey="label"
tick={{ fontSize: 12 }}
tickFormatter={(value) => {
if (typeof value !== "string") return "";
if (value.includes("-W")) return value;
const parsed = new Date(`${value}T00:00:00.000Z`);
if (Number.isNaN(parsed.getTime())) return value;
return parsed.toLocaleDateString(undefined, { month: "short", day: "numeric" });
}}
/>
<YAxis allowDecimals={false} />
<Tooltip
contentStyle={{
backgroundColor: "hsl(var(--popover))",
borderColor: "hsl(var(--border))",
color: "hsl(var(--popover-foreground))",
}}
/>
<Legend />
<Line
type="monotone"
dataKey="merged"
name="Merged PRs"
stroke="hsl(var(--chart-2))"
strokeWidth={2}
dot={false}
connectNulls={false}
/>
<Line
type="monotone"
dataKey="forecast"
name="Forecast"
stroke="hsl(var(--chart-4))"
strokeWidth={2}
dot={false}
strokeDasharray="5 5"
connectNulls={false}
/>
</LineChart>
</ResponsiveContainer>
)}
</div>
</section>
);
}