Bug Report
Route: /student/opensource?repo=22
Example URL: https://www.internhack.xyz/student/opensource?repo=22
Problem
On the open-source repo detail page, the following stats always show 0 regardless of the actual repository data:
These values are stored statically in the database and require an admin to manually update them. They are never automatically refreshed from GitHub.
Expected Behaviour
Stars, forks, and open issues should reflect live (or recently cached) data pulled directly from the GitHub API for the repository's repoUrl.
Proposed Solution
When a repo detail page is loaded (or when a repo is created/approved), fetch live stats from the GitHub API and store/cache them:
GET https://api.github.com/repos/{owner}/{repo}
Response fields to use:
stargazers_count → stars
forks_count → forks
open_issues_count → open issues
watchers_count → watchers (bonus)
language → primary language (bonus)
Implementation options
Option A — On-demand fetch with DB cache (recommended):
- When
GET /api/opensource/:id is called, check if githubStatsUpdatedAt is older than 6 hours
- If stale, fetch live stats from the GitHub API and update
stars, forks, openIssues on the DB row
- Return the updated row
Option B — Background cron sync:
- Add a cron job that runs every 6 hours
- For each approved repo, fetch GitHub stats and update the DB row
- No per-request latency overhead
Option C — Fetch on admin approval:
- When an admin approves a repo request (
PUT /api/opensource/requests/:id/approve), immediately fetch stats from GitHub and populate the fields
- Combine with Option A or B for periodic refresh
Fields to Add / Update
The opensource Prisma model likely already has stars, forks, and openIssues fields. Add:
githubStatsUpdatedAt: DateTime? — timestamp of last sync, to throttle API calls
Acceptance Criteria
Bug Report
Route:
/student/opensource?repo=22Example URL:
https://www.internhack.xyz/student/opensource?repo=22Problem
On the open-source repo detail page, the following stats always show
0regardless of the actual repository data:These values are stored statically in the database and require an admin to manually update them. They are never automatically refreshed from GitHub.
Expected Behaviour
Stars, forks, and open issues should reflect live (or recently cached) data pulled directly from the GitHub API for the repository's
repoUrl.Proposed Solution
When a repo detail page is loaded (or when a repo is created/approved), fetch live stats from the GitHub API and store/cache them:
Response fields to use:
stargazers_count→ starsforks_count→ forksopen_issues_count→ open issueswatchers_count→ watchers (bonus)language→ primary language (bonus)Implementation options
Option A — On-demand fetch with DB cache (recommended):
GET /api/opensource/:idis called, check ifgithubStatsUpdatedAtis older than 6 hoursstars,forks,openIssueson the DB rowOption B — Background cron sync:
Option C — Fetch on admin approval:
PUT /api/opensource/requests/:id/approve), immediately fetch stats from GitHub and populate the fieldsFields to Add / Update
The
opensourcePrisma model likely already hasstars,forks, andopenIssuesfields. Add:githubStatsUpdatedAt: DateTime?— timestamp of last sync, to throttle API callsAcceptance Criteria
GITHUB_TOKENenv var if available)githubStatsUpdatedAtis stored so we can throttle re-fetches