Skip to content

chore: script to update the repo stars in real time#4

Merged
danielmarv merged 2 commits intonext-js-migrationfrom
daniel-dev-rebuild
Mar 12, 2026
Merged

chore: script to update the repo stars in real time#4
danielmarv merged 2 commits intonext-js-migrationfrom
daniel-dev-rebuild

Conversation

@danielmarv
Copy link
Copy Markdown
Member

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.json file.

Repository statistics automation:

  • Replaces the previous file-copy approach in sync-repo-stats.mjs with 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 to repository_stats.json and logs the total star count.

Data updates:

  • Updates the star counts for multiple repositories in repository_stats.json to reflect the latest values.

Changes Made

  • Added...
  • Modified...
  • Fixed...

Related Issues

Screenshots (if applicable)

Checklist

  • Tests added/updated
  • Documentation updated
  • Linting passes
  • Branch up-to-date with main

Deployment Notes

Signed-off-by: Daniel Ntege <danientege785@gmail.com>
Signed-off-by: Daniel Ntege <danientege785@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.mjs to fetch stars from GitHub (optionally authenticated) with fallback to cached data.
  • Updated nextjs/data/repository_stats.json with 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.

Comment on lines +129 to +130
const totalStars = Object.values(stats).reduce((sum, r) => sum + r.stars, 0);
console.log(`[sync-repo-stats] Done. Total stars: ${totalStars.toLocaleString()}`);
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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()}`);

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +39
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 });
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copilot uses AI. Check for mistakes.
Comment on lines +13 to +20
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",
];
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@danielmarv danielmarv merged commit f0c9069 into next-js-migration Mar 12, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants