mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(launch): friendly GitHub-limit message on Generate; document the score formula
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -115,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
|
||||
|
||||
Your contribution volume over the last 6 months, drawn as a smooth area
|
||||
|
||||
@@ -87,6 +87,10 @@ def get_data(username: str):
|
||||
t0 = time.monotonic()
|
||||
try:
|
||||
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:
|
||||
analytics.record_fetch(username, 502, int((time.monotonic() - t0) * 1000))
|
||||
log.exception("github fetch failed for %s", username)
|
||||
|
||||
@@ -203,3 +203,15 @@ 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": {"message": "Not Found"}}) 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
|
||||
|
||||
@@ -350,6 +350,13 @@ export default function App() {
|
||||
setGenerateError(body.status === 'not_found' ? 'User not found' : 'Not enrolled')
|
||||
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) {
|
||||
setGenerateError(`Generate failed (HTTP ${r.status})`)
|
||||
return
|
||||
|
||||
@@ -540,6 +540,16 @@ export function WorkshopScreen({
|
||||
/>
|
||||
</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' && (
|
||||
<div>
|
||||
|
||||
@@ -1135,7 +1135,14 @@ def generate(username: str):
|
||||
widgets = worker.render_widgets_now(username)
|
||||
except LookupError:
|
||||
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)
|
||||
return jsonify({"error": "render_failed"}), 502
|
||||
finally:
|
||||
|
||||
@@ -316,6 +316,21 @@ def test_generate_endpoint_renders_and_stores_svg(client):
|
||||
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):
|
||||
"""With OAuth, unenrolled means having a session but no profile."""
|
||||
with client.session_transaction() as s:
|
||||
|
||||
Reference in New Issue
Block a user