"""
GitHub REST API — Repository Info Demo
=======================================
A minimal, ready-to-run example of reading public repo metadata.

Get a token (free, optional for public data):
    1. Sign in at https://github.com and open
       Settings -> Developer settings -> Personal access tokens.
    2. Click "Generate new token" (a fine-grained token with read-only
       public access is plenty), then copy it.
    3. Public repos work without a token, but a token raises your rate limit.

Setup:
    pip install requests
    export GITHUB_TOKEN="ghp_..."   # optional, raises rate limits

Run:
    python github_demo.py
"""

import os
import requests


def repo_info(owner: str, repo: str) -> dict:
    """Return basic metadata for a GitHub repository."""
    headers = {"Accept": "application/vnd.github+json"}
    token = os.environ.get("GITHUB_TOKEN")
    if token:
        headers["Authorization"] = f"Bearer {token}"
    response = requests.get(f"https://api.github.com/repos/{owner}/{repo}", headers=headers)
    response.raise_for_status()
    return response.json()


if __name__ == "__main__":
    data = repo_info("anthropics", "anthropic-sdk-python")
    print(f"{data['full_name']} — ⭐ {data['stargazers_count']}")
