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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user