Skip to content
Closed
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions src/app/api/metrics/contributions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
withMetricsCache,
} from "@/lib/metrics-cache";
import { supabaseAdmin } from "@/lib/supabase";
import { githubFetch, RateLimitError } from "@/lib/githubFetch";
import { resolveAppUser } from "@/lib/resolve-user";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -77,7 +78,7 @@ async function fetchContributionsForAccount(
since.setDate(since.getDate() - days);
const sinceStr = toLocalDateStr(since);

const searchRes = await fetch(
const searchRes = await githubFetch(
`${GITHUB_API}/search/commits?q=author:${githubLogin}+author-date:>=${sinceStr}&per_page=100&sort=author-date&order=desc`,
{
headers: {
Expand Down Expand Up @@ -255,7 +256,13 @@ export async function GET(req: NextRequest) {
{ bypass, userId: session.githubId ?? session.githubLogin }
);
return Response.json(result);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand All @@ -279,7 +286,13 @@ export async function GET(req: NextRequest) {
});

return Response.json(merged);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand Down Expand Up @@ -357,7 +370,13 @@ export async function GET(req: NextRequest) {
});

return Response.json(merged);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand Down Expand Up @@ -387,7 +406,13 @@ export async function GET(req: NextRequest) {
{ bypass, userId: accountId }
);
return Response.json(result);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
23 changes: 18 additions & 5 deletions src/app/api/metrics/prs/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
withMetricsCache,
} from "@/lib/metrics-cache";
import { supabaseAdmin } from "@/lib/supabase";
import { githubFetch, RateLimitError } from "@/lib/githubFetch";
import { resolveAppUser } from "@/lib/resolve-user";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -82,11 +83,11 @@ async function fetchFirstReviewTimestamp(
Accept: "application/vnd.github+json",
};
const [reviewsRes, commentsRes] = await Promise.all([
fetch(`${GITHUB_API}/repos/${repo}/pulls/${pr.number}/reviews?per_page=100`, {
githubFetch(`${GITHUB_API}/repos/${repo}/pulls/${pr.number}/reviews?per_page=100`, {
headers,
cache: "no-store",
}),
fetch(`${GITHUB_API}/repos/${repo}/pulls/${pr.number}/comments?per_page=100`, {
githubFetch(`${GITHUB_API}/repos/${repo}/pulls/${pr.number}/comments?per_page=100`, {
headers,
cache: "no-store",
}),
Expand Down Expand Up @@ -141,7 +142,7 @@ async function getAverageFirstReviewHours(
}

async function fetchPRMetrics(token: string): Promise<PRMetricsBase> {
const searchRes = await fetch(
const searchRes = await githubFetch(
`${GITHUB_API}/search/issues?q=type:pr+author:@me&sort=updated&order=desc&per_page=100`,
{
headers: { Authorization: `Bearer ${token}` },
Expand Down Expand Up @@ -413,7 +414,13 @@ export async function GET(req: NextRequest) {
});
const gitlab = await getGitLabMetrics(gitlabToken, gitlabCacheContext);
return Response.json(formatPRMetricsResponse(result, gitlab));
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand Down Expand Up @@ -500,7 +507,13 @@ export async function GET(req: NextRequest) {
});
const gitlab = await getGitLabMetrics(gitlabToken, gitlabCacheContext);
return Response.json(formatPRMetricsResponse(result, gitlab));
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
29 changes: 24 additions & 5 deletions src/app/api/metrics/repos/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
withMetricsCache,
} from "@/lib/metrics-cache";
import { supabaseAdmin } from "@/lib/supabase";
import { githubFetch, RateLimitError } from "@/lib/githubFetch";
import { resolveAppUser } from "@/lib/resolve-user";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -66,7 +67,7 @@ async function fetchRepoLanguages(
token: string,
repoName: string
): Promise<RepoLanguage[]> {
const res = await fetch(`${GITHUB_API}/repos/${repoName}/languages`, {
const res = await githubFetch(`${GITHUB_API}/repos/${repoName}/languages`, {
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/vnd.github+json",
Expand Down Expand Up @@ -117,7 +118,7 @@ async function fetchReposForAccount(
since.setDate(since.getDate() - days);
const sinceStr = since.toISOString().slice(0, 10);

const searchRes = await fetch(
const searchRes = await githubFetch(
`${GITHUB_API}/search/commits?q=author:${githubLogin}+author-date:>=${sinceStr}&per_page=100&sort=author-date&order=desc`,
{
headers: {
Expand Down Expand Up @@ -187,7 +188,13 @@ export async function GET(req: NextRequest) {
{ bypass, userId: session.githubId ?? session.githubLogin }
);
return Response.json(result);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand Down Expand Up @@ -242,7 +249,13 @@ export async function GET(req: NextRequest) {
{ bypass, userId: session.githubId }
);
return Response.json(result);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand Down Expand Up @@ -272,7 +285,13 @@ export async function GET(req: NextRequest) {
{ bypass, userId: accountId }
);
return Response.json(result);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
19 changes: 16 additions & 3 deletions src/app/api/metrics/streak/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
withMetricsCache,
} from "@/lib/metrics-cache";
import { supabaseAdmin } from "@/lib/supabase";
import { githubFetch, RateLimitError } from "@/lib/githubFetch";
import { resolveAppUser } from "@/lib/resolve-user";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -44,7 +45,7 @@ async function fetchActiveDates(
const activeDates = new Set<string>();
let page = 1;
while (true) {
const searchRes = await fetch(
const searchRes = await githubFetch(
`${GITHUB_API}/search/commits?q=author:${githubLogin}+author-date:>=${sinceStr}&per_page=100&page=${page}&sort=author-date&order=desc`,
{
headers: {
Expand Down Expand Up @@ -188,7 +189,13 @@ export async function GET(req: NextRequest) {
return Response.json(
calculateStreakFromDates(activeDates, freezeDates)
);
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
Expand Down Expand Up @@ -257,7 +264,13 @@ export async function GET(req: NextRequest) {
userId: accountId,
});
return Response.json(calculateStreakFromDates(activeDates, freezeDates));
} catch {
} catch (err) {
if (err instanceof RateLimitError) {
return Response.json(
{ error: "rate_limited", resetAt: err.resetAt },
{ status: 429 }
);
}
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
8 changes: 4 additions & 4 deletions src/app/dashboard/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ function SettingsPageContent() {
<div
className={`mb-6 rounded-xl border p-4 text-sm ${
statusMessage.kind === "success"
? "border-green-500/30 bg-green-500/10 text-green-400"
: "border-red-500/30 bg-red-500/10 text-red-400"
? "border-[var(--success-border)] bg-[var(--success-soft)] text-[var(--success-foreground)]"
: "border-[var(--destructive-border)] bg-[var(--destructive-soft)] text-[var(--destructive-foreground)]"
}`}
>
{statusMessage.message}
Expand Down Expand Up @@ -491,7 +491,7 @@ function SettingsPageContent() {
</div>

{removeError && (
<div className="mt-4 rounded-lg border border-red-500/30 bg-red-500/10 p-3 text-sm text-red-400">
<div className="mt-4 rounded-lg border border-[var(--destructive-border)] bg-[var(--destructive-soft)] p-3 text-sm text-[var(--destructive-foreground)]">
{removeError}
</div>
)}
Expand Down Expand Up @@ -531,7 +531,7 @@ function SettingsPageContent() {
onClick={() => handleRemoveAccount(account.githubId)}
aria-label={`Remove ${account.githubLogin}`}
disabled={removingAccountId === account.githubId}
className="rounded-lg border border-[var(--border)] px-4 py-2 text-sm font-medium text-[var(--card-foreground)] transition-colors hover:bg-red-500/10 hover:text-red-400 disabled:opacity-60"
className="rounded-lg border border-[var(--border)] px-4 py-2 text-sm font-medium text-[var(--card-foreground)] transition-colors hover:bg-[var(--destructive-soft)] hover:text-[var(--destructive-foreground)] disabled:opacity-60"
>
{removingAccountId === account.githubId
? "Removing..."
Expand Down
26 changes: 24 additions & 2 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
--card-muted: #e2e8f0;
--border: #cbd5e1;
--accent: #6366f1;
--success: #10b981;
--success: #22c55e;
--success-foreground: #15803d;
--success-soft: rgba(34, 197, 94, 0.15);
--success-border: rgba(34, 197, 94, 0.25);
--warning: #eab308;
--warning-foreground: #a16207;
--warning-soft: rgba(234, 179, 8, 0.15);
--warning-border: rgba(234, 179, 8, 0.25);
--destructive: #ef4444;
--destructive-foreground: #b91c1c;
--destructive-soft: rgba(239, 68, 68, 0.15);
--destructive-border: rgba(239, 68, 68, 0.25);
--accent-soft: rgba(99, 102, 241, 0.15);
--accent-foreground: #ffffff;
--control: #e2e8f0;
Expand All @@ -31,7 +42,18 @@
--card-muted: #334155;
--border: #334155;
--accent: #818cf8;
--success: #10b981;
--success: #4ade80;
--success-foreground: #4ade80;
--success-soft: rgba(74, 222, 128, 0.15);
--success-border: rgba(74, 222, 128, 0.25);
--warning: #facc15;
--warning-foreground: #facc15;
--warning-soft: rgba(250, 204, 21, 0.15);
--warning-border: rgba(250, 204, 21, 0.25);
--destructive: #f87171;
--destructive-foreground: #f87171;
--destructive-soft: rgba(248, 113, 113, 0.15);
--destructive-border: rgba(248, 113, 113, 0.25);
--accent-soft: rgba(99, 102, 241, 0.2);
--accent-foreground: #ffffff;
--control: #334155;
Expand Down
4 changes: 2 additions & 2 deletions src/components/CIAnalytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export default function CIAnalytics() {
))}
</div>
) : error ? (
<div className="rounded-lg border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-400">
<div className="rounded-lg border border-[var(--destructive-border)] bg-[var(--destructive-soft)] p-4 text-sm text-[var(--destructive-foreground)]">
<p>{error}</p>
<button
type="button"
onClick={fetchCIAnalytics}
className="mt-3 rounded-md border border-red-500/30 px-3 py-1.5 text-xs font-medium text-red-300 transition-colors hover:bg-red-500/10"
className="mt-3 rounded-md border border-[var(--destructive-border)] px-3 py-1.5 text-xs font-medium text-[var(--destructive-foreground)] transition-colors hover:bg-[var(--destructive-soft)]"
>
Try again
</button>
Expand Down
4 changes: 2 additions & 2 deletions src/components/CommitTimeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ export default function CommitTimeChart() {
</div>
) : error ? (
<div className="flex h-full items-center justify-center">
<div className="rounded-lg border border-red-500/20 bg-red-500/10 p-4 text-sm text-red-400 text-center">
<div className="rounded-lg border border-[var(--destructive-border)] bg-[var(--destructive-soft)] p-4 text-sm text-[var(--destructive-foreground)] text-center">
<p>{error}</p>
<button
type="button"
onClick={fetchContributions}
className="mt-3 rounded-md border border-red-500/30 px-3 py-1.5 text-xs font-medium text-red-300 transition-colors hover:bg-red-500/10"
className="mt-3 rounded-md border border-[var(--destructive-border)] px-3 py-1.5 text-xs font-medium text-[var(--destructive-foreground)] transition-colors hover:bg-[var(--destructive-soft)]"
>
Try again
</button>
Expand Down
Loading
Loading