Skip to content

feat: auto-fetch GitHub stars, forks, and open issues from GitHub API instead of manual updates #900

@Sachinchaurasiya360

Description

@Sachinchaurasiya360

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:

  • Stars
  • Forks
  • Open Issues

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):

  1. When GET /api/opensource/:id is called, check if githubStatsUpdatedAt is older than 6 hours
  2. If stale, fetch live stats from the GitHub API and update stars, forks, openIssues on the DB row
  3. Return the updated row

Option B — Background cron sync:

  1. Add a cron job that runs every 6 hours
  2. For each approved repo, fetch GitHub stats and update the DB row
  3. No per-request latency overhead

Option C — Fetch on admin approval:

  1. When an admin approves a repo request (PUT /api/opensource/requests/:id/approve), immediately fetch stats from GitHub and populate the fields
  2. 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

  • Stars, forks, and open issues show real values from GitHub on the repo detail page
  • Stats are automatically refreshed (at minimum when a repo is approved, ideally every 6 hours)
  • GitHub API rate limits are handled gracefully (use a GITHUB_TOKEN env var if available)
  • If the GitHub API is unavailable, the last known values are shown (no crash)
  • githubStatsUpdatedAt is stored so we can throttle re-fetches

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requestgssoctype:bugBug fixestype:designUI/UX or design-related updatestype:featureNew feature implementationtype:performancePerformance optimization changes

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions