chore: script to update the repo stars in real time#4
chore: script to update the repo stars in real time#4danielmarv merged 2 commits intonext-js-migrationfrom
Conversation
Signed-off-by: Daniel Ntege <danientege785@gmail.com>
Signed-off-by: Daniel Ntege <danientege785@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR replaces the Next.js repo-stats synchronization step with a script that fetches current stargazer counts from the GitHub REST API, writing results into the cached nextjs/data/repository_stats.json used by the site.
Changes:
- Reworked
nextjs/scripts/sync-repo-stats.mjsto fetch stars from GitHub (optionally authenticated) with fallback to cached data. - Updated
nextjs/data/repository_stats.jsonwith refreshed star counts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| nextjs/scripts/sync-repo-stats.mjs | Replaces file-copy sync with GitHub API fetch + cache fallback and output writing. |
| nextjs/data/repository_stats.json | Refreshes cached star counts consumed by the Next.js UI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| const totalStars = Object.values(stats).reduce((sum, r) => sum + r.stars, 0); | ||
| console.log(`[sync-repo-stats] Done. Total stars: ${totalStars.toLocaleString()}`); |
There was a problem hiding this comment.
run() recomputes totalStars with Object.values(stats).reduce((sum, r) => sum + r.stars, 0), which will produce NaN or throw if any cached entry is missing/null/has non-numeric stars (possible when falling back to a partially-written or malformed cache). Reuse the existing totalStars(stats) helper here (and avoid naming the local variable the same as the helper) to keep the total robust.
| const totalStars = Object.values(stats).reduce((sum, r) => sum + r.stars, 0); | |
| console.log(`[sync-repo-stats] Done. Total stars: ${totalStars.toLocaleString()}`); | |
| const totalStarsCount = totalStars(stats); | |
| console.log(`[sync-repo-stats] Done. Total stars: ${totalStarsCount.toLocaleString()}`); |
| console.log("[sync-repo-stats] Fetching repository statistics from GitHub..."); | ||
|
|
||
| let successCount = 0; | ||
|
|
||
| for (const repo of repos) { | ||
| const response = await fetch(`https://api.github.com/repos/hiero-ledger/${repo}`, { headers }); |
There was a problem hiding this comment.
This script runs during pnpm dev and pnpm build (via sync:repo-stats) and always makes 20 GitHub API calls. Without GITHUB_TOKEN, the unauthenticated limit (60 req/hr per IP) can be exhausted quickly in CI or during local development, causing frequent fallbacks/zeros. Consider adding a cache TTL / "only refresh when explicitly requested" behavior (e.g., skip the API fetch if a recent repository_stats.json exists, or require a token/flag to refresh).
| const repos = [ | ||
| "hiero-consensus-node", "hiero-local-node", "hiero-mirror-node", | ||
| "hiero-improvement-proposals", "hiero-sdk-js", "hiero-sdk-java", | ||
| "hiero-json-rpc-relay", "hiero-sdk-go", "hiero-sdk-rust", | ||
| "hiero-mirror-node-explorer", "hiero-cli", "solo", "hiero-block-node", | ||
| "hiero-sdk-tck", "hiero-sdk-cpp", "governance", "hiero-sdk-python", | ||
| "hiero-sdk-swift", "sdk-collaboration-hub", "tsc", | ||
| ]; |
There was a problem hiding this comment.
The hardcoded repos list is duplicated elsewhere in the repo (e.g., scripts/fetch-repo-stats.mjs). Maintaining multiple sources of truth increases the chance the Hugo and Next.js builds drift (different repo sets / missing new repos). Consider centralizing the repo list (single JSON/config module) and importing it from both scripts.
Description
This pull request updates the process for synchronizing repository star statistics by replacing the manual file copy with an automated script that fetches live data from the GitHub API, and updates the cached data accordingly. It also updates the actual repository star counts in the
repository_stats.jsonfile.Repository statistics automation:
sync-repo-stats.mjswith an async script that fetches current star counts for a predefined list of repositories directly from the GitHub API, including support for authentication and rate limiting. If the API fetch fails, the script falls back to cached data or writes empty stats if no cache is available. The script writes the updated stats torepository_stats.jsonand logs the total star count.Data updates:
repository_stats.jsonto reflect the latest values.Changes Made
Related Issues
Screenshots (if applicable)
Checklist
Deployment Notes