feat: add GitHub stars syncing to metrics sync

- Add github.ts to npm-client with functions to fetch GitHub stars
- Add parseGitHubUrl to handle various GitHub URL formats
- Update metrics sync endpoint to fetch and store GitHub stars
- GitHub stars now factor into tool quality score calculation
- Optional GITHUB_TOKEN env var for higher API rate limits

Closes #8

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ajax Davis 2026-01-07 14:11:06 +10:00
parent a4cfea5cc3
commit 724bf18822
4 changed files with 156 additions and 3 deletions

View file

@ -1,5 +1,5 @@
import { prisma } from '@tpmjs/db';
import { fetchDownloadStats } from '@tpmjs/npm-client';
import { fetchDownloadStats, fetchGitHubStarsFromRepository } from '@tpmjs/npm-client';
import { type NextRequest, NextResponse } from 'next/server';
import { env } from '~/env';
@ -44,12 +44,17 @@ export async function POST(request: NextRequest) {
// Fetch download stats from NPM (package-level metric)
const downloads = await fetchDownloadStats(pkg.npmPackageName);
// Fetch GitHub stars if repository is available
const githubStars = await fetchGitHubStarsFromRepository(
pkg.npmRepository as { type?: string; url?: string } | string | null
);
// Update package metrics
await prisma.package.update({
where: { id: pkg.id },
data: {
npmDownloadsLastMonth: downloads,
// githubStars would be updated here if we had GitHub API integration
githubStars,
},
});
@ -58,7 +63,7 @@ export async function POST(request: NextRequest) {
const qualityScore = calculateQualityScore({
tier: pkg.tier, // Tier is at package level
downloads, // Package downloads
githubStars: pkg.githubStars || 0, // Package stars
githubStars, // Use freshly fetched stars
hasParameters: !!tool.parameters,
hasReturns: !!tool.returns,
hasAiAgent: !!tool.aiAgent,