diff --git a/README.md b/README.md index e141779..f8be7c7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/fetcher/src/api.py b/fetcher/src/api.py index 8987fe5..d832884 100644 --- a/fetcher/src/api.py +++ b/fetcher/src/api.py @@ -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) diff --git a/fetcher/tests/test_api.py b/fetcher/tests/test_api.py index 7c6ca5a..bec8a3e 100644 --- a/fetcher/tests/test_api.py +++ b/fetcher/tests/test_api.py @@ -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 diff --git a/generator/frontend/src/App.tsx b/generator/frontend/src/App.tsx index 0e3e8d2..a90d37b 100644 --- a/generator/frontend/src/App.tsx +++ b/generator/frontend/src/App.tsx @@ -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 diff --git a/generator/frontend/src/screens/WorkshopScreen.tsx b/generator/frontend/src/screens/WorkshopScreen.tsx index 3d99b4d..5171d86 100644 --- a/generator/frontend/src/screens/WorkshopScreen.tsx +++ b/generator/frontend/src/screens/WorkshopScreen.tsx @@ -540,6 +540,16 @@ export function WorkshopScreen({ /> )} + {w.id === 'grade' && ( + + How the score works + + )} {w.id === 'impact' && (