mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d32dee489 | ||
|
|
0835c64a63 | ||
|
|
60ff6ac7df | ||
|
|
01afeeda4e | ||
|
|
d4b4a8bc52 | ||
|
|
d907815f19 | ||
|
|
b737a0171e | ||
|
|
53ae54fe98 | ||
|
|
e47a67d1a1 | ||
|
|
f5fab0d6c3 | ||
|
|
98547a3f33 | ||
|
|
c0eba0b5a4 | ||
|
|
3653ef66a5 | ||
|
|
74a8146779 | ||
|
|
02e7270440 | ||
|
|
9b5a13f26b | ||
|
|
a25ae33f29 |
@@ -8,8 +8,12 @@ your account, charts your contribution timeline, highlights your top
|
|||||||
collaborators, breaks down your languages, tracks your commit streaks,
|
collaborators, breaks down your languages, tracks your commit streaks,
|
||||||
and earns you tags like `Backend`, `ML`, or `Founder #42`.
|
and earns you tags like `Backend`, `ML`, or `Founder #42`.
|
||||||
|
|
||||||
|
[](https://gh-stats.com)
|
||||||
|
|
||||||
|
That card is live, not a screenshot. Swap in your own username:
|
||||||
|
|
||||||
```md
|
```md
|
||||||

|
[](https://gh-stats.com)
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="./assets/examples/composite-midnight.svg" width="420" alt="composite widget, midnight theme" />
|
<img src="./assets/examples/composite-midnight.svg" width="420" alt="composite widget, midnight theme" />
|
||||||
@@ -37,11 +41,11 @@ and earns you tags like `Backend`, `ML`, or `Founder #42`.
|
|||||||
2. Sign in with GitHub. Signing in is how you prove ownership of the
|
2. Sign in with GitHub. Signing in is how you prove ownership of the
|
||||||
username, and it unlocks the editor.
|
username, and it unlocks the editor.
|
||||||
3. Pick a theme, reorder widgets, add any custom tags or achievements.
|
3. Pick a theme, reorder widgets, add any custom tags or achievements.
|
||||||
4. Click **Generate**.
|
4. Click **Get embed code**.
|
||||||
5. Paste this one line into your profile README:
|
5. Paste this one line into your profile README:
|
||||||
|
|
||||||
```md
|
```md
|
||||||

|
[](https://gh-stats.com)
|
||||||
```
|
```
|
||||||
|
|
||||||
The image URL is stable. Once it's in your README you can change
|
The image URL is stable. Once it's in your README you can change
|
||||||
@@ -111,6 +115,28 @@ Overall score (0 to 100), letter grade, and your top role tags.
|
|||||||

|

|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### How the score works
|
||||||
|
|
||||||
|
The score is a weighted sum of seven public signals. Each signal earns
|
||||||
|
0 to 100 points, reaching 100 at the cap shown, and the weights add up to
|
||||||
|
100%.
|
||||||
|
|
||||||
|
| Signal | Weight | Cap |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| Contributions, all time (commits, PRs, issues, reviews) | 33% | 3,000 |
|
||||||
|
| Active weeks in the last year | 22% | 40 |
|
||||||
|
| Repositories (owned and contributed to, at most 50 counted) | 15% | 40 |
|
||||||
|
| Stars across those repositories | 11% | 200 |
|
||||||
|
| Forks across those repositories | 8% | 20 |
|
||||||
|
| Recent public events | 8% | 80 |
|
||||||
|
| Followers | 3% | 100 |
|
||||||
|
|
||||||
|
Letters follow the total: S++ from 97, S+ 93, S 89, A++ 86, A+ 82, A 78,
|
||||||
|
A- 72, B++ 68, B+ 64, B 58, B- 50, C+ 42, and C below that. The score
|
||||||
|
measures the volume and regularity of public activity, not code quality.
|
||||||
|
Private work is invisible to it. To leave it off your card, turn off the
|
||||||
|
Grade widget in the editor.
|
||||||
|
|
||||||
### Impact
|
### Impact
|
||||||
|
|
||||||
Your contribution volume over the last 6 months, drawn as a smooth area
|
Your contribution volume over the last 6 months, drawn as a smooth area
|
||||||
@@ -319,7 +345,7 @@ Sign in with GitHub at <https://gh-stats.com/api/>. Only the account whose
|
|||||||
login matches the username can edit that widget's settings.
|
login matches the username can edit that widget's settings.
|
||||||
|
|
||||||
**Can I change the widget without re-embedding?**
|
**Can I change the widget without re-embedding?**
|
||||||
Yes. The image URL is stable. Edit in the editor, click **Generate**,
|
Yes. The image URL is stable. Edit in the editor, click **Get embed code**,
|
||||||
and the next fetch serves the new version. GitHub's image cache may
|
and the next fetch serves the new version. GitHub's image cache may
|
||||||
delay propagation by a few minutes.
|
delay propagation by a few minutes.
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ services:
|
|||||||
GITHUB_PAT: ${GITHUB_PAT:?missing GITHUB_PAT}
|
GITHUB_PAT: ${GITHUB_PAT:?missing GITHUB_PAT}
|
||||||
FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN}
|
FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN}
|
||||||
GENERATOR_URL: http://generator:5002
|
GENERATOR_URL: http://generator:5002
|
||||||
|
COLLABORATOR_TOP_REPOS: "15"
|
||||||
volumes:
|
volumes:
|
||||||
- ${HOME}/ghstats/data/fetcher:/app/data
|
- ${HOME}/ghstats/data/fetcher:/app/data
|
||||||
ports:
|
ports:
|
||||||
@@ -22,6 +23,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
GITHUB_PAT: ${GITHUB_PAT:?missing GITHUB_PAT}
|
GITHUB_PAT: ${GITHUB_PAT:?missing GITHUB_PAT}
|
||||||
FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN}
|
FETCHER_INTERNAL_TOKEN: ${FETCHER_INTERNAL_TOKEN:?missing FETCHER_INTERNAL_TOKEN}
|
||||||
|
COLLABORATOR_TOP_REPOS: "15"
|
||||||
volumes:
|
volumes:
|
||||||
- ${HOME}/ghstats/data/fetcher:/app/data
|
- ${HOME}/ghstats/data/fetcher:/app/data
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -41,6 +43,11 @@ services:
|
|||||||
BUILD_VERSION: ${IMAGE_TAG:-}
|
BUILD_VERSION: ${IMAGE_TAG:-}
|
||||||
DEV_DASHBOARD_USER: ${DEV_DASHBOARD_USER:?missing DEV_DASHBOARD_USER}
|
DEV_DASHBOARD_USER: ${DEV_DASHBOARD_USER:?missing DEV_DASHBOARD_USER}
|
||||||
DEV_DASHBOARD_PASSWORD: ${DEV_DASHBOARD_PASSWORD:?missing DEV_DASHBOARD_PASSWORD}
|
DEV_DASHBOARD_PASSWORD: ${DEV_DASHBOARD_PASSWORD:?missing DEV_DASHBOARD_PASSWORD}
|
||||||
|
ENROLLMENT_HOURLY_CAP: "120"
|
||||||
|
ENROLLMENT_DAILY_CAP: "1500"
|
||||||
|
# Fallback while Caddy sends every visitor as 127.0.0.1 (one shared
|
||||||
|
# bucket). Remove once Caddy forwards Cf-Connecting-Ip as X-Forwarded-For.
|
||||||
|
RATE_LIMIT_READ_MAX: "30000"
|
||||||
volumes:
|
volumes:
|
||||||
- ${HOME}/ghstats/data/generator:/app/data
|
- ${HOME}/ghstats/data/generator:/app/data
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -9,5 +9,9 @@ cd "$(dirname "$0")"
|
|||||||
mkdir -p "$HOME/ghstats/data/fetcher" "$HOME/ghstats/data/generator"
|
mkdir -p "$HOME/ghstats/data/fetcher" "$HOME/ghstats/data/generator"
|
||||||
|
|
||||||
docker compose pull
|
docker compose pull
|
||||||
|
# Keep fetcher-cron stopped across a deploy if an operator stopped it (e.g.
|
||||||
|
# during a sign-up spike); otherwise the recreated container runs at once.
|
||||||
|
cron_was_stopped=$(docker inspect -f '{{.State.Status}}' ghstats-fetcher-cron 2>/dev/null | grep -qx exited && echo 1 || true)
|
||||||
docker compose up -d --remove-orphans
|
docker compose up -d --remove-orphans
|
||||||
|
if [ -n "$cron_was_stopped" ]; then docker stop ghstats-fetcher-cron; fi
|
||||||
docker compose ps
|
docker compose ps
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ WORKDIR /app
|
|||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
COPY gunicorn.conf.py ./
|
||||||
|
|
||||||
EXPOSE 5003
|
EXPOSE 5003
|
||||||
# Bind to $PORT when set (e.g. Cloud Run injects PORT=8080); default to 5003.
|
# Bind to $PORT when set (e.g. Cloud Run injects PORT=8080); default to 5003.
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"""Gunicorn settings: one access line per request on stdout, for Pantheos.
|
||||||
|
|
||||||
|
Docker's json-file driver captures stdout and Pantheos ingests it, so each line
|
||||||
|
becomes a request log and feeds the container's rps / 5xx / p95. Monitoring
|
||||||
|
traffic (/metrics scrapes, /health checks) is left out so it doesn't drown the
|
||||||
|
real requests.
|
||||||
|
"""
|
||||||
|
from gunicorn import glogging
|
||||||
|
|
||||||
|
accesslog = "-"
|
||||||
|
access_log_format = '"%(r)s" %(s)s %(M)sms'
|
||||||
|
|
||||||
|
_QUIET_PATHS = ("/metrics", "/health")
|
||||||
|
|
||||||
|
|
||||||
|
class _Logger(glogging.Logger):
|
||||||
|
def access(self, resp, req, environ, request_time):
|
||||||
|
if req.path not in _QUIET_PATHS:
|
||||||
|
super().access(resp, req, environ, request_time)
|
||||||
|
|
||||||
|
|
||||||
|
logger_class = _Logger
|
||||||
@@ -5,6 +5,7 @@ COPY requirements.txt ./
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
COPY gunicorn.conf.py ./
|
||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
|
|
||||||
EXPOSE 5001
|
EXPOSE 5001
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"""Gunicorn settings: one access line per request on stdout, for Pantheos.
|
||||||
|
|
||||||
|
Docker's json-file driver captures stdout and Pantheos ingests it, so each line
|
||||||
|
becomes a request log and feeds the container's rps / 5xx / p95. Monitoring
|
||||||
|
traffic (/metrics scrapes, /health checks) is left out so it doesn't drown the
|
||||||
|
real requests.
|
||||||
|
"""
|
||||||
|
from gunicorn import glogging
|
||||||
|
|
||||||
|
accesslog = "-"
|
||||||
|
access_log_format = '"%(r)s" %(s)s %(M)sms'
|
||||||
|
|
||||||
|
_QUIET_PATHS = ("/metrics", "/health")
|
||||||
|
|
||||||
|
|
||||||
|
class _Logger(glogging.Logger):
|
||||||
|
def access(self, resp, req, environ, request_time):
|
||||||
|
if req.path not in _QUIET_PATHS:
|
||||||
|
super().access(resp, req, environ, request_time)
|
||||||
|
|
||||||
|
|
||||||
|
logger_class = _Logger
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
"""Flask app for the fetcher service. All endpoints require X-Internal-Token."""
|
"""Flask app for the fetcher service. All endpoints require X-Internal-Token."""
|
||||||
|
import fcntl
|
||||||
import hmac
|
import hmac
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
import tempfile
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from flask import Flask, jsonify, request, Response
|
from flask import Flask, jsonify, request, Response
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
@@ -31,6 +34,10 @@ _BG_POOL = ThreadPoolExecutor(
|
|||||||
# fetcher container; a multi-replica deploy would need a distributed lock.
|
# fetcher container; a multi-replica deploy would need a distributed lock.
|
||||||
_INFLIGHT: set[str] = set()
|
_INFLIGHT: set[str] = set()
|
||||||
_INFLIGHT_LOCK = threading.Lock()
|
_INFLIGHT_LOCK = threading.Lock()
|
||||||
|
# /data misses for the same user (worker build, ad hoc renders, cron) used to
|
||||||
|
# each run a full GitHub fetch. gunicorn runs sync worker processes, so the
|
||||||
|
# lock is a per-username file lock that all workers in the container share.
|
||||||
|
_MISS_LOCK_DIR = tempfile.gettempdir()
|
||||||
|
|
||||||
# Must stay in sync with github.py's _USERNAME_RE. Trust boundary: the
|
# Must stay in sync with github.py's _USERNAME_RE. Trust boundary: the
|
||||||
# fetcher is called only by the generator over the internal network, but
|
# fetcher is called only by the generator over the internal network, but
|
||||||
@@ -81,12 +88,25 @@ def metrics():
|
|||||||
def get_data(username: str):
|
def get_data(username: str):
|
||||||
if not _valid_username(username):
|
if not _valid_username(username):
|
||||||
return jsonify({"error": "invalid_username"}), 400
|
return jsonify({"error": "invalid_username"}), 400
|
||||||
|
if db.get_user(username) is None:
|
||||||
|
path = os.path.join(_MISS_LOCK_DIR, f"ghstats-miss-{username.lower()}.lock")
|
||||||
|
with open(path, "w") as lock:
|
||||||
|
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||||
|
return _get_data(username)
|
||||||
|
return _get_data(username)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_data(username: str):
|
||||||
row = db.get_user(username)
|
row = db.get_user(username)
|
||||||
if row is None:
|
if row is None:
|
||||||
# Auto-fetch path
|
# Auto-fetch path
|
||||||
t0 = time.monotonic()
|
t0 = time.monotonic()
|
||||||
try:
|
try:
|
||||||
data = github.fetch_github_data(username, token=config.GITHUB_PAT)
|
data = github.fetch_github_data(username, token=config.GITHUB_PAT)
|
||||||
|
except github.GitHubTransientError as e:
|
||||||
|
analytics.record_fetch(username, 503, int((time.monotonic() - t0) * 1000))
|
||||||
|
log.warning("github fetch rate-limited for %s: %s", username, e)
|
||||||
|
return jsonify({"error": "github_rate_limited"}), 503
|
||||||
except Exception:
|
except Exception:
|
||||||
analytics.record_fetch(username, 502, int((time.monotonic() - t0) * 1000))
|
analytics.record_fetch(username, 502, int((time.monotonic() - t0) * 1000))
|
||||||
log.exception("github fetch failed for %s", username)
|
log.exception("github fetch failed for %s", username)
|
||||||
|
|||||||
@@ -7,6 +7,18 @@ GITHUB_PAT = os.getenv("GITHUB_PAT", "")
|
|||||||
INTERNAL_TOKEN = os.getenv("FETCHER_INTERNAL_TOKEN", "")
|
INTERNAL_TOKEN = os.getenv("FETCHER_INTERNAL_TOKEN", "")
|
||||||
REFRESH_INTERVAL_HOURS = int(os.getenv("FETCHER_REFRESH_INTERVAL_HOURS", "24"))
|
REFRESH_INTERVAL_HOURS = int(os.getenv("FETCHER_REFRESH_INTERVAL_HOURS", "24"))
|
||||||
TRIAL_GC_DAYS = int(os.getenv("FETCHER_TRIAL_GC_DAYS", "7"))
|
TRIAL_GC_DAYS = int(os.getenv("FETCHER_TRIAL_GC_DAYS", "7"))
|
||||||
|
# The hourly refresh tick stops once the PAT's core budget falls under this
|
||||||
|
# reserve, so new sign-ups still get fetched, and refreshes at most this many
|
||||||
|
# users per tick, so a day's worth of sign-ups going stale together is spread
|
||||||
|
# over several hours. Oldest-fetched users go first; the rest wait a tick.
|
||||||
|
REFRESH_CORE_RESERVE = int(os.getenv("FETCHER_REFRESH_CORE_RESERVE", "1500"))
|
||||||
|
REFRESH_MAX_PER_TICK = int(os.getenv("FETCHER_REFRESH_MAX_PER_TICK", "60"))
|
||||||
|
# GitHub's secondary (burst) limits trip when refreshes run back to back. The
|
||||||
|
# tick pauses between users; on a rate limit it waits Retry-After (else the
|
||||||
|
# default, capped) and retries that user once, then stops and defers the rest.
|
||||||
|
REFRESH_USER_PAUSE = float(os.getenv("FETCHER_REFRESH_USER_PAUSE", "1.5"))
|
||||||
|
REFRESH_RETRY_SLEEP = int(os.getenv("FETCHER_REFRESH_RETRY_SLEEP", "60"))
|
||||||
|
REFRESH_RETRY_SLEEP_MAX = int(os.getenv("FETCHER_REFRESH_RETRY_SLEEP_MAX", "120"))
|
||||||
API_TIMEOUT = int(os.getenv("API_TIMEOUT", "15"))
|
API_TIMEOUT = int(os.getenv("API_TIMEOUT", "15"))
|
||||||
|
|
||||||
# Generator URL is used as a callback target when a /fetch-async background
|
# Generator URL is used as a callback target when a /fetch-async background
|
||||||
@@ -31,5 +43,9 @@ DEEP_COLLAB_THRESHOLD = int(os.getenv("DEEP_COLLAB_THRESHOLD", "25"))
|
|||||||
COMMIT_MAX_REPOS = int(os.getenv("COMMIT_MAX_REPOS", "10"))
|
COMMIT_MAX_REPOS = int(os.getenv("COMMIT_MAX_REPOS", "10"))
|
||||||
COMMIT_PER_REPO = int(os.getenv("COMMIT_PER_REPO", "30"))
|
COMMIT_PER_REPO = int(os.getenv("COMMIT_PER_REPO", "30"))
|
||||||
|
|
||||||
|
# Per-repo language-bytes fetches: one REST call each, so cap them to the
|
||||||
|
# most recently pushed repos the user owns (forks excluded).
|
||||||
|
LANGUAGE_MAX_REPOS = int(os.getenv("LANGUAGE_MAX_REPOS", "40"))
|
||||||
|
|
||||||
ANALYTICS_FLUSH_SECONDS = int(os.getenv("ANALYTICS_FLUSH_SECONDS", "5"))
|
ANALYTICS_FLUSH_SECONDS = int(os.getenv("ANALYTICS_FLUSH_SECONDS", "5"))
|
||||||
ANALYTICS_QUEUE_MAX = int(os.getenv("ANALYTICS_QUEUE_MAX", "2000"))
|
ANALYTICS_QUEUE_MAX = int(os.getenv("ANALYTICS_QUEUE_MAX", "2000"))
|
||||||
|
|||||||
+45
-4
@@ -2,19 +2,57 @@
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
from . import config, db, github
|
from . import config, db, github
|
||||||
|
|
||||||
log = logging.getLogger("fetcher.cron")
|
log = logging.getLogger("fetcher.cron")
|
||||||
|
|
||||||
|
|
||||||
|
def _core_remaining() -> int | None:
|
||||||
|
"""Core REST calls left on the PAT, or None if unknown. GitHub does not
|
||||||
|
count /rate_limit calls against the quota."""
|
||||||
|
if not config.GITHUB_PAT:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
r = requests.get("https://api.github.com/rate_limit",
|
||||||
|
headers={"Authorization": f"Bearer {config.GITHUB_PAT}"},
|
||||||
|
timeout=config.API_TIMEOUT)
|
||||||
|
return int(r.json()["resources"]["core"]["remaining"])
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _fetch_retrying_once(username: str) -> dict:
|
||||||
|
"""Fetch a user; on a transient GitHub error wait Retry-After (else the
|
||||||
|
default, capped) and try once more. A second failure propagates."""
|
||||||
|
try:
|
||||||
|
return github.fetch_github_data(username, token=config.GITHUB_PAT)
|
||||||
|
except github.GitHubTransientError as e:
|
||||||
|
wait = min(e.retry_after or config.REFRESH_RETRY_SLEEP, config.REFRESH_RETRY_SLEEP_MAX)
|
||||||
|
log.warning("refresh rate-limited for %s: %s; retrying once in %ss", username, e, wait)
|
||||||
|
time.sleep(wait)
|
||||||
|
return github.fetch_github_data(username, token=config.GITHUB_PAT)
|
||||||
|
|
||||||
|
|
||||||
def tick(hours: int, active_within_days: int, gc_days: int) -> dict:
|
def tick(hours: int, active_within_days: int, gc_days: int) -> dict:
|
||||||
"""Refresh due users, then GC abandoned ones. Returns counts."""
|
"""Refresh due users, then GC abandoned ones. Returns counts."""
|
||||||
refreshed = 0
|
refreshed = 0
|
||||||
failed = 0
|
failed = 0
|
||||||
due = db.users_due_for_refresh(hours=hours, active_within_days=active_within_days)
|
due = db.users_due_for_refresh(hours=hours, active_within_days=active_within_days)
|
||||||
for username in due:
|
deferred = max(len(due) - config.REFRESH_MAX_PER_TICK, 0)
|
||||||
|
due = due[:config.REFRESH_MAX_PER_TICK]
|
||||||
|
for i, username in enumerate(due):
|
||||||
|
if i:
|
||||||
|
time.sleep(config.REFRESH_USER_PAUSE)
|
||||||
|
left = _core_remaining()
|
||||||
|
if left is not None and left < config.REFRESH_CORE_RESERVE:
|
||||||
|
log.info("core budget %s under reserve %s; deferring %s refreshes",
|
||||||
|
left, config.REFRESH_CORE_RESERVE, len(due) - i)
|
||||||
|
deferred += len(due) - i
|
||||||
|
break
|
||||||
try:
|
try:
|
||||||
data = github.fetch_github_data(username, token=config.GITHUB_PAT)
|
data = _fetch_retrying_once(username)
|
||||||
user = data.get("user")
|
user = data.get("user")
|
||||||
if user is None or (isinstance(user, dict) and user.get("message") == "Not Found"):
|
if user is None or (isinstance(user, dict) and user.get("message") == "Not Found"):
|
||||||
data = {"error": "not_found"}
|
data = {"error": "not_found"}
|
||||||
@@ -25,14 +63,17 @@ def tick(hours: int, active_within_days: int, gc_days: int) -> dict:
|
|||||||
refreshed += 1
|
refreshed += 1
|
||||||
except github.GitHubTransientError as e:
|
except github.GitHubTransientError as e:
|
||||||
db.bump_fetch_metric("rate_limited")
|
db.bump_fetch_metric("rate_limited")
|
||||||
log.warning("refresh rate-limited for %s (kept last-good): %s", username, e)
|
log.warning("refresh rate-limited for %s (kept last-good): %s; deferring %s refreshes",
|
||||||
|
username, e, len(due) - i - 1)
|
||||||
failed += 1
|
failed += 1
|
||||||
|
deferred += len(due) - i - 1
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db.bump_fetch_metric("error")
|
db.bump_fetch_metric("error")
|
||||||
log.warning("refresh failed for %s: %s", username, e)
|
log.warning("refresh failed for %s: %s", username, e)
|
||||||
failed += 1
|
failed += 1
|
||||||
gc_removed = db.delete_stale(days=gc_days)
|
gc_removed = db.delete_stale(days=gc_days)
|
||||||
return {"refreshed": refreshed, "failed": failed, "gc_removed": gc_removed}
|
return {"refreshed": refreshed, "failed": failed, "deferred": deferred, "gc_removed": gc_removed}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
+1
-1
@@ -122,7 +122,7 @@ def users_due_for_refresh(hours: int, active_within_days: int) -> list[str]:
|
|||||||
active_after = (datetime.utcnow() - timedelta(days=active_within_days)).isoformat(timespec="seconds") + "Z"
|
active_after = (datetime.utcnow() - timedelta(days=active_within_days)).isoformat(timespec="seconds") + "Z"
|
||||||
with _connect() as c:
|
with _connect() as c:
|
||||||
rows = c.execute(
|
rows = c.execute(
|
||||||
"SELECT username FROM users WHERE fetched_at < ? AND last_requested_at > ?",
|
"SELECT username FROM users WHERE fetched_at < ? AND last_requested_at > ? ORDER BY fetched_at",
|
||||||
(stale_before, active_after),
|
(stale_before, active_after),
|
||||||
).fetchall()
|
).fetchall()
|
||||||
return [r["username"] for r in rows]
|
return [r["username"] for r in rows]
|
||||||
|
|||||||
+18
-5
@@ -47,19 +47,26 @@ class GitHubTransientError(Exception):
|
|||||||
next successful fetch. Propagate it instead so the caller aborts the fetch
|
next successful fetch. Propagate it instead so the caller aborts the fetch
|
||||||
and keeps the previously-cached record."""
|
and keeps the previously-cached record."""
|
||||||
|
|
||||||
|
def __init__(self, msg="", retry_after=None):
|
||||||
|
super().__init__(msg)
|
||||||
|
# Seconds from GitHub's Retry-After header, when it sent one.
|
||||||
|
self.retry_after = retry_after
|
||||||
|
|
||||||
|
|
||||||
def _raise_if_transient(resp) -> None:
|
def _raise_if_transient(resp) -> None:
|
||||||
"""Raise GitHubTransientError if `resp` looks like a rate limit or server
|
"""Raise GitHubTransientError if `resp` looks like a rate limit or server
|
||||||
error. A genuine NOT_FOUND (unknown user) is left alone — that is a real,
|
error. A genuine NOT_FOUND (unknown user) is left alone — that is a real,
|
||||||
persistable "this user has no data" answer, not a transient failure."""
|
persistable "this user has no data" answer, not a transient failure."""
|
||||||
|
retry_after = resp.headers.get("Retry-After")
|
||||||
|
retry_after = int(retry_after) if retry_after and retry_after.isdigit() else None
|
||||||
if resp.status_code in (429, 500, 502, 503, 504):
|
if resp.status_code in (429, 500, 502, 503, 504):
|
||||||
raise GitHubTransientError(f"HTTP {resp.status_code}")
|
raise GitHubTransientError(f"HTTP {resp.status_code}", retry_after)
|
||||||
# Primary/secondary REST rate limits come back as 403 with the remaining
|
# Primary/secondary REST rate limits come back as 403 with the remaining
|
||||||
# budget at 0 (or a "secondary rate limit" message).
|
# budget at 0 (or a "secondary rate limit" message).
|
||||||
if resp.status_code == 403 and resp.headers.get("X-RateLimit-Remaining") == "0":
|
if resp.status_code == 403 and resp.headers.get("X-RateLimit-Remaining") == "0":
|
||||||
raise GitHubTransientError("REST rate limit exhausted")
|
raise GitHubTransientError("REST rate limit exhausted", retry_after)
|
||||||
if resp.status_code == 403 and "rate limit" in (resp.text or "").lower():
|
if resp.status_code == 403 and "rate limit" in (resp.text or "").lower():
|
||||||
raise GitHubTransientError("REST rate limit exhausted")
|
raise GitHubTransientError("REST rate limit exhausted", retry_after)
|
||||||
# GraphQL reports rate limits as HTTP 200 with an `errors` array — the same
|
# GraphQL reports rate limits as HTTP 200 with an `errors` array — the same
|
||||||
# 200 that a valid response uses — so the body has to be inspected.
|
# 200 that a valid response uses — so the body has to be inspected.
|
||||||
try:
|
try:
|
||||||
@@ -714,7 +721,7 @@ def fetch_github_data(
|
|||||||
avatar_b64 = ""
|
avatar_b64 = ""
|
||||||
avatar_url = user.get("avatar_url") if isinstance(user, dict) else None
|
avatar_url = user.get("avatar_url") if isinstance(user, dict) else None
|
||||||
with ThreadPoolExecutor(max_workers=2, thread_name_prefix="fetch-stage2") as pool:
|
with ThreadPoolExecutor(max_workers=2, thread_name_prefix="fetch-stage2") as pool:
|
||||||
fut_lang = pool.submit(_enrich_repo_languages, repos, source)
|
fut_lang = pool.submit(_enrich_repo_languages, repos, source, username)
|
||||||
fut_avatar = pool.submit(source.fetch_avatar, avatar_url) if avatar_url else None
|
fut_avatar = pool.submit(source.fetch_avatar, avatar_url) if avatar_url else None
|
||||||
fut_lang.result()
|
fut_lang.result()
|
||||||
if fut_avatar is not None:
|
if fut_avatar is not None:
|
||||||
@@ -733,13 +740,19 @@ def fetch_github_data(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _enrich_repo_languages(repos: list, source: GitHubDataSource) -> None:
|
def _enrich_repo_languages(repos: list, source: GitHubDataSource, username: str = "") -> None:
|
||||||
"""Mutates `repos` in-place, attaching `language_bytes: {lang: bytes}` to
|
"""Mutates `repos` in-place, attaching `language_bytes: {lang: bytes}` to
|
||||||
each repo. Uses a small thread pool — one REST call per repo is cheap
|
each repo. Uses a small thread pool — one REST call per repo is cheap
|
||||||
individually, but sequentially N repos would block the fetch noticeably."""
|
individually, but sequentially N repos would block the fetch noticeably."""
|
||||||
if not repos:
|
if not repos:
|
||||||
return
|
return
|
||||||
names = [(i, r["full_name"]) for i, r in enumerate(repos) if r.get("full_name")]
|
names = [(i, r["full_name"]) for i, r in enumerate(repos) if r.get("full_name")]
|
||||||
|
if username:
|
||||||
|
owner = username.lower()
|
||||||
|
names = [(i, fn) for i, fn in names
|
||||||
|
if not repos[i].get("fork") and fn.split("/")[0].lower() == owner]
|
||||||
|
names.sort(key=lambda p: repos[p[0]].get("pushed_at") or "", reverse=True)
|
||||||
|
names = names[:config.LANGUAGE_MAX_REPOS]
|
||||||
print(f" Fetching language byte breakdown for {len(names)} repos...")
|
print(f" Fetching language byte breakdown for {len(names)} repos...")
|
||||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||||
futures = {pool.submit(source.fetch_repo_languages, fn): i for i, fn in names}
|
futures = {pool.submit(source.fetch_repo_languages, fn): i for i, fn in names}
|
||||||
|
|||||||
@@ -203,3 +203,42 @@ def test_rate_limit_body_is_not_classified_as_valid_user_data():
|
|||||||
assert apimod._is_github_not_found({"user": {"login": "alice"}}) is False
|
assert apimod._is_github_not_found({"user": {"login": "alice"}}) is False
|
||||||
assert apimod._is_github_not_found({"user": {"message": "Not Found"}}) is True
|
assert apimod._is_github_not_found({"user": {"message": "Not Found"}}) is True
|
||||||
assert apimod._is_github_not_found({"user": None}) is True
|
assert apimod._is_github_not_found({"user": None}) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_data_miss_rate_limited_returns_503(client, monkeypatch):
|
||||||
|
# A spent GitHub quota is transient: the fetcher says so (503), so the
|
||||||
|
# generator can tell the user the card will build after the reset.
|
||||||
|
def fake_fetch(*_a, **_kw):
|
||||||
|
raise apimod.github.GitHubTransientError("REST rate limit exhausted")
|
||||||
|
monkeypatch.setattr(apimod.github, "fetch_github_data", fake_fetch)
|
||||||
|
r = client.get("/data/alice", headers={"X-Internal-Token": "secret"})
|
||||||
|
assert r.status_code == 503
|
||||||
|
assert r.get_json() == {"error": "github_rate_limited"}
|
||||||
|
assert dbmod.get_user("alice") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_concurrent_data_misses_fetch_once(client, monkeypatch):
|
||||||
|
# Concurrent misses for one user used to each run a full GitHub fetch;
|
||||||
|
# the per-user lock makes later callers read what the first stored.
|
||||||
|
import threading, time as _time
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
def fake_fetch(username, **_kw):
|
||||||
|
calls.append(username)
|
||||||
|
_time.sleep(0.3)
|
||||||
|
return {"user": {"login": username}, "repos": [], "events": []}
|
||||||
|
monkeypatch.setattr(apimod.github, "fetch_github_data", fake_fetch)
|
||||||
|
monkeypatch.setattr(apimod, "_is_github_not_found", lambda _d: False)
|
||||||
|
app = apimod.app
|
||||||
|
codes = []
|
||||||
|
|
||||||
|
def hit():
|
||||||
|
with app.test_client() as c:
|
||||||
|
codes.append(c.get("/data/alice", headers={"X-Internal-Token": "secret"}).status_code)
|
||||||
|
threads = [threading.Thread(target=hit) for _ in range(3)]
|
||||||
|
for t in threads:
|
||||||
|
t.start()
|
||||||
|
for t in threads:
|
||||||
|
t.join()
|
||||||
|
assert codes == [200, 200, 200]
|
||||||
|
assert calls == ["alice"]
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ def tmp_db(monkeypatch):
|
|||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def sleeps(monkeypatch):
|
||||||
|
# The tick pauses between users and before a retry; record, don't wait.
|
||||||
|
calls = []
|
||||||
|
monkeypatch.setattr(cronmod.time, "sleep", calls.append)
|
||||||
|
return calls
|
||||||
|
|
||||||
|
|
||||||
def test_refresh_tick_calls_github_for_due_users(tmp_db):
|
def test_refresh_tick_calls_github_for_due_users(tmp_db):
|
||||||
dbmod.upsert_user("alice", {"user": {"login": "alice"}})
|
dbmod.upsert_user("alice", {"user": {"login": "alice"}})
|
||||||
# Backdate
|
# Backdate
|
||||||
@@ -50,3 +58,68 @@ def test_tick_runs_gc_for_abandoned_trial_users(tmp_db):
|
|||||||
stats = cronmod.tick(hours=24, active_within_days=7, gc_days=7)
|
stats = cronmod.tick(hours=24, active_within_days=7, gc_days=7)
|
||||||
assert stats["gc_removed"] == 1
|
assert stats["gc_removed"] == 1
|
||||||
assert dbmod.get_user("ghost") is None
|
assert dbmod.get_user("ghost") is None
|
||||||
|
|
||||||
|
|
||||||
|
def _due(*names):
|
||||||
|
# Backdate each user so they're due; later names are fetched more recently.
|
||||||
|
for i, n in enumerate(names):
|
||||||
|
dbmod.upsert_user(n, {"user": {"login": n}})
|
||||||
|
with dbmod._connect() as c:
|
||||||
|
c.execute("UPDATE users SET fetched_at=?, last_requested_at=? WHERE username=?",
|
||||||
|
(f"2020-01-0{i + 1}T00:00:00Z", dbmod._now(), n))
|
||||||
|
|
||||||
|
|
||||||
|
def test_tick_caps_refreshes_oldest_first(tmp_db, monkeypatch):
|
||||||
|
_due("old", "mid", "new")
|
||||||
|
monkeypatch.setattr(cronmod.config, "REFRESH_MAX_PER_TICK", 2)
|
||||||
|
monkeypatch.setattr(cronmod, "_core_remaining", lambda: None)
|
||||||
|
with patch("src.cron.github.fetch_github_data", side_effect=lambda u, **_k: {"user": {"login": u}}) as gh:
|
||||||
|
stats = cronmod.tick(hours=24, active_within_days=7, gc_days=7)
|
||||||
|
assert [c.args[0] for c in gh.call_args_list] == ["old", "mid"]
|
||||||
|
assert stats["refreshed"] == 2 and stats["deferred"] == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_tick_stops_under_core_reserve(tmp_db, monkeypatch):
|
||||||
|
# New sign-ups need the quota more than a day-old card does: once the
|
||||||
|
# PAT's core budget drops under the reserve, the tick stops refreshing.
|
||||||
|
_due("a", "b", "c")
|
||||||
|
monkeypatch.setattr(cronmod.config, "REFRESH_CORE_RESERVE", 1500)
|
||||||
|
left = iter([4000, 1400, 1400])
|
||||||
|
monkeypatch.setattr(cronmod, "_core_remaining", lambda: next(left))
|
||||||
|
with patch("src.cron.github.fetch_github_data", side_effect=lambda u, **_k: {"user": {"login": u}}) as gh:
|
||||||
|
stats = cronmod.tick(hours=24, active_within_days=7, gc_days=7)
|
||||||
|
assert [c.args[0] for c in gh.call_args_list] == ["a"]
|
||||||
|
assert stats["refreshed"] == 1 and stats["deferred"] == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_tick_retries_once_after_capped_retry_after(tmp_db, monkeypatch, sleeps):
|
||||||
|
# A secondary rate limit clears after a wait: honour Retry-After (capped)
|
||||||
|
# and retry the same user once; pause between users.
|
||||||
|
_due("a", "b")
|
||||||
|
monkeypatch.setattr(cronmod, "_core_remaining", lambda: None)
|
||||||
|
results = iter([ghmod.GitHubTransientError("rate limited", retry_after=500),
|
||||||
|
{"user": {"login": "a"}}, {"user": {"login": "b"}}])
|
||||||
|
|
||||||
|
def fake(u, **_k):
|
||||||
|
r = next(results)
|
||||||
|
if isinstance(r, Exception):
|
||||||
|
raise r
|
||||||
|
return r
|
||||||
|
with patch("src.cron.github.fetch_github_data", side_effect=fake) as gh:
|
||||||
|
stats = cronmod.tick(hours=24, active_within_days=7, gc_days=7)
|
||||||
|
assert [c.args[0] for c in gh.call_args_list] == ["a", "a", "b"]
|
||||||
|
assert sleeps == [120, 1.5]
|
||||||
|
assert stats["refreshed"] == 2 and stats["failed"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_tick_stops_and_defers_after_second_rate_limit(tmp_db, monkeypatch, sleeps):
|
||||||
|
# Hammering on after a repeat rate limit only fails every remaining user;
|
||||||
|
# stop the tick and leave them due for the next one.
|
||||||
|
_due("a", "b", "c")
|
||||||
|
monkeypatch.setattr(cronmod, "_core_remaining", lambda: None)
|
||||||
|
with patch("src.cron.github.fetch_github_data",
|
||||||
|
side_effect=ghmod.GitHubTransientError("rate limited")) as gh:
|
||||||
|
stats = cronmod.tick(hours=24, active_within_days=7, gc_days=7)
|
||||||
|
assert [c.args[0] for c in gh.call_args_list] == ["a", "a"]
|
||||||
|
assert sleeps == [60]
|
||||||
|
assert stats["failed"] == 1 and stats["refreshed"] == 0 and stats["deferred"] == 2
|
||||||
|
|||||||
@@ -250,3 +250,43 @@ def test_rate_limited_repo_languages_aborts_whole_fetch():
|
|||||||
repos = [{"full_name": "alice/proj"}]
|
repos = [{"full_name": "alice/proj"}]
|
||||||
with pytest.raises(github.GitHubTransientError):
|
with pytest.raises(github.GitHubTransientError):
|
||||||
github._enrich_repo_languages(repos, src)
|
github._enrich_repo_languages(repos, src)
|
||||||
|
|
||||||
|
|
||||||
|
def test_repo_languages_capped_to_recent_owned_repos(monkeypatch):
|
||||||
|
# One REST call per repo, so only the most recently pushed non-fork repos
|
||||||
|
# the user owns get a byte breakdown.
|
||||||
|
monkeypatch.setattr(github.config, "LANGUAGE_MAX_REPOS", 2)
|
||||||
|
|
||||||
|
class _Src:
|
||||||
|
def __init__(self):
|
||||||
|
self.calls = []
|
||||||
|
|
||||||
|
def fetch_repo_languages(self, full_name):
|
||||||
|
self.calls.append(full_name)
|
||||||
|
return {"Python": 1}
|
||||||
|
|
||||||
|
repos = [
|
||||||
|
{"full_name": "Alice/old", "pushed_at": "2024-01-01T00:00:00Z"},
|
||||||
|
{"full_name": "alice/new", "pushed_at": "2026-01-01T00:00:00Z"},
|
||||||
|
{"full_name": "alice/mid", "pushed_at": "2025-01-01T00:00:00Z"},
|
||||||
|
{"full_name": "alice/fork", "pushed_at": "2026-06-01T00:00:00Z", "fork": True},
|
||||||
|
{"full_name": "org/other", "pushed_at": "2026-06-01T00:00:00Z"},
|
||||||
|
]
|
||||||
|
src = _Src()
|
||||||
|
github._enrich_repo_languages(repos, src, "alice")
|
||||||
|
assert sorted(src.calls) == ["alice/mid", "alice/new"]
|
||||||
|
assert repos[1]["language_bytes"] == {"Python": 1}
|
||||||
|
assert "language_bytes" not in repos[0]
|
||||||
|
|
||||||
|
|
||||||
|
@responses.activate
|
||||||
|
def test_rate_limit_error_carries_retry_after():
|
||||||
|
responses.add(
|
||||||
|
responses.GET, "https://api.github.com/users/alice",
|
||||||
|
json={"message": "You have exceeded a secondary rate limit."}, status=403,
|
||||||
|
headers={"Retry-After": "42"},
|
||||||
|
)
|
||||||
|
src = github.DirectAPISource(token="t")
|
||||||
|
with pytest.raises(github.GitHubTransientError) as exc:
|
||||||
|
src.fetch_user_data("alice")
|
||||||
|
assert exc.value.retry_after == 42
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ COPY requirements.txt ./
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
COPY gunicorn.conf.py ./
|
||||||
RUN mkdir -p /app/src/static /app/data
|
RUN mkdir -p /app/src/static /app/data
|
||||||
COPY --from=frontend-build /app/frontend/dist/ /app/src/static/
|
COPY --from=frontend-build /app/frontend/dist/ /app/src/static/
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
45e91fcd547e2331201dd125dd388d94
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>How to create a GitHub profile README (and add a stats card)</title>
|
||||||
|
<meta name="description"
|
||||||
|
content="Create the special repository that GitHub shows on your profile, then add a live stats card with one line of markdown. Five steps, about two minutes, no signup."/>
|
||||||
|
<link rel="canonical" href="https://gh-stats.com/github-profile-readme.html"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||||
|
<meta property="og:type" content="article"/>
|
||||||
|
<meta property="og:site_name" content="gh-stats"/>
|
||||||
|
<meta property="og:url" content="https://gh-stats.com/github-profile-readme.html"/>
|
||||||
|
<meta property="og:title" content="How to create a GitHub profile README"/>
|
||||||
|
<meta property="og:description"
|
||||||
|
content="The special repository, the one setting that trips people up, and a stats card in one line."/>
|
||||||
|
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||||
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
|
||||||
|
<script type="module">
|
||||||
|
// Same GA4 stream as the SPA (index.html), so this page's traffic and its
|
||||||
|
// referrers land in the existing property instead of going unmeasured.
|
||||||
|
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||||
|
import {getAnalytics} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-analytics.js";
|
||||||
|
getAnalytics(initializeApp({
|
||||||
|
apiKey: "AIzaSyCy2pUW8Geo0Aagq9mTYKlfCpa9GUIXpy8",
|
||||||
|
authDomain: "gh-stats-284de.firebaseapp.com",
|
||||||
|
projectId: "gh-stats-284de",
|
||||||
|
storageBucket: "gh-stats-284de.firebasestorage.app",
|
||||||
|
messagingSenderId: "723662839762",
|
||||||
|
appId: "1:723662839762:web:4ba5337f6489ea67dc320b",
|
||||||
|
measurementId: "G-228GR89RYX"
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#f9fafb; --card:#ffffff; --line:#e5e7eb;
|
||||||
|
--ink:#1f2937; --muted:#6b7280; --faint:#9ca3af; --accent:#0969da;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{margin:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:'DM Sans',system-ui,sans-serif;-webkit-font-smoothing:antialiased;
|
||||||
|
line-height:1.65}
|
||||||
|
main{max-width:760px;margin:0 auto;padding:56px 24px 96px}
|
||||||
|
h1{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:2.6rem;line-height:1.15;letter-spacing:-.01em;margin:0 0 16px}
|
||||||
|
h2{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:1.65rem;margin:48px 0 12px;letter-spacing:-.01em}
|
||||||
|
p{margin:0 0 16px}
|
||||||
|
.lede{font-size:1.08rem;color:var(--muted);margin-bottom:32px}
|
||||||
|
a{color:var(--accent);text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
code,pre{font-family:'JetBrains Mono',ui-monospace,monospace;font-size:.86rem}
|
||||||
|
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||||||
|
padding:14px 16px;overflow-x:auto;margin:0 0 16px}
|
||||||
|
code:not(pre code){background:#f3f4f6;border-radius:5px;padding:.12em .38em;font-size:.85em}
|
||||||
|
.tablewrap{overflow-x:auto;margin:0 0 16px}
|
||||||
|
table{border-collapse:collapse;width:100%;font-size:.86rem;background:var(--card);
|
||||||
|
border:1px solid var(--line);border-radius:10px}
|
||||||
|
th,td{text-align:left;padding:10px 14px;border-bottom:1px solid var(--line);
|
||||||
|
vertical-align:top}
|
||||||
|
th{font-weight:600;color:var(--muted);font-size:.78rem;text-transform:uppercase;
|
||||||
|
letter-spacing:.04em}
|
||||||
|
tr:last-child td{border-bottom:none}
|
||||||
|
td code{white-space:nowrap}
|
||||||
|
figure{margin:0 0 28px}
|
||||||
|
figure img{width:100%;max-width:400px;display:block;border-radius:12px}
|
||||||
|
figcaption{color:var(--faint);font-size:.8rem;margin-top:8px}
|
||||||
|
.clip{position:relative;max-width:340px;max-height:400px;overflow:hidden;
|
||||||
|
border-radius:12px}
|
||||||
|
.clip img{width:100%;display:block;border-radius:12px}
|
||||||
|
.clip::after{content:"";position:absolute;left:0;right:0;bottom:0;height:72px;
|
||||||
|
background:linear-gradient(to top,var(--bg),transparent)}
|
||||||
|
.cta{display:inline-block;background:var(--ink);color:#fff;border-radius:9px;
|
||||||
|
padding:11px 20px;font-weight:600;font-size:.92rem;margin:8px 0 0}
|
||||||
|
.cta:hover{text-decoration:none;opacity:.9}
|
||||||
|
.note{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted);
|
||||||
|
font-size:.92rem;margin:0 0 16px}
|
||||||
|
footer{border-top:1px solid var(--line);margin-top:64px;padding-top:20px;
|
||||||
|
color:var(--faint);font-size:.82rem}
|
||||||
|
@media (max-width:640px){h1{font-size:2.05rem}main{padding:36px 20px 72px}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<h1>How to create a GitHub profile README</h1>
|
||||||
|
|
||||||
|
<p class="lede">
|
||||||
|
A profile README is the block of text and images at the top of your GitHub profile
|
||||||
|
page. GitHub builds it from one specific repository, so setting it up is a matter of
|
||||||
|
creating that repository and writing a README in it.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>What GitHub needs</h2>
|
||||||
|
|
||||||
|
<p>GitHub shows a README on your profile when all four of these hold:</p>
|
||||||
|
|
||||||
|
<div class="tablewrap">
|
||||||
|
<table>
|
||||||
|
<tr><th>Requirement</th><th>Example for the username <code>octocat</code></th></tr>
|
||||||
|
<tr><td>A repository named exactly like your username</td><td><code>octocat/octocat</code></td></tr>
|
||||||
|
<tr><td>The repository is public</td><td>Visibility: Public</td></tr>
|
||||||
|
<tr><td>A file named <code>README.md</code> in its root</td><td><code>octocat/octocat/README.md</code></td></tr>
|
||||||
|
<tr><td>The file is not empty</td><td>Any text at all</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Create it in five steps</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
1. Open <a href="https://github.com/new">github.com/new</a>.<br/>
|
||||||
|
2. Under Repository name, type your username exactly. GitHub confirms with a
|
||||||
|
note that this is a special repository.<br/>
|
||||||
|
3. Select <strong>Public</strong>.<br/>
|
||||||
|
4. Turn on <strong>Add a README file</strong>.<br/>
|
||||||
|
5. Click <strong>Create repository</strong>, then <strong>Edit README</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Save any text and your profile page shows it. The pre-filled template is fine to
|
||||||
|
keep, replace, or delete.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
To start from a finished layout instead, open the
|
||||||
|
<a href="https://github.com/ShayManor/profile-readme-template">profile README template</a>,
|
||||||
|
click <strong>Use this template</strong>, name the new repository after your username,
|
||||||
|
and replace <code>YOUR_USERNAME</code> in its README.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="note">
|
||||||
|
If you made a public repository with your username before July 2020, GitHub does
|
||||||
|
not show it automatically. Open the repository and click <strong>Share to
|
||||||
|
profile</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Add a stats card</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Paste this line into the README, replace the username in both places, and commit:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://gh-stats.com)</code></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
It renders one card with a score out of 100, your contribution timeline, top
|
||||||
|
collaborators, language breakdown and commit streaks, and it updates on its own.
|
||||||
|
The first request for a new username queues a build, so give it a minute.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<div class="clip">
|
||||||
|
<img src="https://gh-stats.com/api/ShayManor" alt="A gh-stats card: profile score, impact timeline, collaborators, languages, streaks and achievements."/>
|
||||||
|
</div>
|
||||||
|
<figcaption>A stats card in a profile README, cropped.</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<a class="cta" href="https://gh-stats.com/">Preview the card for your username</a>
|
||||||
|
|
||||||
|
<p style="margin-top:24px">
|
||||||
|
Want only one part? The
|
||||||
|
<a href="https://gh-stats.com/github-top-languages-card.html">top languages card</a>
|
||||||
|
works the same way, and there are <a href="https://gh-stats.com/github-readme-themes.html">five
|
||||||
|
themes</a> to pick from. Already using github-readme-stats? See the
|
||||||
|
<a href="https://gh-stats.com/github-readme-stats-alternative.html">migration guide</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Common questions</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>I created the repository but my profile shows nothing.</strong> Check the
|
||||||
|
four requirements above. The usual cause is a private repository or a name that does
|
||||||
|
not match the username exactly.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Can I edit it later?</strong> Yes. Every commit to that <code>README.md</code>
|
||||||
|
updates your profile page.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Does the card need a token or an account?</strong> No. It reads public
|
||||||
|
GitHub activity only, and there is nothing to sign up for.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> ·
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">source on GitHub</a> ·
|
||||||
|
MIT licensed
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>github-profile-trophy not loading (402)? Two fixes</title>
|
||||||
|
<meta name="description"
|
||||||
|
content="github-profile-trophy.vercel.app returns HTTP 402, so trophy images in GitHub profile READMEs are broken. Self-host it, or swap in a rank card with one line."/>
|
||||||
|
<link rel="canonical" href="https://gh-stats.com/github-profile-trophy-alternative.html"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||||
|
<meta property="og:type" content="article"/>
|
||||||
|
<meta property="og:site_name" content="gh-stats"/>
|
||||||
|
<meta property="og:url" content="https://gh-stats.com/github-profile-trophy-alternative.html"/>
|
||||||
|
<meta property="og:title" content="github-profile-trophy not loading? Two fixes"/>
|
||||||
|
<meta property="og:description"
|
||||||
|
content="The public trophy instance returns 402. Self-host it, or use a rank card instead."/>
|
||||||
|
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||||
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
|
||||||
|
<script type="module">
|
||||||
|
// Same GA4 stream as the SPA (index.html), so this page's traffic and its
|
||||||
|
// referrers land in the existing property instead of going unmeasured.
|
||||||
|
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||||
|
import {getAnalytics} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-analytics.js";
|
||||||
|
getAnalytics(initializeApp({
|
||||||
|
apiKey: "AIzaSyCy2pUW8Geo0Aagq9mTYKlfCpa9GUIXpy8",
|
||||||
|
authDomain: "gh-stats-284de.firebaseapp.com",
|
||||||
|
projectId: "gh-stats-284de",
|
||||||
|
storageBucket: "gh-stats-284de.firebasestorage.app",
|
||||||
|
messagingSenderId: "723662839762",
|
||||||
|
appId: "1:723662839762:web:4ba5337f6489ea67dc320b",
|
||||||
|
measurementId: "G-228GR89RYX"
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#f9fafb; --card:#ffffff; --line:#e5e7eb;
|
||||||
|
--ink:#1f2937; --muted:#6b7280; --faint:#9ca3af; --accent:#0969da;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{margin:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:'DM Sans',system-ui,sans-serif;-webkit-font-smoothing:antialiased;
|
||||||
|
line-height:1.65}
|
||||||
|
main{max-width:760px;margin:0 auto;padding:56px 24px 96px}
|
||||||
|
h1{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:2.6rem;line-height:1.15;letter-spacing:-.01em;margin:0 0 16px}
|
||||||
|
h2{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:1.65rem;margin:48px 0 12px;letter-spacing:-.01em}
|
||||||
|
p{margin:0 0 16px}
|
||||||
|
.lede{font-size:1.08rem;color:var(--muted);margin-bottom:32px}
|
||||||
|
a{color:var(--accent);text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
code,pre{font-family:'JetBrains Mono',ui-monospace,monospace;font-size:.86rem}
|
||||||
|
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||||||
|
padding:14px 16px;overflow-x:auto;margin:0 0 16px}
|
||||||
|
code:not(pre code){background:#f3f4f6;border-radius:5px;padding:.12em .38em;font-size:.85em}
|
||||||
|
.tablewrap{overflow-x:auto;margin:0 0 16px}
|
||||||
|
table{border-collapse:collapse;width:100%;font-size:.86rem;background:var(--card);
|
||||||
|
border:1px solid var(--line);border-radius:10px}
|
||||||
|
th,td{text-align:left;padding:10px 14px;border-bottom:1px solid var(--line);
|
||||||
|
vertical-align:top}
|
||||||
|
th{font-weight:600;color:var(--muted);font-size:.78rem;text-transform:uppercase;
|
||||||
|
letter-spacing:.04em}
|
||||||
|
tr:last-child td{border-bottom:none}
|
||||||
|
td code{white-space:nowrap}
|
||||||
|
figure{margin:0 0 28px}
|
||||||
|
figure img{width:100%;max-width:400px;display:block;border-radius:12px}
|
||||||
|
figcaption{color:var(--faint);font-size:.8rem;margin-top:8px}
|
||||||
|
.clip{position:relative;max-width:340px;max-height:400px;overflow:hidden;
|
||||||
|
border-radius:12px}
|
||||||
|
.clip img{width:100%;display:block;border-radius:12px}
|
||||||
|
.clip::after{content:"";position:absolute;left:0;right:0;bottom:0;height:72px;
|
||||||
|
background:linear-gradient(to top,var(--bg),transparent)}
|
||||||
|
.cta{display:inline-block;background:var(--ink);color:#fff;border-radius:9px;
|
||||||
|
padding:11px 20px;font-weight:600;font-size:.92rem;margin:8px 0 0}
|
||||||
|
.cta:hover{text-decoration:none;opacity:.9}
|
||||||
|
.note{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted);
|
||||||
|
font-size:.92rem;margin:0 0 16px}
|
||||||
|
footer{border-top:1px solid var(--line);margin-top:64px;padding-top:20px;
|
||||||
|
color:var(--faint);font-size:.82rem}
|
||||||
|
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:20px;margin:0 0 16px}
|
||||||
|
.grid .clip{max-height:300px}
|
||||||
|
.grid h3{font-size:1rem;margin:0 0 8px}
|
||||||
|
.grid pre{font-size:.72rem;margin-top:10px}
|
||||||
|
@media (max-width:640px){h1{font-size:2.05rem}main{padding:36px 20px 72px}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<h1>github-profile-trophy not loading?</h1>
|
||||||
|
|
||||||
|
<p class="lede">
|
||||||
|
The public instance at <code>github-profile-trophy.vercel.app</code> returns
|
||||||
|
<code>402 Payment required</code> (Vercel's <code>DEPLOYMENT_DISABLED</code>), so every
|
||||||
|
README that embeds it shows a broken image. There are two ways to fix it: run your own
|
||||||
|
copy, or switch to a different card.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Is yours broken?</h2>
|
||||||
|
|
||||||
|
<p>Open your profile. If the trophies are a broken-image icon or alt text, your README
|
||||||
|
points at the disabled instance. The line looks like this:</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://github.com/ryo-ma/github-profile-trophy)</code></pre>
|
||||||
|
|
||||||
|
<h2>Fix 1: host your own copy</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The project is open source and its README asks users to fork it and deploy the fork to
|
||||||
|
Vercel, then point the image at the new address. Its README also lists volunteer
|
||||||
|
mirrors, but most of them returned errors when this page was written (November 2026),
|
||||||
|
so a mirror may break again.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Fix 2: a rank card, in one line</h2>
|
||||||
|
|
||||||
|
<p>To switch to gh-stats instead, replace the line with this one, change the username, and commit:</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://gh-stats.com)</code></pre>
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<img src="https://gh-stats.com/api/torvalds/grade.svg" alt="gh-stats grade card: a letter rank, a score out of 100, and commit, PR, star, repo and follower counts." style="max-width:380px"/>
|
||||||
|
<figcaption>The grade card for torvalds, rendered live.</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There is no token to create, no signup and nothing to deploy. The first request for a
|
||||||
|
new username queues a build, so the image can take a minute to appear.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>How it differs</h2>
|
||||||
|
|
||||||
|
<div class="tablewrap">
|
||||||
|
<table>
|
||||||
|
<tr><th></th><th>github-profile-trophy</th><th>gh-stats grade card</th></tr>
|
||||||
|
<tr><td>Shows</td><td>A row of trophies, each with its own rank</td><td>One overall rank and score, plus commits, PRs, stars, repos and followers</td></tr>
|
||||||
|
<tr><td>Extras</td><td>Many themes, row and column layout</td><td>Role tags worked out from your repos; five themes</td></tr>
|
||||||
|
<tr><td>Hosting</td><td>Public instance returns 402; self-host on Vercel</td><td>gh-stats.com, or self-host (MIT)</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Want the whole profile?</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Drop the <code>/grade.svg</code> and the same URL renders one card with the rank, a
|
||||||
|
contribution timeline, top collaborators, languages and streaks:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://gh-stats.com)</code></pre>
|
||||||
|
|
||||||
|
<a class="cta" href="https://gh-stats.com/">Preview it for your username</a>
|
||||||
|
|
||||||
|
<p style="margin-top:24px">
|
||||||
|
See the <a href="https://gh-stats.com/github-readme-themes.html">five themes</a>, or
|
||||||
|
<a href="https://gh-stats.com/github-profile-readme.html">how to create a profile README</a>
|
||||||
|
if you do not have one yet.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Common questions</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Does gh-stats need access to my account?</strong> No. It reads public GitHub
|
||||||
|
activity only.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> ·
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">source on GitHub</a> ·
|
||||||
|
MIT licensed
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>github-readme-activity-graph not loading (402)? Two fixes</title>
|
||||||
|
<meta name="description"
|
||||||
|
content="The vercel.app address of github-readme-activity-graph returns HTTP 402. Point at the project's new address, or swap in a different contribution graph with one line."/>
|
||||||
|
<link rel="canonical" href="https://gh-stats.com/github-readme-activity-graph-alternative.html"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||||
|
<meta property="og:type" content="article"/>
|
||||||
|
<meta property="og:site_name" content="gh-stats"/>
|
||||||
|
<meta property="og:url" content="https://gh-stats.com/github-readme-activity-graph-alternative.html"/>
|
||||||
|
<meta property="og:title" content="github-readme-activity-graph not loading? Two fixes"/>
|
||||||
|
<meta property="og:description"
|
||||||
|
content="The old vercel.app address returns 402. Here is the new one, and an alternative."/>
|
||||||
|
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||||
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
|
||||||
|
<script type="module">
|
||||||
|
// Same GA4 stream as the SPA (index.html), so this page's traffic and its
|
||||||
|
// referrers land in the existing property instead of going unmeasured.
|
||||||
|
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||||
|
import {getAnalytics} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-analytics.js";
|
||||||
|
getAnalytics(initializeApp({
|
||||||
|
apiKey: "AIzaSyCy2pUW8Geo0Aagq9mTYKlfCpa9GUIXpy8",
|
||||||
|
authDomain: "gh-stats-284de.firebaseapp.com",
|
||||||
|
projectId: "gh-stats-284de",
|
||||||
|
storageBucket: "gh-stats-284de.firebasestorage.app",
|
||||||
|
messagingSenderId: "723662839762",
|
||||||
|
appId: "1:723662839762:web:4ba5337f6489ea67dc320b",
|
||||||
|
measurementId: "G-228GR89RYX"
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#f9fafb; --card:#ffffff; --line:#e5e7eb;
|
||||||
|
--ink:#1f2937; --muted:#6b7280; --faint:#9ca3af; --accent:#0969da;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{margin:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:'DM Sans',system-ui,sans-serif;-webkit-font-smoothing:antialiased;
|
||||||
|
line-height:1.65}
|
||||||
|
main{max-width:760px;margin:0 auto;padding:56px 24px 96px}
|
||||||
|
h1{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:2.6rem;line-height:1.15;letter-spacing:-.01em;margin:0 0 16px}
|
||||||
|
h2{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:1.65rem;margin:48px 0 12px;letter-spacing:-.01em}
|
||||||
|
p{margin:0 0 16px}
|
||||||
|
.lede{font-size:1.08rem;color:var(--muted);margin-bottom:32px}
|
||||||
|
a{color:var(--accent);text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
code,pre{font-family:'JetBrains Mono',ui-monospace,monospace;font-size:.86rem}
|
||||||
|
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||||||
|
padding:14px 16px;overflow-x:auto;margin:0 0 16px}
|
||||||
|
code:not(pre code){background:#f3f4f6;border-radius:5px;padding:.12em .38em;font-size:.85em}
|
||||||
|
.tablewrap{overflow-x:auto;margin:0 0 16px}
|
||||||
|
table{border-collapse:collapse;width:100%;font-size:.86rem;background:var(--card);
|
||||||
|
border:1px solid var(--line);border-radius:10px}
|
||||||
|
th,td{text-align:left;padding:10px 14px;border-bottom:1px solid var(--line);
|
||||||
|
vertical-align:top}
|
||||||
|
th{font-weight:600;color:var(--muted);font-size:.78rem;text-transform:uppercase;
|
||||||
|
letter-spacing:.04em}
|
||||||
|
tr:last-child td{border-bottom:none}
|
||||||
|
td code{white-space:nowrap}
|
||||||
|
figure{margin:0 0 28px}
|
||||||
|
figure img{width:100%;max-width:400px;display:block;border-radius:12px}
|
||||||
|
figcaption{color:var(--faint);font-size:.8rem;margin-top:8px}
|
||||||
|
.clip{position:relative;max-width:340px;max-height:400px;overflow:hidden;
|
||||||
|
border-radius:12px}
|
||||||
|
.clip img{width:100%;display:block;border-radius:12px}
|
||||||
|
.clip::after{content:"";position:absolute;left:0;right:0;bottom:0;height:72px;
|
||||||
|
background:linear-gradient(to top,var(--bg),transparent)}
|
||||||
|
.cta{display:inline-block;background:var(--ink);color:#fff;border-radius:9px;
|
||||||
|
padding:11px 20px;font-weight:600;font-size:.92rem;margin:8px 0 0}
|
||||||
|
.cta:hover{text-decoration:none;opacity:.9}
|
||||||
|
.note{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted);
|
||||||
|
font-size:.92rem;margin:0 0 16px}
|
||||||
|
footer{border-top:1px solid var(--line);margin-top:64px;padding-top:20px;
|
||||||
|
color:var(--faint);font-size:.82rem}
|
||||||
|
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:20px;margin:0 0 16px}
|
||||||
|
.grid .clip{max-height:300px}
|
||||||
|
.grid h3{font-size:1rem;margin:0 0 8px}
|
||||||
|
.grid pre{font-size:.72rem;margin-top:10px}
|
||||||
|
@media (max-width:640px){h1{font-size:2.05rem}main{padding:36px 20px 72px}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<h1>github-readme-activity-graph not loading?</h1>
|
||||||
|
|
||||||
|
<p class="lede">
|
||||||
|
The old github-readme-activity-graph address on vercel.app has returned
|
||||||
|
<code>402 Payment required</code> (Vercel's <code>DEPLOYMENT_DISABLED</code>) since
|
||||||
|
September 2026, so READMEs that still use it show a broken image. There are two ways
|
||||||
|
to fix it: point at the project's new address, or switch to a different graph.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Is yours broken?</h2>
|
||||||
|
|
||||||
|
<p>Open your profile. If the graph is a broken-image icon or alt text, your README points at
|
||||||
|
the disabled instance. The line looks like this:</p>
|
||||||
|
|
||||||
|
<pre><code></code></pre>
|
||||||
|
|
||||||
|
<p>The older address <code>activity-graph.herokuapp.com</code> returns 404 too, and both fixes below work for it.</p>
|
||||||
|
|
||||||
|
<h2>Fix 1: the project's new address</h2>
|
||||||
|
|
||||||
|
<p>The project now runs on Cloudflare Workers. Change the domain and keep everything else:</p>
|
||||||
|
|
||||||
|
<pre><code>https://github-readme-activity-graph.ashutosh-dwivedi0710.workers.dev/graph?username=YOUR_USERNAME</code></pre>
|
||||||
|
|
||||||
|
<h2>Fix 2: a different graph, in one line</h2>
|
||||||
|
|
||||||
|
<p>To switch to gh-stats instead, replace the line with this one, change the username, and commit:</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://gh-stats.com)</code></pre>
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<img src="https://gh-stats.com/api/torvalds/impact.svg" alt="gh-stats impact timeline: weekly contributions over the last six months." style="max-width:380px"/>
|
||||||
|
<figcaption>The impact timeline for torvalds, rendered live.</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There is no token to create and no signup. The first request for a new username queues
|
||||||
|
a build, so the image can take a minute to appear.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>How it differs</h2>
|
||||||
|
|
||||||
|
<div class="tablewrap">
|
||||||
|
<table>
|
||||||
|
<tr><th></th><th>github-readme-activity-graph</th><th>gh-stats impact timeline</th></tr>
|
||||||
|
<tr><td>Window</td><td>Last 31 days by default (up to 90), one point per day</td><td>Last six months, one point per week</td></tr>
|
||||||
|
<tr><td>Counts</td><td>Daily contributions</td><td>Weekly totals from your contribution calendar</td></tr>
|
||||||
|
<tr><td>Themes</td><td>Many, plus custom colours and title</td><td>Five: <code>?theme=midnight</code>, <code>onyx</code>, <code>nord</code>, <code>clean</code>, <code>paper</code></td></tr>
|
||||||
|
<tr><td>Address</td><td>Moved from vercel.app to workers.dev</td><td>gh-stats.com</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
A weekly line over six months is smoother than a daily one. It shows the shape of your
|
||||||
|
year, and a quiet weekend does not read as a gap.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Want the whole profile?</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Drop the <code>/impact.svg</code> and the same URL renders one card with a score out of
|
||||||
|
100, the timeline, top collaborators, languages and streaks:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://gh-stats.com)</code></pre>
|
||||||
|
|
||||||
|
<a class="cta" href="https://gh-stats.com/">Preview it for your username</a>
|
||||||
|
|
||||||
|
<p style="margin-top:24px">
|
||||||
|
See the <a href="https://gh-stats.com/github-readme-themes.html">five themes</a>, or
|
||||||
|
<a href="https://gh-stats.com/github-profile-readme.html">how to create a profile README</a>
|
||||||
|
if you do not have one yet.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Common questions</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Can I keep using github-readme-activity-graph?</strong> Yes. Use Fix 1; the
|
||||||
|
project is maintained and only its old vercel.app address is disabled.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Does gh-stats need access to my account?</strong> No. It reads public GitHub
|
||||||
|
activity only.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> ·
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">source on GitHub</a> ·
|
||||||
|
MIT licensed
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,214 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>github-readme-stats alternative: a maintained stats card for your profile README</title>
|
||||||
|
<meta name="description"
|
||||||
|
content="anuraghazra/github-readme-stats is marked no longer maintained. gh-stats is a maintained, MIT-licensed stats card you can drop into your GitHub profile README by changing the domain in your existing URL, or self-host on your own API quota."/>
|
||||||
|
<link rel="canonical" href="https://gh-stats.com/github-readme-stats-alternative.html"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||||
|
<meta property="og:type" content="article"/>
|
||||||
|
<meta property="og:site_name" content="gh-stats"/>
|
||||||
|
<meta property="og:url" content="https://gh-stats.com/github-readme-stats-alternative.html"/>
|
||||||
|
<meta property="og:title" content="github-readme-stats alternative: a maintained stats card"/>
|
||||||
|
<meta property="og:description"
|
||||||
|
content="The card most profile READMEs use is marked no longer maintained. Here is how to move, with the URL shapes you already have."/>
|
||||||
|
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||||
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
|
||||||
|
<script type="module">
|
||||||
|
// Same GA4 stream as the SPA (index.html), so this page's traffic and its
|
||||||
|
// referrers land in the existing property instead of going unmeasured.
|
||||||
|
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||||
|
import {getAnalytics} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-analytics.js";
|
||||||
|
getAnalytics(initializeApp({
|
||||||
|
apiKey: "AIzaSyCy2pUW8Geo0Aagq9mTYKlfCpa9GUIXpy8",
|
||||||
|
authDomain: "gh-stats-284de.firebaseapp.com",
|
||||||
|
projectId: "gh-stats-284de",
|
||||||
|
storageBucket: "gh-stats-284de.firebasestorage.app",
|
||||||
|
messagingSenderId: "723662839762",
|
||||||
|
appId: "1:723662839762:web:4ba5337f6489ea67dc320b",
|
||||||
|
measurementId: "G-228GR89RYX"
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#f9fafb; --card:#ffffff; --line:#e5e7eb;
|
||||||
|
--ink:#1f2937; --muted:#6b7280; --faint:#9ca3af; --accent:#0969da;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{margin:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:'DM Sans',system-ui,sans-serif;-webkit-font-smoothing:antialiased;
|
||||||
|
line-height:1.65}
|
||||||
|
main{max-width:760px;margin:0 auto;padding:56px 24px 96px}
|
||||||
|
h1{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:2.6rem;line-height:1.15;letter-spacing:-.01em;margin:0 0 16px}
|
||||||
|
h2{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:1.65rem;margin:48px 0 12px;letter-spacing:-.01em}
|
||||||
|
p{margin:0 0 16px}
|
||||||
|
.lede{font-size:1.08rem;color:var(--muted);margin-bottom:32px}
|
||||||
|
a{color:var(--accent);text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
code,pre{font-family:'JetBrains Mono',ui-monospace,monospace;font-size:.86rem}
|
||||||
|
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||||||
|
padding:14px 16px;overflow-x:auto;margin:0 0 16px}
|
||||||
|
code:not(pre code){background:#f3f4f6;border-radius:5px;padding:.12em .38em;font-size:.85em}
|
||||||
|
.tablewrap{overflow-x:auto;margin:0 0 16px}
|
||||||
|
table{border-collapse:collapse;width:100%;font-size:.86rem;background:var(--card);
|
||||||
|
border:1px solid var(--line);border-radius:10px}
|
||||||
|
th,td{text-align:left;padding:10px 14px;border-bottom:1px solid var(--line);
|
||||||
|
vertical-align:top}
|
||||||
|
th{font-weight:600;color:var(--muted);font-size:.78rem;text-transform:uppercase;
|
||||||
|
letter-spacing:.04em}
|
||||||
|
tr:last-child td{border-bottom:none}
|
||||||
|
td code{white-space:nowrap}
|
||||||
|
figure{margin:0 0 28px}
|
||||||
|
figure img{width:100%;max-width:400px;display:block;border-radius:12px}
|
||||||
|
figcaption{color:var(--faint);font-size:.8rem;margin-top:8px}
|
||||||
|
.clip{position:relative;max-width:340px;max-height:400px;overflow:hidden;
|
||||||
|
border-radius:12px}
|
||||||
|
.clip img{width:100%;display:block;border-radius:12px}
|
||||||
|
.clip::after{content:"";position:absolute;left:0;right:0;bottom:0;height:72px;
|
||||||
|
background:linear-gradient(to top,var(--bg),transparent)}
|
||||||
|
.cta{display:inline-block;background:var(--ink);color:#fff;border-radius:9px;
|
||||||
|
padding:11px 20px;font-weight:600;font-size:.92rem;margin:8px 0 0}
|
||||||
|
.cta:hover{text-decoration:none;opacity:.9}
|
||||||
|
.note{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted);
|
||||||
|
font-size:.92rem;margin:0 0 16px}
|
||||||
|
footer{border-top:1px solid var(--line);margin-top:64px;padding-top:20px;
|
||||||
|
color:var(--faint);font-size:.82rem}
|
||||||
|
@media (max-width:640px){h1{font-size:2.05rem}main{padding:36px 20px 72px}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<h1>A maintained alternative to github-readme-stats</h1>
|
||||||
|
|
||||||
|
<p class="lede">
|
||||||
|
<a href="https://github.com/anuraghazra/github-readme-stats">anuraghazra/github-readme-stats</a>
|
||||||
|
is the stats card most GitHub profile READMEs use, and it earned that place.
|
||||||
|
Its README now opens with a caution notice saying the repository is no longer
|
||||||
|
maintained. If you are looking for somewhere to move, this page shows the swap.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<img src="https://gh-stats.com/?username=ShayManor" alt="A gh-stats developer profile card showing score, commits, pull requests, stars and role tags."/>
|
||||||
|
<figcaption>The profile card: score out of 100, headline counts, and role tags earned from your repositories.</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<h2>Change the domain, keep the URL</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The common URL shapes work here with only the domain changed, so migrating is
|
||||||
|
an edit to one line of markdown.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="tablewrap">
|
||||||
|
<table>
|
||||||
|
<tr><th>Your current URL</th><th>Change it to</th></tr>
|
||||||
|
<tr><td><code>github-readme-stats.vercel.app/api?username=U</code></td>
|
||||||
|
<td><code>gh-stats.com/api?username=U</code></td></tr>
|
||||||
|
<tr><td><code>github-readme-stats.vercel.app/api/top-langs?username=U</code></td>
|
||||||
|
<td><code>gh-stats.com/api/top-langs?username=U</code></td></tr>
|
||||||
|
<tr><td><code>github-readme-stats-sigma-five.vercel.app/api?username=U</code> (returns 402)</td>
|
||||||
|
<td><code>gh-stats.com/api?username=U</code></td></tr>
|
||||||
|
<tr><td><code>github-readme-stats-eight-theta.vercel.app/api?username=U</code> (returns 402)</td>
|
||||||
|
<td><code>gh-stats.com/api?username=U</code></td></tr>
|
||||||
|
<tr><td><code>github-readme-stats-eight-theta.vercel.app/api/top-langs?username=U</code> (returns 402)</td>
|
||||||
|
<td><code>gh-stats.com/api/top-langs?username=U</code></td></tr>
|
||||||
|
<tr><td><code>github-readme-streak-stats.herokuapp.com/?user=U</code></td>
|
||||||
|
<td><code>gh-stats.com/api/streak/U</code></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>Nothing else in your README changes.</p>
|
||||||
|
|
||||||
|
<p class="note">
|
||||||
|
<code>theme=</code> is honoured on the composite card (<code>/api/<user></code>).
|
||||||
|
On the compatibility and single-widget URLs above it is currently ignored and the
|
||||||
|
default theme is served.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Or replace several badges with one card</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Most profile READMEs stack a stats badge, a streak badge, a languages badge and a
|
||||||
|
trophy row, each one a separate request. The composite card covers all of it in a
|
||||||
|
single image:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code></code></pre>
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<div class="clip">
|
||||||
|
<img src="https://gh-stats.com/api/ShayManor" alt="The full gh-stats composite card: profile score, impact timeline, collaborators, languages, streaks and achievements."/>
|
||||||
|
</div>
|
||||||
|
<figcaption>The composite card, cropped. It stacks profile, timeline, collaborators, languages, streaks and achievements.</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
No signup is required to try it. Type a username on the
|
||||||
|
<a href="https://gh-stats.com/">home page</a> and the real card renders immediately.
|
||||||
|
Signing in with GitHub proves you own the username and unlocks the editor for
|
||||||
|
themes, widget order and custom tags.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a class="cta" href="https://gh-stats.com/">Try it on your username</a>
|
||||||
|
|
||||||
|
<h2>What you should know before switching</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The project's own successor is
|
||||||
|
<a href="https://github.com/stats-organization/github-stats-extended">GitHub Stats Extended</a>,
|
||||||
|
named in that caution notice. It is a fork that keeps the original's shape, so pick
|
||||||
|
it if what you want is the same card with the same options.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
gh-stats is a different design: one card that summarises the whole profile, rather
|
||||||
|
than a set of separate badges. It is MIT licensed, and you can
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">self-host it</a> with
|
||||||
|
<code>docker compose up</code> on your own GitHub API quota if you would rather not
|
||||||
|
depend on someone else's instance.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Only public GitHub activity is counted. Private repositories, private commit counts
|
||||||
|
and contributions to org-restricted repositories are never visible to the fetcher.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Common questions</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Is github-readme-stats actually dead?</strong> The repository is not archived
|
||||||
|
and the hosted instance still serves cards. The maintainer marked it no longer
|
||||||
|
maintained in the README, which is a statement about future work rather than an
|
||||||
|
outage.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Why do stats cards return an error or a blank image?</strong> A shared
|
||||||
|
instance runs on one GitHub API quota, so a popular deployment hits rate limits and
|
||||||
|
serves errors to everyone behind it. Self-hosting puts you on your own quota and
|
||||||
|
removes that failure mode.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Do I have to change my README again later?</strong> No. The image URL is
|
||||||
|
stable, so themes, tags and widget order can change in the editor without touching
|
||||||
|
the markdown.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> ·
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">source on GitHub</a> ·
|
||||||
|
MIT licensed
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>GitHub README stats card themes: dark, light and auto-switching</title>
|
||||||
|
<meta name="description"
|
||||||
|
content="Five themes for a GitHub profile stats card, with a live preview and a copy-paste line for each, plus the snippet that switches between dark and light with the viewer's GitHub theme."/>
|
||||||
|
<link rel="canonical" href="https://gh-stats.com/github-readme-themes.html"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||||
|
<meta property="og:type" content="article"/>
|
||||||
|
<meta property="og:site_name" content="gh-stats"/>
|
||||||
|
<meta property="og:url" content="https://gh-stats.com/github-readme-themes.html"/>
|
||||||
|
<meta property="og:title" content="GitHub README stats card themes"/>
|
||||||
|
<meta property="og:description"
|
||||||
|
content="Five themes, a live preview of each, and dark/light auto-switching in one snippet."/>
|
||||||
|
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||||
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
|
||||||
|
<script type="module">
|
||||||
|
// Same GA4 stream as the SPA (index.html), so this page's traffic and its
|
||||||
|
// referrers land in the existing property instead of going unmeasured.
|
||||||
|
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||||
|
import {getAnalytics} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-analytics.js";
|
||||||
|
getAnalytics(initializeApp({
|
||||||
|
apiKey: "AIzaSyCy2pUW8Geo0Aagq9mTYKlfCpa9GUIXpy8",
|
||||||
|
authDomain: "gh-stats-284de.firebaseapp.com",
|
||||||
|
projectId: "gh-stats-284de",
|
||||||
|
storageBucket: "gh-stats-284de.firebasestorage.app",
|
||||||
|
messagingSenderId: "723662839762",
|
||||||
|
appId: "1:723662839762:web:4ba5337f6489ea67dc320b",
|
||||||
|
measurementId: "G-228GR89RYX"
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#f9fafb; --card:#ffffff; --line:#e5e7eb;
|
||||||
|
--ink:#1f2937; --muted:#6b7280; --faint:#9ca3af; --accent:#0969da;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{margin:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:'DM Sans',system-ui,sans-serif;-webkit-font-smoothing:antialiased;
|
||||||
|
line-height:1.65}
|
||||||
|
main{max-width:760px;margin:0 auto;padding:56px 24px 96px}
|
||||||
|
h1{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:2.6rem;line-height:1.15;letter-spacing:-.01em;margin:0 0 16px}
|
||||||
|
h2{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:1.65rem;margin:48px 0 12px;letter-spacing:-.01em}
|
||||||
|
p{margin:0 0 16px}
|
||||||
|
.lede{font-size:1.08rem;color:var(--muted);margin-bottom:32px}
|
||||||
|
a{color:var(--accent);text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
code,pre{font-family:'JetBrains Mono',ui-monospace,monospace;font-size:.86rem}
|
||||||
|
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||||||
|
padding:14px 16px;overflow-x:auto;margin:0 0 16px}
|
||||||
|
code:not(pre code){background:#f3f4f6;border-radius:5px;padding:.12em .38em;font-size:.85em}
|
||||||
|
.tablewrap{overflow-x:auto;margin:0 0 16px}
|
||||||
|
table{border-collapse:collapse;width:100%;font-size:.86rem;background:var(--card);
|
||||||
|
border:1px solid var(--line);border-radius:10px}
|
||||||
|
th,td{text-align:left;padding:10px 14px;border-bottom:1px solid var(--line);
|
||||||
|
vertical-align:top}
|
||||||
|
th{font-weight:600;color:var(--muted);font-size:.78rem;text-transform:uppercase;
|
||||||
|
letter-spacing:.04em}
|
||||||
|
tr:last-child td{border-bottom:none}
|
||||||
|
td code{white-space:nowrap}
|
||||||
|
figure{margin:0 0 28px}
|
||||||
|
figure img{width:100%;max-width:400px;display:block;border-radius:12px}
|
||||||
|
figcaption{color:var(--faint);font-size:.8rem;margin-top:8px}
|
||||||
|
.clip{position:relative;max-width:340px;max-height:400px;overflow:hidden;
|
||||||
|
border-radius:12px}
|
||||||
|
.clip img{width:100%;display:block;border-radius:12px}
|
||||||
|
.clip::after{content:"";position:absolute;left:0;right:0;bottom:0;height:72px;
|
||||||
|
background:linear-gradient(to top,var(--bg),transparent)}
|
||||||
|
.cta{display:inline-block;background:var(--ink);color:#fff;border-radius:9px;
|
||||||
|
padding:11px 20px;font-weight:600;font-size:.92rem;margin:8px 0 0}
|
||||||
|
.cta:hover{text-decoration:none;opacity:.9}
|
||||||
|
.note{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted);
|
||||||
|
font-size:.92rem;margin:0 0 16px}
|
||||||
|
footer{border-top:1px solid var(--line);margin-top:64px;padding-top:20px;
|
||||||
|
color:var(--faint);font-size:.82rem}
|
||||||
|
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:20px;margin:0 0 16px}
|
||||||
|
.grid .clip{max-height:300px}
|
||||||
|
.grid h3{font-size:1rem;margin:0 0 8px}
|
||||||
|
.grid pre{font-size:.72rem;margin-top:10px}
|
||||||
|
@media (max-width:640px){h1{font-size:2.05rem}main{padding:36px 20px 72px}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<h1>Stats card themes for your GitHub profile README</h1>
|
||||||
|
|
||||||
|
<p class="lede">
|
||||||
|
A gh-stats card takes one <code>theme</code> parameter. Pick one of five, or serve a dark
|
||||||
|
card to dark-mode visitors and a light one to everyone else.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>The five themes</h2>
|
||||||
|
|
||||||
|
<div class="grid">
|
||||||
|
<div>
|
||||||
|
<h3>midnight</h3>
|
||||||
|
<div class="clip"><img loading="lazy" src="https://gh-stats.com/api/ShayManor?theme=midnight" alt="gh-stats card in the midnight theme"/></div>
|
||||||
|
<p style="margin:8px 0 0;color:var(--muted);font-size:.86rem">Dark slate. The default look.</p>
|
||||||
|
<pre><code>?theme=midnight</code></pre>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3>onyx</h3>
|
||||||
|
<div class="clip"><img loading="lazy" src="https://gh-stats.com/api/ShayManor?theme=onyx" alt="gh-stats card in the onyx theme"/></div>
|
||||||
|
<p style="margin:8px 0 0;color:var(--muted);font-size:.86rem">High-contrast neon on pure black.</p>
|
||||||
|
<pre><code>?theme=onyx</code></pre>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3>nord</h3>
|
||||||
|
<div class="clip"><img loading="lazy" src="https://gh-stats.com/api/ShayManor?theme=nord" alt="gh-stats card in the nord theme"/></div>
|
||||||
|
<p style="margin:8px 0 0;color:var(--muted);font-size:.86rem">Muted pastels on slate blue.</p>
|
||||||
|
<pre><code>?theme=nord</code></pre>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3>clean</h3>
|
||||||
|
<div class="clip"><img loading="lazy" src="https://gh-stats.com/api/ShayManor?theme=clean" alt="gh-stats card in the clean theme"/></div>
|
||||||
|
<p style="margin:8px 0 0;color:var(--muted);font-size:.86rem">White, for light-mode profiles.</p>
|
||||||
|
<pre><code>?theme=clean</code></pre>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<h3>paper</h3>
|
||||||
|
<div class="clip"><img loading="lazy" src="https://gh-stats.com/api/ShayManor?theme=paper" alt="gh-stats card in the paper theme"/></div>
|
||||||
|
<p style="margin:8px 0 0;color:var(--muted);font-size:.86rem">Warm off-white.</p>
|
||||||
|
<pre><code>?theme=paper</code></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Use a theme</h2>
|
||||||
|
|
||||||
|
<p>Add <code>?theme=</code> to the card URL in your README, replace the username, and commit:</p>
|
||||||
|
|
||||||
|
<pre><code>[](https://gh-stats.com)</code></pre>
|
||||||
|
|
||||||
|
<p>Leave the parameter out and the card uses midnight.</p>
|
||||||
|
|
||||||
|
<h2>Switch with the viewer's GitHub theme</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
GitHub renders <code><picture></code> in READMEs and honours
|
||||||
|
<code>prefers-color-scheme</code>, so each visitor sees the card that matches their
|
||||||
|
GitHub appearance setting:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code><a href="https://gh-stats.com">
|
||||||
|
<picture>
|
||||||
|
<source media="(prefers-color-scheme: dark)"
|
||||||
|
srcset="https://gh-stats.com/api/YOUR_USERNAME?theme=onyx"/>
|
||||||
|
<source media="(prefers-color-scheme: light)"
|
||||||
|
srcset="https://gh-stats.com/api/YOUR_USERNAME?theme=clean"/>
|
||||||
|
<img alt="GitHub stats" src="https://gh-stats.com/api/YOUR_USERNAME?theme=clean"/>
|
||||||
|
</picture>
|
||||||
|
</a></code></pre>
|
||||||
|
|
||||||
|
<p>Any dark theme works in the first line and any light one in the second.</p>
|
||||||
|
|
||||||
|
<a class="cta" href="https://gh-stats.com/">Preview every theme with your username</a>
|
||||||
|
|
||||||
|
<p style="margin-top:24px">
|
||||||
|
New to profile READMEs? Start with
|
||||||
|
<a href="https://gh-stats.com/github-profile-readme.html">how to create one</a>.
|
||||||
|
Coming from github-readme-stats? See the
|
||||||
|
<a href="https://gh-stats.com/github-readme-stats-alternative.html">migration guide</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Common questions</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Can I make a theme the default without the parameter?</strong> Yes. Sign in on
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> with the GitHub account the card belongs
|
||||||
|
to, pick the theme, and save. <code>/api/YOUR_USERNAME</code> then uses it.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Does changing the theme reset my card?</strong> No. The theme changes colours
|
||||||
|
only; the data is the same.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> ·
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">source on GitHub</a> ·
|
||||||
|
MIT licensed
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<title>GitHub top languages card for your profile README</title>
|
||||||
|
<meta name="description"
|
||||||
|
content="Add a most-used-languages card to your GitHub profile README with one line of markdown. Hide languages you do not want counted, pick a theme, no signup. Drop-in for github-readme-stats top-langs URLs."/>
|
||||||
|
<link rel="canonical" href="https://gh-stats.com/github-top-languages-card.html"/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg"/>
|
||||||
|
<meta property="og:type" content="article"/>
|
||||||
|
<meta property="og:site_name" content="gh-stats"/>
|
||||||
|
<meta property="og:url" content="https://gh-stats.com/github-top-languages-card.html"/>
|
||||||
|
<meta property="og:title" content="GitHub top languages card for your profile README"/>
|
||||||
|
<meta property="og:description"
|
||||||
|
content="One line of markdown, a theme, and a list of languages to hide."/>
|
||||||
|
<meta property="og:image" content="https://gh-stats.com/og.png"/>
|
||||||
|
<meta name="twitter:card" content="summary_large_image"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com"/>
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400..700&family=Instrument+Serif&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet"/>
|
||||||
|
<script type="module">
|
||||||
|
// Same GA4 stream as the SPA (index.html), so this page's traffic and its
|
||||||
|
// referrers land in the existing property instead of going unmeasured.
|
||||||
|
import {initializeApp} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-app.js";
|
||||||
|
import {getAnalytics} from "https://www.gstatic.com/firebasejs/12.13.0/firebase-analytics.js";
|
||||||
|
getAnalytics(initializeApp({
|
||||||
|
apiKey: "AIzaSyCy2pUW8Geo0Aagq9mTYKlfCpa9GUIXpy8",
|
||||||
|
authDomain: "gh-stats-284de.firebaseapp.com",
|
||||||
|
projectId: "gh-stats-284de",
|
||||||
|
storageBucket: "gh-stats-284de.firebasestorage.app",
|
||||||
|
messagingSenderId: "723662839762",
|
||||||
|
appId: "1:723662839762:web:4ba5337f6489ea67dc320b",
|
||||||
|
measurementId: "G-228GR89RYX"
|
||||||
|
}));
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#f9fafb; --card:#ffffff; --line:#e5e7eb;
|
||||||
|
--ink:#1f2937; --muted:#6b7280; --faint:#9ca3af; --accent:#0969da;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
body{margin:0;background:var(--bg);color:var(--ink);
|
||||||
|
font-family:'DM Sans',system-ui,sans-serif;-webkit-font-smoothing:antialiased;
|
||||||
|
line-height:1.65}
|
||||||
|
main{max-width:760px;margin:0 auto;padding:56px 24px 96px}
|
||||||
|
h1{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:2.6rem;line-height:1.15;letter-spacing:-.01em;margin:0 0 16px}
|
||||||
|
h2{font-family:'Instrument Serif',Georgia,serif;font-weight:400;
|
||||||
|
font-size:1.65rem;margin:48px 0 12px;letter-spacing:-.01em}
|
||||||
|
p{margin:0 0 16px}
|
||||||
|
.lede{font-size:1.08rem;color:var(--muted);margin-bottom:32px}
|
||||||
|
a{color:var(--accent);text-decoration:none}
|
||||||
|
a:hover{text-decoration:underline}
|
||||||
|
code,pre{font-family:'JetBrains Mono',ui-monospace,monospace;font-size:.86rem}
|
||||||
|
pre{background:var(--card);border:1px solid var(--line);border-radius:10px;
|
||||||
|
padding:14px 16px;overflow-x:auto;margin:0 0 16px}
|
||||||
|
code:not(pre code){background:#f3f4f6;border-radius:5px;padding:.12em .38em;font-size:.85em}
|
||||||
|
.tablewrap{overflow-x:auto;margin:0 0 16px}
|
||||||
|
table{border-collapse:collapse;width:100%;font-size:.86rem;background:var(--card);
|
||||||
|
border:1px solid var(--line);border-radius:10px}
|
||||||
|
th,td{text-align:left;padding:10px 14px;border-bottom:1px solid var(--line);
|
||||||
|
vertical-align:top}
|
||||||
|
th{font-weight:600;color:var(--muted);font-size:.78rem;text-transform:uppercase;
|
||||||
|
letter-spacing:.04em}
|
||||||
|
tr:last-child td{border-bottom:none}
|
||||||
|
td code{white-space:nowrap}
|
||||||
|
figure{margin:0 0 28px}
|
||||||
|
figure img{width:100%;max-width:400px;display:block;border-radius:12px}
|
||||||
|
figcaption{color:var(--faint);font-size:.8rem;margin-top:8px}
|
||||||
|
.clip{position:relative;max-width:340px;max-height:400px;overflow:hidden;
|
||||||
|
border-radius:12px}
|
||||||
|
.clip img{width:100%;display:block;border-radius:12px}
|
||||||
|
.clip::after{content:"";position:absolute;left:0;right:0;bottom:0;height:72px;
|
||||||
|
background:linear-gradient(to top,var(--bg),transparent)}
|
||||||
|
.cta{display:inline-block;background:var(--ink);color:#fff;border-radius:9px;
|
||||||
|
padding:11px 20px;font-weight:600;font-size:.92rem;margin:8px 0 0}
|
||||||
|
.cta:hover{text-decoration:none;opacity:.9}
|
||||||
|
.note{border-left:3px solid var(--line);padding:2px 0 2px 16px;color:var(--muted);
|
||||||
|
font-size:.92rem;margin:0 0 16px}
|
||||||
|
footer{border-top:1px solid var(--line);margin-top:64px;padding-top:20px;
|
||||||
|
color:var(--faint);font-size:.82rem}
|
||||||
|
@media (max-width:640px){h1{font-size:2.05rem}main{padding:36px 20px 72px}}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<h1>A top languages card for your GitHub profile README</h1>
|
||||||
|
|
||||||
|
<p class="lede">
|
||||||
|
The languages card shows which languages your public repositories are written in,
|
||||||
|
as a donut and a ranked legend. It is one image, served from one URL, and it stays
|
||||||
|
current without a GitHub Action or a token.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<figure>
|
||||||
|
<img src="https://gh-stats.com/api/ShayManor?widgets=languages" alt="A gh-stats top languages card: a donut chart with Python, Go, Jupyter Notebook, JavaScript and TypeScript, each with a percentage."/>
|
||||||
|
<figcaption>The languages card for one profile.</figcaption>
|
||||||
|
</figure>
|
||||||
|
|
||||||
|
<h2>Add it to your README</h2>
|
||||||
|
|
||||||
|
<p>Paste this into your profile README and replace the username:</p>
|
||||||
|
|
||||||
|
<pre><code></code></pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The first request for a new username queues a build, so the card can take a minute
|
||||||
|
to fill in. After that it is served from cache and refreshed in the background.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<a class="cta" href="https://gh-stats.com/">Preview it on your username</a>
|
||||||
|
|
||||||
|
<h2>Hide languages and pick a theme</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Notebooks, generated HTML and vendored code often dominate a languages chart.
|
||||||
|
List what to leave out in <code>hide</code>, comma-separated, and choose a look
|
||||||
|
with <code>theme</code>:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre><code></code></pre>
|
||||||
|
|
||||||
|
<div class="tablewrap">
|
||||||
|
<table>
|
||||||
|
<tr><th>Parameter</th><th>What it does</th></tr>
|
||||||
|
<tr><td><code>hide</code></td>
|
||||||
|
<td>Languages to exclude, comma-separated. Use <code>%20</code> for spaces.</td></tr>
|
||||||
|
<tr><td><code>theme</code></td>
|
||||||
|
<td><code>clean</code>, <code>midnight</code>, <code>nord</code>, <code>onyx</code> or <code>paper</code>.</td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Coming from github-readme-stats</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If your README already has a <code>top-langs</code> card from
|
||||||
|
<code>github-readme-stats.vercel.app</code>, change only the domain:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="tablewrap">
|
||||||
|
<table>
|
||||||
|
<tr><th>Your current URL</th><th>Change it to</th></tr>
|
||||||
|
<tr><td><code>github-readme-stats.vercel.app/api/top-langs?username=U</code></td>
|
||||||
|
<td><code>gh-stats.com/api/top-langs?username=U</code></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="note">
|
||||||
|
The compatibility URL ignores the original styling parameters (<code>layout</code>,
|
||||||
|
<code>langs_count</code>, colours) and serves the default card. Use the
|
||||||
|
<code>?widgets=languages</code> form above for <code>hide</code> and <code>theme</code>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The full migration guide covers the stats and streak cards too:
|
||||||
|
<a href="https://gh-stats.com/github-readme-stats-alternative.html">github-readme-stats alternative</a>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>Common questions</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>How are percentages worked out?</strong> From the byte counts GitHub reports
|
||||||
|
for each public repository you authored, summed across those repositories. Forks are
|
||||||
|
left out. A large repository in one language weighs more than several small ones.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Are private repositories counted?</strong> No. Only public activity is
|
||||||
|
visible to the fetcher.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Can I show it alongside other stats?</strong> Yes. Drop the
|
||||||
|
<code>?widgets=languages</code> part and the same URL serves the full profile card:
|
||||||
|
score, contribution timeline, collaborators, languages and streaks in one image.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<a href="https://gh-stats.com/">gh-stats.com</a> ·
|
||||||
|
<a href="https://github.com/ShayManor/github-readme-stats">source on GitHub</a> ·
|
||||||
|
MIT licensed
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -5,4 +5,34 @@
|
|||||||
<changefreq>weekly</changefreq>
|
<changefreq>weekly</changefreq>
|
||||||
<priority>1.0</priority>
|
<priority>1.0</priority>
|
||||||
</url>
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://gh-stats.com/github-readme-stats-alternative.html</loc>
|
||||||
|
<changefreq>monthly</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://gh-stats.com/github-top-languages-card.html</loc>
|
||||||
|
<changefreq>monthly</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://gh-stats.com/github-profile-readme.html</loc>
|
||||||
|
<changefreq>monthly</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://gh-stats.com/github-readme-themes.html</loc>
|
||||||
|
<changefreq>monthly</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://gh-stats.com/github-readme-activity-graph-alternative.html</loc>
|
||||||
|
<changefreq>monthly</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
|
<url>
|
||||||
|
<loc>https://gh-stats.com/github-profile-trophy-alternative.html</loc>
|
||||||
|
<changefreq>monthly</changefreq>
|
||||||
|
<priority>0.8</priority>
|
||||||
|
</url>
|
||||||
</urlset>
|
</urlset>
|
||||||
|
|||||||
@@ -262,7 +262,9 @@ export default function App() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (r.status === 429 || status === 'rate_limited') {
|
if (r.status === 429 || status === 'rate_limited') {
|
||||||
setFetchError('Enrollment limit reached — try again tomorrow')
|
setFetchError((body as { cap?: string }).cap === 'daily'
|
||||||
|
? 'Enrollment limit reached — try again tomorrow'
|
||||||
|
: 'Enrollment limit reached — try again in an hour')
|
||||||
setFetchDone(true)
|
setFetchDone(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -348,6 +350,13 @@ export default function App() {
|
|||||||
setGenerateError(body.status === 'not_found' ? 'User not found' : 'Not enrolled')
|
setGenerateError(body.status === 'not_found' ? 'User not found' : 'Not enrolled')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (r.status === 503) {
|
||||||
|
const body = await r.json().catch(() => ({} as { error?: string }))
|
||||||
|
if (body.error === 'github_rate_limited') {
|
||||||
|
setGenerateError("GitHub's API limit is reached for now. Your card builds automatically once it resets (within the hour), and you can paste the embed now.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!r.ok) {
|
if (!r.ok) {
|
||||||
setGenerateError(`Generate failed (HTTP ${r.status})`)
|
setGenerateError(`Generate failed (HTTP ${r.status})`)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,5 +1,16 @@
|
|||||||
import DOMPurify from 'dompurify'
|
import DOMPurify from 'dompurify'
|
||||||
import { useMemo, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
|
|
||||||
|
// Stats cards people already have in their profile README. A visitor who has
|
||||||
|
// one needs "replace that line", not "paste this somewhere".
|
||||||
|
const OTHER_CARDS: [RegExp, string][] = [
|
||||||
|
[/github-readme-stats/i, 'github-readme-stats'],
|
||||||
|
[/streak-stats|readme-streak/i, 'GitHub Readme Streak Stats'],
|
||||||
|
[/github-stats-extended/i, 'github-stats-extended'],
|
||||||
|
[/github-profile-summary-cards/i, 'github-profile-summary-cards'],
|
||||||
|
[/github-profile-trophy/i, 'github-profile-trophy'],
|
||||||
|
[/github-readme-activity-graph/i, 'github-readme-activity-graph'],
|
||||||
|
]
|
||||||
|
|
||||||
function sanitizeSvg(raw: string): string {
|
function sanitizeSvg(raw: string): string {
|
||||||
return DOMPurify.sanitize(raw, {
|
return DOMPurify.sanitize(raw, {
|
||||||
@@ -34,6 +45,42 @@ export function ResultScreen({ username, generating, generatedSvg, generateError
|
|||||||
const fallbackUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
|
const fallbackUrl = `${window.location.origin}/api/${encodeURIComponent(username)}`
|
||||||
const finalUrl = embedUrl || fallbackUrl
|
const finalUrl = embedUrl || fallbackUrl
|
||||||
const embedSnippet = `[](${window.location.origin})`
|
const embedSnippet = `[](${window.location.origin})`
|
||||||
|
// The snippet is useless without somewhere to paste it: GitHub only renders a
|
||||||
|
// profile README from the repo named exactly after the account. Most people
|
||||||
|
// arriving here don't have that repo yet, so offer both paths.
|
||||||
|
const profileRepo = encodeURIComponent(username)
|
||||||
|
const editReadmeUrl = `https://github.com/${profileRepo}/${profileRepo}/edit/HEAD/README.md`
|
||||||
|
const createRepoUrl = `https://github.com/new?name=${profileRepo}&description=${encodeURIComponent('My GitHub profile')}&visibility=public`
|
||||||
|
// raw.githubusercontent.com sends Access-Control-Allow-Origin: *, so the
|
||||||
|
// browser can read the profile README directly. Any failure leaves the
|
||||||
|
// generic hint in place.
|
||||||
|
const [found, setFound] = useState<{ repo: string; card: string } | null>(null)
|
||||||
|
const otherCard = found?.repo === profileRepo ? found.card : null
|
||||||
|
// No profile repo at all: GitHub's new-file page takes ?filename=&value=, so
|
||||||
|
// after creating the (empty) repo one click opens a README with the card in it.
|
||||||
|
const [noRepo, setNoRepo] = useState<string | null>(null)
|
||||||
|
const addReadmeUrl = `https://github.com/${profileRepo}/${profileRepo}/new/main?filename=README.md&value=${encodeURIComponent(embedSnippet + '\n')}`
|
||||||
|
useEffect(() => {
|
||||||
|
let live = true
|
||||||
|
fetch(`https://raw.githubusercontent.com/${profileRepo}/${profileRepo}/HEAD/README.md`)
|
||||||
|
.then(r => {
|
||||||
|
// A 404 here can also mean readme.md in another case, so only the
|
||||||
|
// API's 404 for the repo itself counts as "no repo".
|
||||||
|
if (r.status === 404) {
|
||||||
|
fetch(`https://api.github.com/repos/${profileRepo}/${profileRepo}`)
|
||||||
|
.then(a => { if (live && a.status === 404) setNoRepo(profileRepo) })
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
return r.ok ? r.text() : ''
|
||||||
|
})
|
||||||
|
.then(text => {
|
||||||
|
if (!live || /gh-stats\.com/i.test(text)) return
|
||||||
|
const hit = OTHER_CARDS.find(([re]) => re.test(text))
|
||||||
|
if (hit) setFound({ repo: profileRepo, card: hit[1] })
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
return () => { live = false }
|
||||||
|
}, [profileRepo])
|
||||||
|
|
||||||
const copy = async () => {
|
const copy = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -126,6 +173,22 @@ export function ResultScreen({ username, generating, generatedSvg, generateError
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-full mt-8">
|
<div className="w-full mt-8">
|
||||||
|
{noRepo === profileRepo && (
|
||||||
|
<div className="mb-6 rounded-xl ring-1 ring-gray-200 bg-white p-4">
|
||||||
|
<p className="text-sm text-gray-700 mb-3">
|
||||||
|
{username} has no profile README yet. GitHub shows the README of the repo named <code className="text-gray-600">{username}/{username}</code> on your profile.
|
||||||
|
</p>
|
||||||
|
<div className="flex flex-col sm:flex-row gap-2">
|
||||||
|
<a href={createRepoUrl} target="_blank" rel="noopener noreferrer" className="flex-1 text-center py-2.5 px-3 rounded-lg bg-gray-800 text-white text-sm hover:bg-gray-700 transition-colors">
|
||||||
|
1. Create {username}/{username}
|
||||||
|
</a>
|
||||||
|
<a href={addReadmeUrl} target="_blank" rel="noopener noreferrer" className="flex-1 text-center py-2.5 px-3 rounded-lg bg-gray-800 text-white text-sm hover:bg-gray-700 transition-colors">
|
||||||
|
2. Add the card to its README
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<p className="mt-2 text-xs text-gray-500">In step 1, leave "Add a README" unticked. Step 2 opens a README with this card already in it; commit it.</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<p className="text-xs uppercase tracking-wider text-gray-500 mb-2">Embed in your README</p>
|
<p className="text-xs uppercase tracking-wider text-gray-500 mb-2">Embed in your README</p>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<pre className="bg-gray-900 text-gray-100 text-xs p-4 pr-12 rounded-lg overflow-x-auto">
|
<pre className="bg-gray-900 text-gray-100 text-xs p-4 pr-12 rounded-lg overflow-x-auto">
|
||||||
@@ -148,6 +211,17 @@ export function ResultScreen({ username, generating, generatedSvg, generateError
|
|||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{noRepo !== profileRepo && <p className="mt-3 text-xs text-gray-500">
|
||||||
|
Paste it into <code className="text-gray-600">{username}/{username}</code>, the repo GitHub shows on your profile.{' '}
|
||||||
|
<a href={editReadmeUrl} onClick={copy} target="_blank" rel="noopener noreferrer" className="text-gray-700 underline hover:text-gray-900">Copy & open your README</a>
|
||||||
|
{' \u00b7 '}
|
||||||
|
<a href={createRepoUrl} target="_blank" rel="noopener noreferrer" className="text-gray-700 underline hover:text-gray-900">Create the repo</a>
|
||||||
|
</p>}
|
||||||
|
{otherCard && (
|
||||||
|
<p className="mt-2 text-xs text-gray-600">
|
||||||
|
This README already shows a {otherCard} card. Replace that line with the one above to swap it for this card.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -375,7 +375,7 @@ export function WorkshopScreen({
|
|||||||
onClick={onGenerate}
|
onClick={onGenerate}
|
||||||
className="w-full py-3 rounded-xl bg-gray-800 text-white text-sm font-medium hover:bg-gray-700 transition-colors mb-6"
|
className="w-full py-3 rounded-xl bg-gray-800 text-white text-sm font-medium hover:bg-gray-700 transition-colors mb-6"
|
||||||
>
|
>
|
||||||
Generate →
|
Get embed code →
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{fetchError && (
|
{fetchError && (
|
||||||
@@ -540,6 +540,16 @@ export function WorkshopScreen({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{w.id === 'grade' && (
|
||||||
|
<a
|
||||||
|
href="https://github.com/ShayManor/github-readme-stats#how-the-score-works"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-[10px] text-gray-500 underline"
|
||||||
|
>
|
||||||
|
How the score works
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
|
||||||
{w.id === 'impact' && (
|
{w.id === 'impact' && (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
"""Gunicorn settings: one access line per request on stdout, for Pantheos.
|
||||||
|
|
||||||
|
Docker's json-file driver captures stdout and Pantheos ingests it, so each line
|
||||||
|
becomes a request log and feeds the container's rps / 5xx / p95. Monitoring
|
||||||
|
traffic (/metrics scrapes, /health checks) is left out so it doesn't drown the
|
||||||
|
real requests.
|
||||||
|
"""
|
||||||
|
from gunicorn import glogging
|
||||||
|
|
||||||
|
accesslog = "-"
|
||||||
|
access_log_format = '"%(r)s" %(s)s %(M)sms'
|
||||||
|
|
||||||
|
_QUIET_PATHS = ("/metrics", "/health")
|
||||||
|
|
||||||
|
|
||||||
|
class _Logger(glogging.Logger):
|
||||||
|
def access(self, resp, req, environ, request_time):
|
||||||
|
if req.path not in _QUIET_PATHS:
|
||||||
|
super().access(resp, req, environ, request_time)
|
||||||
|
|
||||||
|
|
||||||
|
logger_class = _Logger
|
||||||
+24
-3
@@ -709,10 +709,20 @@ def internal_analytics_events():
|
|||||||
return jsonify({"ingested": n})
|
return jsonify({"ingested": n})
|
||||||
|
|
||||||
|
|
||||||
|
# Literal placeholders from the README snippets. Lowercased because the
|
||||||
|
# username normaliser lowercases before this is reached.
|
||||||
|
_DOC_PLACEHOLDERS = {"your_username", "yourusername", "your-username", "username"}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/<username>", methods=["GET"])
|
@app.route("/api/<username>", methods=["GET"])
|
||||||
@track_request("composite")
|
@track_request("composite")
|
||||||
@rate_limited("read")
|
@rate_limited("read")
|
||||||
def get_widget(username: str):
|
def get_widget(username: str):
|
||||||
|
if username.lower() in _DOC_PLACEHOLDERS:
|
||||||
|
# People paste the README snippet without swapping YOUR_USERNAME for
|
||||||
|
# their own name, so GitHub renders a broken image on their profile.
|
||||||
|
# A card that says what to do is more use to them than a JSON 400.
|
||||||
|
return _placeholder_response("unsubstituted", username)
|
||||||
if not is_valid_username(username):
|
if not is_valid_username(username):
|
||||||
return jsonify({"error": "invalid_username"}), 400
|
return jsonify({"error": "invalid_username"}), 400
|
||||||
return _serve(username, widget_name="composite")
|
return _serve(username, widget_name="composite")
|
||||||
@@ -817,7 +827,8 @@ def get_user_data(username: str):
|
|||||||
# Daily cap is the abuse backstop: a botnet typing random names
|
# Daily cap is the abuse backstop: a botnet typing random names
|
||||||
# can't burn through the GitHub PAT budget past this number.
|
# can't burn through the GitHub PAT budget past this number.
|
||||||
if _enrollment_capped():
|
if _enrollment_capped():
|
||||||
return jsonify({"status": "rate_limited"}), 429
|
cap = "daily" if db.enrollments_today() >= config.ENROLLMENT_DAILY_CAP else "hourly"
|
||||||
|
return jsonify({"status": "rate_limited", "cap": cap}), 429
|
||||||
defaults = {
|
defaults = {
|
||||||
"theme": "dark",
|
"theme": "dark",
|
||||||
"enabled": config.ENABLED_WIDGETS,
|
"enabled": config.ENABLED_WIDGETS,
|
||||||
@@ -900,7 +911,10 @@ def _serve(username: str, widget_name: str) -> Response:
|
|||||||
overrides = sanitize_settings_query(request.args)
|
overrides = sanitize_settings_query(request.args)
|
||||||
if widget_name != "composite":
|
if widget_name != "composite":
|
||||||
overrides = {k: v for k, v in overrides.items() if k == "theme"}
|
overrides = {k: v for k, v in overrides.items() if k == "theme"}
|
||||||
if overrides and current_hash != "not_found":
|
# No current widget means no build has landed yet, so the fetcher likely
|
||||||
|
# has no data either; an ad hoc render would trigger a GitHub fetch per
|
||||||
|
# request. Fall through to the building placeholder instead.
|
||||||
|
if overrides and current_hash is not None and current_hash != "not_found":
|
||||||
# Honor the possibly-overridden theme for error placeholders.
|
# Honor the possibly-overridden theme for error placeholders.
|
||||||
override_theme = overrides.get("theme") if isinstance(overrides.get("theme"), str) else None
|
override_theme = overrides.get("theme") if isinstance(overrides.get("theme"), str) else None
|
||||||
effective_theme = override_theme or theme
|
effective_theme = override_theme or theme
|
||||||
@@ -1124,7 +1138,14 @@ def generate(username: str):
|
|||||||
widgets = worker.render_widgets_now(username)
|
widgets = worker.render_widgets_now(username)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
return jsonify({"error": "not_enrolled"}), 404
|
return jsonify({"error": "not_enrolled"}), 404
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
# The fetcher answers 503 when GitHub's quota is spent; the card
|
||||||
|
# still builds on its own once it resets, so say that, not 502.
|
||||||
|
if getattr(getattr(e, "response", None), "status_code", None) == 503:
|
||||||
|
resp = jsonify({"error": "github_rate_limited"})
|
||||||
|
resp.status_code = 503
|
||||||
|
resp.headers["Retry-After"] = "600"
|
||||||
|
return resp
|
||||||
log.exception("generate failed for %s", username)
|
log.exception("generate failed for %s", username)
|
||||||
return jsonify({"error": "render_failed"}), 502
|
return jsonify({"error": "render_failed"}), 502
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
+9
-3
@@ -493,8 +493,11 @@ def pending_job_count() -> int:
|
|||||||
def claim_next_job() -> Optional[dict]:
|
def claim_next_job() -> Optional[dict]:
|
||||||
now = _now()
|
now = _now()
|
||||||
with _settings_conn() as c:
|
with _settings_conn() as c:
|
||||||
|
# A pending job whose updated_at is in the future is backing off
|
||||||
|
# (see fail_job's delay_s) and is not claimable yet.
|
||||||
row = c.execute(
|
row = c.execute(
|
||||||
"SELECT * FROM jobs WHERE status='pending' ORDER BY created_at LIMIT 1"
|
"SELECT * FROM jobs WHERE status='pending' AND updated_at <= ? ORDER BY created_at LIMIT 1",
|
||||||
|
(now,),
|
||||||
).fetchone()
|
).fetchone()
|
||||||
if row is None:
|
if row is None:
|
||||||
return None
|
return None
|
||||||
@@ -511,11 +514,14 @@ def complete_job(job_id: int) -> None:
|
|||||||
c.commit()
|
c.commit()
|
||||||
|
|
||||||
|
|
||||||
def fail_job(job_id: int, err: str, retry: bool) -> None:
|
def fail_job(job_id: int, err: str, retry: bool, delay_s: float = 0) -> None:
|
||||||
status = "pending" if retry else "failed"
|
status = "pending" if retry else "failed"
|
||||||
|
when = _now()
|
||||||
|
if retry and delay_s > 0:
|
||||||
|
when = (datetime.utcnow() + timedelta(seconds=delay_s)).isoformat(timespec="seconds") + "Z"
|
||||||
with _settings_conn() as c:
|
with _settings_conn() as c:
|
||||||
c.execute("UPDATE jobs SET status=?, last_error=?, updated_at=? WHERE id=?",
|
c.execute("UPDATE jobs SET status=?, last_error=?, updated_at=? WHERE id=?",
|
||||||
(status, err, _now(), job_id))
|
(status, err, when, job_id))
|
||||||
c.commit()
|
c.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ from .widgets.attribution import attribution_text
|
|||||||
|
|
||||||
_MESSAGES = {
|
_MESSAGES = {
|
||||||
"building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."),
|
"building": ("Building @{u}'s widget\u2026", "This usually takes under a minute."),
|
||||||
"rate_limited": ("Too many new users today", "Try again tomorrow."),
|
"rate_limited": ("Too many new users right now", "Try again later."),
|
||||||
"not_found": ("GitHub user @{u} doesn't exist", "Check the spelling of the username."),
|
"not_found": ("GitHub user @{u} doesn't exist", "Check the spelling of the username."),
|
||||||
|
"unsubstituted": ("Replace YOUR_USERNAME in the URL", "Put your own GitHub username there, e.g. /api/octocat."),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,9 @@ def compose_widget(
|
|||||||
fill="none" stroke="{t["card_border"]}" stroke-width="1"/>
|
fill="none" stroke="{t["card_border"]}" stroke-width="1"/>
|
||||||
{header}
|
{header}
|
||||||
{embedded}
|
{embedded}
|
||||||
|
<a href="https://gh-stats.com/?ref=card" xlink:href="https://gh-stats.com/?ref=card" target="_top">
|
||||||
<text x="{total_w // 2}" y="{total_h - 8}" text-anchor="middle"
|
<text x="{total_w // 2}" y="{total_h - 8}" text-anchor="middle"
|
||||||
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||||
font-size="10" fill="{t["text_secondary"]}" opacity="0.75">Generated with gh-stats.com</text>
|
font-size="10" fill="{t["text_secondary"]}" opacity="0.75">Generated with gh-stats.com</text>
|
||||||
|
</a>
|
||||||
</svg>'''
|
</svg>'''
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ re-renders triggered by the Generate button.
|
|||||||
Run as its own container: CMD python -m src.worker
|
Run as its own container: CMD python -m src.worker
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
import time
|
import time
|
||||||
from dataclasses import asdict
|
from dataclasses import asdict
|
||||||
|
|
||||||
@@ -18,6 +19,22 @@ from .widgets import compose_widget
|
|||||||
|
|
||||||
log = logging.getLogger("generator.worker")
|
log = logging.getLogger("generator.worker")
|
||||||
MAX_ATTEMPTS = 3
|
MAX_ATTEMPTS = 3
|
||||||
|
# A fetcher 503 means GitHub's quota is spent. Retrying in seconds burns all
|
||||||
|
# attempts before the hourly reset, so back off exponentially (1, 2, 4, ...
|
||||||
|
# minutes, jittered, capped at an hour) and allow enough attempts to span
|
||||||
|
# a full quota window.
|
||||||
|
RATE_LIMIT_MAX_ATTEMPTS = 8
|
||||||
|
RATE_LIMIT_BACKOFF_CAP_S = 3600
|
||||||
|
|
||||||
|
|
||||||
|
def _rate_limit_delay(e: Exception, attempts: int) -> float:
|
||||||
|
resp = getattr(e, "response", None)
|
||||||
|
try:
|
||||||
|
retry_after = float(resp.headers.get("Retry-After"))
|
||||||
|
except (AttributeError, TypeError, ValueError):
|
||||||
|
retry_after = 0
|
||||||
|
delay = max(retry_after, 60 * 2 ** (attempts - 1))
|
||||||
|
return min(delay * random.uniform(0.8, 1.2), RATE_LIMIT_BACKOFF_CAP_S)
|
||||||
|
|
||||||
|
|
||||||
def _compute_widget_data(payload: dict, settings: dict, username: str) -> dict:
|
def _compute_widget_data(payload: dict, settings: dict, username: str) -> dict:
|
||||||
@@ -133,6 +150,12 @@ def process_one() -> bool:
|
|||||||
log.info("prefetched + rendered widgets for %s", username)
|
log.info("prefetched + rendered widgets for %s", username)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if getattr(getattr(e, "response", None), "status_code", None) == 503:
|
||||||
|
retry = job["attempts"] < RATE_LIMIT_MAX_ATTEMPTS
|
||||||
|
db.fail_job(job["id"], str(e)[:500], retry=retry,
|
||||||
|
delay_s=_rate_limit_delay(e, job["attempts"]))
|
||||||
|
log.warning("prefetch rate-limited for %s (retry=%s): %s", username, retry, e)
|
||||||
|
return True
|
||||||
retry = job["attempts"] < MAX_ATTEMPTS
|
retry = job["attempts"] < MAX_ATTEMPTS
|
||||||
db.fail_job(job["id"], str(e)[:500], retry=retry)
|
db.fail_job(job["id"], str(e)[:500], retry=retry)
|
||||||
log.warning("prefetch failed for %s (retry=%s): %s", username, retry, e)
|
log.warning("prefetch failed for %s (retry=%s): %s", username, retry, e)
|
||||||
|
|||||||
@@ -316,6 +316,21 @@ def test_generate_endpoint_renders_and_stores_svg(client):
|
|||||||
assert b"<svg>r</svg>" in r2.data
|
assert b"<svg>r</svg>" in r2.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_generate_rate_limited_returns_503(client):
|
||||||
|
"""A spent GitHub quota surfaces as 503 github_rate_limited, not 502."""
|
||||||
|
import requests
|
||||||
|
dbmod.enroll("alice", {"theme": "dark"})
|
||||||
|
with client.session_transaction() as s:
|
||||||
|
s["gh_login"] = "alice"
|
||||||
|
resp = requests.Response()
|
||||||
|
resp.status_code = 503
|
||||||
|
err = requests.HTTPError("503 Server Error", response=resp)
|
||||||
|
with patch("src.worker.render_widgets_now", side_effect=err):
|
||||||
|
r = client.post("/api/alice/generate", headers={"Origin": "https://gh-stats.com"})
|
||||||
|
assert r.status_code == 503
|
||||||
|
assert r.get_json() == {"error": "github_rate_limited"}
|
||||||
|
|
||||||
|
|
||||||
def test_generate_endpoint_rejects_unenrolled(client):
|
def test_generate_endpoint_rejects_unenrolled(client):
|
||||||
"""With OAuth, unenrolled means having a session but no profile."""
|
"""With OAuth, unenrolled means having a session but no profile."""
|
||||||
with client.session_transaction() as s:
|
with client.session_transaction() as s:
|
||||||
@@ -458,6 +473,20 @@ def test_data_unknown_user_enrolls_when_under_both_caps(client, monkeypatch):
|
|||||||
assert dbmod.get_settings("testuser") is not None
|
assert dbmod.get_settings("testuser") is not None
|
||||||
|
|
||||||
|
|
||||||
|
# ---- README snippet pasted without substituting the username ----
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("name", ["YOUR_USERNAME", "your_username", "yourusername", "username"])
|
||||||
|
def test_unsubstituted_placeholder_returns_card_not_400(client, name):
|
||||||
|
"""The README snippet uses YOUR_USERNAME. People paste it as-is, which
|
||||||
|
renders a broken image on their profile. Serve instructions instead."""
|
||||||
|
r = client.get(f"/api/{name}")
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.mimetype == "image/svg+xml"
|
||||||
|
assert r.headers["X-Widget-Status"] == "unsubstituted"
|
||||||
|
assert b"Replace YOUR_USERNAME" in r.data
|
||||||
|
|
||||||
|
|
||||||
# ---- /api/top-langs compat shim for upstream github-readme-stats URLs ----
|
# ---- /api/top-langs compat shim for upstream github-readme-stats URLs ----
|
||||||
|
|
||||||
|
|
||||||
@@ -690,6 +719,20 @@ def test_query_override_without_params_uses_cached_composite(client):
|
|||||||
assert b"<svg>cached</svg>" in r.data
|
assert b"<svg>cached</svg>" in r.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_query_override_skips_adhoc_render_before_first_build(client):
|
||||||
|
"""With no build landed yet the fetcher likely has no data, so an ad hoc
|
||||||
|
render would start a GitHub fetch per request. Serve the building
|
||||||
|
placeholder instead."""
|
||||||
|
dbmod.enroll("alice", {"theme": "midnight"})
|
||||||
|
|
||||||
|
with patch("src.worker.render_composite_adhoc") as adhoc:
|
||||||
|
r = client.get("/api/alice?theme=onyx&widgets=name,grade")
|
||||||
|
assert adhoc.call_count == 0
|
||||||
|
|
||||||
|
assert r.status_code == 200
|
||||||
|
assert r.headers["X-Widget-Status"] == "building"
|
||||||
|
|
||||||
|
|
||||||
def test_query_override_ignores_unknown_params(client):
|
def test_query_override_ignores_unknown_params(client):
|
||||||
"""Keys not in the allow-list are dropped by sanitize_settings_query so
|
"""Keys not in the allow-list are dropped by sanitize_settings_query so
|
||||||
bogus query strings don't trigger the expensive ad-hoc path."""
|
bogus query strings don't trigger the expensive ad-hoc path."""
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ def test_attribution_is_legible_and_consistent(name):
|
|||||||
assert node.get("text-anchor") == "middle"
|
assert node.get("text-anchor") == "middle"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("variant", ["building", "rate_limited", "not_found"])
|
@pytest.mark.parametrize("variant", ["building", "rate_limited", "not_found", "unsubstituted"])
|
||||||
def test_placeholder_cards_have_attribution(variant):
|
def test_placeholder_cards_have_attribution(variant):
|
||||||
svg = placeholder.render(variant, "alice", theme="dark")
|
svg = placeholder.render(variant, "alice", theme="dark")
|
||||||
assert "Generated with gh-stats.com" in svg
|
assert "Generated with gh-stats.com" in svg
|
||||||
|
|||||||
@@ -83,6 +83,56 @@ def test_worker_marks_failed_after_max_attempts(tmp_dbs):
|
|||||||
assert row["attempts"] >= 3
|
assert row["attempts"] >= 3
|
||||||
|
|
||||||
|
|
||||||
|
def _http_503(retry_after=None):
|
||||||
|
import requests
|
||||||
|
resp = requests.Response()
|
||||||
|
resp.status_code = 503
|
||||||
|
if retry_after is not None:
|
||||||
|
resp.headers["Retry-After"] = str(retry_after)
|
||||||
|
return requests.HTTPError("503 Server Error", response=resp)
|
||||||
|
|
||||||
|
|
||||||
|
def test_worker_backs_off_on_rate_limit(tmp_dbs):
|
||||||
|
"""A fetcher 503 (GitHub quota spent) delays the retry instead of
|
||||||
|
burning all attempts in seconds; the job is not claimable until then."""
|
||||||
|
dbmod.enroll("alice", {"theme": "dark"})
|
||||||
|
with patch("src.worker.fetcher_client.get_data", side_effect=_http_503()):
|
||||||
|
worker.process_one()
|
||||||
|
assert worker.process_one() is False # backing off, nothing claimable
|
||||||
|
with dbmod._settings_conn() as c:
|
||||||
|
row = c.execute("SELECT status, attempts, updated_at FROM jobs WHERE username='alice'").fetchone()
|
||||||
|
assert row["status"] == "pending"
|
||||||
|
assert row["attempts"] == 1
|
||||||
|
assert row["updated_at"] > dbmod._now()
|
||||||
|
# Once the delay has passed the job is claimed again.
|
||||||
|
with dbmod._settings_conn() as c:
|
||||||
|
c.execute("UPDATE jobs SET updated_at='2020-01-01T00:00:00Z'")
|
||||||
|
c.commit()
|
||||||
|
assert dbmod.claim_next_job()["username"] == "alice"
|
||||||
|
|
||||||
|
|
||||||
|
def test_rate_limit_delay_grows_honors_retry_after_and_caps():
|
||||||
|
with patch("src.worker.random.uniform", return_value=1.0):
|
||||||
|
assert worker._rate_limit_delay(_http_503(), 1) == 60
|
||||||
|
assert worker._rate_limit_delay(_http_503(), 3) == 240
|
||||||
|
assert worker._rate_limit_delay(_http_503(retry_after=600), 1) == 600
|
||||||
|
assert worker._rate_limit_delay(_http_503(), 10) == worker.RATE_LIMIT_BACKOFF_CAP_S
|
||||||
|
|
||||||
|
|
||||||
|
def test_worker_rate_limit_allows_more_attempts(tmp_dbs):
|
||||||
|
dbmod.enroll("alice", {"theme": "dark"})
|
||||||
|
with patch("src.worker.fetcher_client.get_data", side_effect=_http_503()):
|
||||||
|
for _ in range(worker.RATE_LIMIT_MAX_ATTEMPTS):
|
||||||
|
with dbmod._settings_conn() as c:
|
||||||
|
c.execute("UPDATE jobs SET updated_at='2020-01-01T00:00:00Z' WHERE status='pending'")
|
||||||
|
c.commit()
|
||||||
|
worker.process_one()
|
||||||
|
with dbmod._settings_conn() as c:
|
||||||
|
row = c.execute("SELECT status, attempts FROM jobs WHERE username='alice'").fetchone()
|
||||||
|
assert row["status"] == "failed"
|
||||||
|
assert row["attempts"] == worker.RATE_LIMIT_MAX_ATTEMPTS
|
||||||
|
|
||||||
|
|
||||||
def test_process_one_persists_streak(tmp_dbs):
|
def test_process_one_persists_streak(tmp_dbs):
|
||||||
"""Phase 1 worker must compute and persist the user's streak so max survives
|
"""Phase 1 worker must compute and persist the user's streak so max survives
|
||||||
future settings changes."""
|
future settings changes."""
|
||||||
|
|||||||
Reference in New Issue
Block a user