Skip to content

Include a badge to count all stars of all repos in the org #12

@gcanasherrera

Description

@gcanasherrera

🛠️ Feature: Badge with Total Stars across all Org Repositories

🎯 Goal

We’d like to add a badge to our organization README that displays the total number of GitHub stars across all our repositories. GitHub does not provide this natively, so we need to compute it ourselves and expose it via a custom Shields.io endpoint.


✅ Desired Outcome

A badge like this in our README:

![Org Stars](https://img.shields.io/endpoint?url=https://<our-hosted-json-url>)

It should dynamically update (e.g. daily) with the sum of stars from all public repositories in the organization.


🔧 How to Implement

1. Write a script to count all stars

Use the GitHub REST API to list repositories and sum their stargazers_count.

Example in Python:

import requests

ORG = "your-org-name"
GITHUB_TOKEN = "ghp_xxx"  # Use a GitHub secret in production
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
page = 1
stars = 0

while True:
    url = f"https://api.github.com/orgs/{ORG}/repos?per_page=100&page={page}"
    res = requests.get(url, headers=headers).json()
    if not res:
        break
    stars += sum(repo["stargazers_count"] for repo in res)
    page += 1

print(f"Total stars: {stars}")

2. Create a JSON file for the badge

Shields.io supports custom endpoints. Example badge JSON:

{
  "schemaVersion": 1,
  "label": "Org stars",
  "message": "★ 1234",
  "color": "blue"
}

Have the script generate this automatically and save it to e.g. badge/star-badge.json.


3. Host the badge JSON

Options:

  • Use GitHub Pages (e.g., from a gh-pages branch or /docs folder)
  • Or push it to a public server if available

Make sure the badge JSON is accessible at a public HTTPS URL like:

https://your-org.github.io/your-repo/badge/star-badge.json

4. Add the badge to the README

Once hosted, embed the badge in your README like this:

![Org Stars](https://img.shields.io/endpoint?url=https://your-org.github.io/your-repo/badge/star-badge.json)

5. Automate with GitHub Actions (optional but recommended)

Set up a GitHub Action to:

  • Run the star-count script daily (or on push)
  • Commit or upload the updated badge JSON

Example workflow:

name: Update Star Badge
on:
  schedule:
    - cron: "0 0 * * *"  # Every day at midnight
  workflow_dispatch:

jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'

      - name: Run star counter script
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: python your-script.py

      - name: Commit & push badge
        run: |
          git config user.name "github-actions"
          git config user.email "github-actions@github.com"
          git add badge/star-badge.json
          git commit -m "Update star badge"
          git push

🧪 Extras (Optional Enhancements)

  • Cache stars in a .json to avoid unnecessary commits if unchanged
  • Add more org-wide stats: forks, issues, contributors, etc.
  • Extend to private repos (requires token with repo scope)

📌 Tasks

  • Write the star-count script ✅
  • Create badge JSON and validate it
  • Set up hosting (GitHub Pages or similar)
  • Automate via GitHub Actions
  • Add badge to README

This is a Help Wanted task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions