Skip to content
Open
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
22 changes: 12 additions & 10 deletions src/app/api/metrics/repo-explorer/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { getSessionWithToken } from "@/lib/get-session-token";
import { NextRequest } from "next/server";
import { isMetricsCacheBypassed, metricsCacheKey, withMetricsCache } from "@/lib/metrics-cache";
import { fetchUserRepos } from "@/lib/github";
import { ExplorerRepoCardData } from "@/lib/repo-analytics-types";


export const dynamic = "force-dynamic";
const GITHUB_API = "https://api.github.com";

Expand All @@ -18,15 +20,14 @@
const bypass = isMetricsCacheBypassed(req);
const key = metricsCacheKey(session.githubId ?? session.githubLogin!, "repo-explorer-v2" as any, { days: 7 });

try {
const data = await withMetricsCache({ bypass, key, ttlSeconds: 30 * 60 }, async () => {
const reposRes = await fetch(`${GITHUB_API}/user/repos?sort=pushed&per_page=100`, {
headers: { Authorization: `Bearer ${accessToken}`, Accept: "application/vnd.github+json" },
cache: "no-store",
});

if (!reposRes.ok) throw new Error("API error fetching repos");
const repos = await reposRes.json();
try {
const data = await withMetricsCache(
{ bypass, key, ttlSeconds: 30 * 60 },
async () => {
const repos = await fetchUserRepos(session.accessToken);

Check failure on line 28 in src/app/api/metrics/repo-explorer/route.ts

View workflow job for this annotation

GitHub Actions / Type check

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.



const since = new Date();
since.setDate(since.getDate() - 30);
Expand Down Expand Up @@ -82,9 +83,9 @@
name: repo.name,
fullName: repo.full_name,
commitCount,
createdAt: repo.created_at,

Check failure on line 86 in src/app/api/metrics/repo-explorer/route.ts

View workflow job for this annotation

GitHub Actions / Type check

Property 'created_at' does not exist on type 'GitHubRepo'.
updatedAt: repo.updated_at,
primaryLanguage: repo.language,

Check failure on line 88 in src/app/api/metrics/repo-explorer/route.ts

View workflow job for this annotation

GitHub Actions / Type check

Property 'language' does not exist on type 'GitHubRepo'.
htmlUrl: repo.html_url,
activity7d,
});
Expand All @@ -93,10 +94,11 @@
result.sort((a, b) => b.commitCount - a.commitCount || new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime());

return { repos: result };
});
}
);
return Response.json(data);
} catch (error) {
console.error(error);
return Response.json({ error: "GitHub API error" }, { status: 502 });
}
}
}
Loading