Skip to content

feat: add total release assets download count via /assets-dl/:owner/:repo/total - #786

Open
gumaciel wants to merge 3 commits into
badgen:mainfrom
gumaciel:feat/total-release-assets-downloads
Open

feat: add total release assets download count via /assets-dl/:owner/:repo/total#786
gumaciel wants to merge 3 commits into
badgen:mainfrom
gumaciel:feat/total-release-assets-downloads

Conversation

@gumaciel

@gumaciel gumaciel commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Currently, the GitHub assets download badge endpoint (/github/assets-dl/:owner/:repo/:tag?) only supports fetching downloads for the latest release (when tag is omitted) or for a specific release tag (e.g. /v7.0.0).

Users who want to display the total asset download count across recent releases cannot do so.

Solution

Add support for /github/assets-dl/:owner/:repo/total (and /all) to calculate total asset downloads for recent releases.

  • Queries GET /repos/{owner}/{repo}/releases?per_page=30.
  • Sums download_count for all assets found across the returned releases.
  • Formats the sum using millify() and returns a green badge (or grey 'no releases' if none exist).
  • Updates documentation and example lists in pages/api/github.ts and public/badges.md.

Implementation Notes & Trade-offs

  1. Not 100% of All-Time Downloads for Mega Repos: This solution does not sum 100% of releases for mega repositories with hundreds of releases.
  2. Timeout Constraints: While increasing per_page to 100 fetches more releases, heavy repositories with many binary assets per release (like electron/electron) generate large JSON responses that trigger RequestError: Timeout awaiting 'request' for 6400ms configured in libs/got.ts.
  3. Pagination Risks: Implementing a full pagination loop to iterate through all release pages until the end was considered, but poses a risk of hitting rate limits and creating excessive request bursts (DDoS-like behavior) on very large repositories.
  4. Current Choice (per_page=30): Querying the 30 most recent releases proved to be the safest and most reliable threshold during testing across various repositories.

Suggestions for improvements or alternative strategies are welcome!

Usage

![Total Downloads](https://badgen.net/github/assets-dl/electron/electron/total)
Screenshot 2026-07-22 at 20 30 07

gumaciel added 2 commits July 22, 2026 20:06
- Adds support for /github/assets-dl/:owner/:repo/total and /all endpoints
- Paginates up to 5 pages (500 releases max) to sum download counts across all release assets
- Updates documentation and handler example lists
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown

@gumaciel is attempting to deploy a commit to the Badgen Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant