Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/app/(app)/maintainer/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link from 'next/link';
import { pingReviewers } from '@/app/actions/maintainer';
import { redirect } from 'next/navigation';
import { getServerSupabase } from '@/lib/supabase/server';
import { isUserMaintainer } from '@/lib/maintainer/detect';
Expand All @@ -8,6 +9,7 @@ import {
getMaintainerAnalyticsTrends,
getRepoHealthOverview,
getStaleIssues,
getStalePrs,
getFlaggedAccounts,
getTopContributors,
getInstallationSettings,
Expand All @@ -19,6 +21,7 @@ import {
type InstallationSettingsData,
type RepoHealthRow,
type StaleIssueRow,
type StalePrRow,
type ContributorRow,
type ReviewerLoadRow,
type NoiseBreakdown,
Expand All @@ -37,6 +40,7 @@ import { VerifyButton } from '../issues/verify-button';
import ExportCsvButton from './export-csv-button';
import QueueSettings from './queue-settings';
import { ResolveFlagButton } from './resolve-flag-button';
import { StalePrBanner } from './stale-pr-banner';
import { getContributorFunnel } from '@/app/actions/maintainer/analytics';
import type { ContributorFunnelData } from '@/app/actions/maintainer/types';
import { ContributorFunnel } from './contributor-funnel';
Expand Down Expand Up @@ -146,6 +150,8 @@ export default async function MaintainerPage({
const reviewerLoads: ReviewerLoadRow[] = isOk(reviewerLoadsRes) ? reviewerLoadsRes.data : [];
const maxLoad = reviewerLoads.length > 0 ? Math.max(...reviewerLoads.map((r) => r.prCount)) : 0;

const stalePrsRes = await getStalePrs({ installationId: activeInstallId });
const stalePrs: StalePrRow[] = isOk(stalePrsRes) ? stalePrsRes.data : [];
let noise: NoiseBreakdown = { valid: 0, spamAi: 0, other: 0, total: 0 };
if (settings.aiPrDetection) {
const noiseRes = await getNoiseBreakdown({ installationId: activeInstallId });
Expand Down Expand Up @@ -175,6 +181,7 @@ export default async function MaintainerPage({
return (
<div className="min-h-screen bg-zinc-950 px-6 py-12 text-white">
<div className="mx-auto max-w-5xl">
<StalePrBanner stalePrs={stalePrs} onPing={pingReviewers} />
<header className="mb-8 flex items-baseline justify-between gap-4">
<h1 className="font-display text-3xl font-bold">Maintainer</h1>
<div className="flex items-center gap-2">
Expand Down
104 changes: 104 additions & 0 deletions src/app/(app)/maintainer/stale-pr-banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use client';

import { useState, useTransition } from 'react';
import { AlertCircle, X } from 'lucide-react';
import { isOk, type Result } from '@/lib/result';
import type { StalePrRow } from '@/app/actions/maintainer/analytics';

type PingAction = (prId: number) => Promise<Result<{ commented: boolean }>>;

export function StalePrBanner({
stalePrs,
onPing,
}: {
stalePrs: StalePrRow[];
onPing: PingAction;
}) {
const [dismissed, setDismissed] = useState<Set<number>>(new Set());
const [pinged, setPinged] = useState<Set<number>>(new Set());
const [errors, setErrors] = useState<Record<number, string>>({});
const [pending, startTransition] = useTransition();
const [activePingId, setActivePingId] = useState<number | null>(null);

const visible = stalePrs.filter((pr) => !dismissed.has(pr.id));

if (visible.length === 0) return null;

function dismiss(id: number) {
setDismissed((prev) => new Set(prev).add(id));
}

function handlePing(pr: StalePrRow) {
setActivePingId(pr.id);
setErrors((prev) => {
const next = { ...prev };
delete next[pr.id];
return next;
});
startTransition(async () => {
const res = await onPing(pr.id);
if (isOk(res)) {
setPinged((prev) => new Set(prev).add(pr.id));
} else {
setErrors((prev) => ({ ...prev, [pr.id]: res.error.message }));
}
setActivePingId(null);
});
}

return (
<div className="mb-6 space-y-2">
{visible.map((pr) => {
const hasPinged = pinged.has(pr.id);
const isThisPending = pending && activePingId === pr.id;
const error = errors[pr.id];

return (
<div
key={pr.id}
className="flex items-start justify-between gap-4 rounded-lg border border-amber-800/60 bg-amber-950/30 px-4 py-3"
>
<div className="flex min-w-0 items-start gap-3">
<AlertCircle className="mt-0.5 h-4 w-4 shrink-0 text-amber-400" />
<div className="min-w-0">
<p className="text-[13px] text-amber-100">
<span className="font-mono text-amber-300">
{pr.repoFullName} #{pr.number}
</span>{' '}
has been stalled for{' '}
<span className="font-semibold text-amber-300">{pr.daysSinceUpdate} days</span>{' '}
waiting on reviewer feedback.
</p>
{error && (
<p className="mt-1 text-[11px] uppercase tracking-widest text-red-400">{error}</p>
)}
</div>
</div>
<div className="flex shrink-0 items-center gap-2">
{hasPinged ? (
<span className="text-[11px] uppercase tracking-widest text-emerald-400">
Pinged ✓
</span>
) : (
<button
onClick={() => handlePing(pr)}
disabled={isThisPending || pending}
className="text-[11px] uppercase tracking-widest text-amber-300 underline underline-offset-2 hover:text-amber-100 disabled:cursor-not-allowed disabled:opacity-50"
>
{isThisPending ? 'Pinging...' : 'Ping reviewers →'}
</button>
)}
<button
onClick={() => dismiss(pr.id)}
className="text-amber-600 hover:text-amber-300"
aria-label="Dismiss"
>
<X className="h-4 w-4" />
</button>
</div>
</div>
);
})}
</div>
);
}
89 changes: 82 additions & 7 deletions src/app/actions/maintainer/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,74 @@ export async function getStaleIssues(args: {
);
}

export type StalePrRow = {
id: number;
number: number;
title: string;
url: string;
repoFullName: string;
daysSinceUpdate: number;
authorLogin: string;
};

export async function getStalePrs({
installationId,
thresholdDays = 14,
}: {
installationId: number;
thresholdDays?: number;
}): Promise<Result<StalePrRow[]>> {
const authRes = await requireMaintainer({
rateLimit: { namespace: 'maintainer', ...RATE_LIMIT_TIERS.STANDARD },
requireService: true,
});
if (!authRes.ok) return authRes;
const { user, service } = authRes.data;

const repos = await listMaintainerRepos(user.id, installationId);
if (repos.length === 0) {
return ok([]);
}

const thresholdDate = new Date();
thresholdDate.setDate(thresholdDate.getDate() - thresholdDays);

const { data, error } = await service
.from('pull_requests')
.select('id, number, title, url, repo_full_name, github_updated_at, author_login')
.in('repo_full_name', repos)
.eq('state', 'open')
.lt('github_updated_at', thresholdDate.toISOString())
.order('github_updated_at', { ascending: true })
.limit(5);

if (error) return err('db_error', error.message);

type RawStalePr = {
id: number;
number: number;
title: string;
url: string;
repo_full_name: string;
github_updated_at: string;
author_login: string | null;
};

const rows: StalePrRow[] = ((data ?? []) as RawStalePr[]).map((row) => ({
id: row.id,
number: row.number,
title: row.title,
url: row.url,
repoFullName: row.repo_full_name,
daysSinceUpdate: Math.floor(
(Date.now() - new Date(row.github_updated_at).getTime()) / 86_400_000,
),
authorLogin: row.author_login ?? 'unknown',
}));

return ok(rows);
}

export async function getTopContributors(args: {
installationId: number;
}): Promise<Result<ContributorRow[]>> {
Expand Down Expand Up @@ -160,7 +228,7 @@ export async function getTopContributors(args: {
.limit(5);

return ok(
rows.map((row) => ({
rows.map((row: { githubHandle: string | null; xp: unknown; level: number | null }) => ({
githubHandle: row.githubHandle ?? 'unknown',
xp: row.xp ? Number(row.xp) : 0,
level: row.level ?? 0,
Expand Down Expand Up @@ -501,12 +569,19 @@ export async function getReviewerLoad(args: {
.orderBy(desc(count(pullRequests.id)));

return ok(
rows.map((row) => ({
reviewerId: row.reviewerId as string,
githubHandle: row.githubHandle,
avatarUrl: row.avatarUrl,
prCount: row.prCount,
})),
rows.map(
(row: {
reviewerId: string | null;
githubHandle: string;
avatarUrl: string | null;
prCount: number;
}) => ({
reviewerId: row.reviewerId as string,
githubHandle: row.githubHandle,
avatarUrl: row.avatarUrl,
prCount: row.prCount,
}),
),
);
} catch (error: any) {
return err('query_failed', error.message || 'Drizzle query failed');
Expand Down
Loading
Loading