How to Use GitHub’s Star History API to Generate README Growth Charts

Tracking repository popularity and stargazer growth is an essential metric for open-source project maintainers. Visualizing this trajectory directly within project documentation provides immediate social proof and technical context regarding community adoption. Following updates to API access policies that restricted individual stargazer listings for privacy reasons, GitHub introduced a dedicated star history endpoint designed specifically for tracking growth over time without exposing user identities.

Understanding the GitHub Star History Endpoint

The star history feature provides programmatic access to weekly and daily stargazer counts through a dedicated REST API endpoint:

GET /repos/{owner}/{repo}/stargazers/history

This endpoint delivers aggregated star activity structured by calendar week, with the most recent records appearing first in the payload. Each entry contains a Unix timestamp representing the start of the week, a total count of stars earned during that week, and an array representing individual daily totals from Sunday through Saturday.

Key Specifications of the History Endpoint

  • Public Accessibility: Public repositories permit unauthenticated requests, though developers can use personal access tokens with metadata read permissions to handle higher request volumes without hitting rate limits.
  • Paginated Results: Data is organized into pages containing up to 30 weeks of repository activity, supporting up to 100 pages total to cover several decades of history.
  • Automatic Redirect Handling: The endpoint seamlessly resolves repository renames and transfers, ensuring metrics remain accurate even if an organization rebrands or moves a repository.
  • Daily Precision: The days array inside the JSON response maps directly to star counts starting on Sunday, allowing developers to render detailed daily timeline charts.

Performance and Privacy Advantages

Previously, tools attempting to build growth charts had to fetch every individual user account that starred a repository. For massive projects with tens of thousands of stars, this required making thousands of distinct API requests, consuming rate limits and slowing down rendering engines. A repository requiring over 2,500 API calls under the legacy approach now requires as few as two dozen requests under the time-bucketed architecture.

Additionally, privacy protections are maintained because the new history structure returns anonymous aggregate figures rather than exposing personal user accounts or individual activity timestamps. Testing across major open-source repositories confirms that aggregating daily and weekly buckets produces exact historical totals matching active repository star counts.

Generating and Embedding README Star Charts

To implement a custom chart generator or utilize existing rendering platforms, developers calculate repository age from creation dates and retrieve weekly pages in parallel execution batches. Once the JSON dataset is collected, rendering engines generate static SVG images or interactive growth curves.

To embed these visual charts directly into a GitHub README.md file, developers frequently use theme-aware HTML markup. By utilizing the HTML <picture> element, documentation can automatically switch between dark and light modes based on user display preferences:

Using adaptive HTML markup ensures that star history graphs maintain optimal contrast and visibility regardless of whether a visitor views GitHub in light mode or dark mode.

By leveraging GitHub’s optimized star history endpoint, open-source developers can easily display accurate, high-performance growth charts while respecting user privacy and preserving network resources.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close filters
Products Search