Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(health): count active contributors by canonical identity (#4086)

JackGitLaba70dc5674d0e
diff --git a/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py b/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py
index cb1c81ada..f45c1518f 100644
--- a/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py
+++ b/packages/core/src/repowise/core/ingestion/git_indexer/enrich.py
@@ -13,7 +13,7 @@ import json
from collections import Counter
from typing import Any
-from repowise.core.author_identity import identity_kind, is_bot
+from repowise.core.author_identity import author_identity_key, identity_kind, is_bot
from ._constants import (
_DECISION_SIGNAL_WORDS,
@@ -181,13 +181,15 @@ def count_active_contributors(metadata_list: list[dict], *, window_days: int = 9
if not isinstance(ts, int | float) or ts <= 0:
continue
name = str(a.get("name") or "").strip()
- if not name:
+ email = a.get("email")
+ key = author_identity_key(name, email)
+ if not key:
continue
- if is_bot(name, a.get("email")):
+ if is_bot(name, email):
continue
- prev = author_last_ts.get(name)
+ prev = author_last_ts.get(key)
if prev is None or ts > prev:
- author_last_ts[name] = int(ts)
+ author_last_ts[key] = int(ts)
if not author_last_ts:
return None
diff --git a/tests/unit/test_git_indexer.py b/tests/unit/test_git_indexer.py
index 837e81ce5..068a090cf 100644
--- a/tests/unit/test_git_indexer.py
+++ b/tests/unit/test_git_indexer.py
@@ -380,6 +380,67 @@ class TestCountActiveContributors:
metas = [self._meta(("Alice", anchor), ("Bob", anchor - 30 * 86400))]
assert count_active_contributors(metas) == 2
+ @pytest.mark.parametrize(
+ ("authors", "expected"),
+ [
+ pytest.param(
+ [("Alice Smith", "[email protected]"), ("alice", "[email protected]")],
+ 1,
+ id="same-email-aliases",
+ ),
+ pytest.param(
+ [("Alex", "[email protected]"), ("Alex", "[email protected]")],
+ 2,
+ id="same-name-distinct-emails",
+ ),
+ pytest.param(
+ [
+ ("Alice", "[email protected]"),
+ ("alice", "[email protected]"),
+ ],
+ 1,
+ id="canonical-noreply-email",
+ ),
+ pytest.param([("Alice", None), (" Alice ", None)], 1, id="name-fallback-whitespace"),
+ pytest.param([("Alice", None), ("alice", None)], 1, id="name-fallback-case-insensitive"),
+ pytest.param([("", "[email protected]")], 1, id="email-without-name"),
+ pytest.param([("", None)], None, id="missing-identity"),
+ ],
+ )
+ def test_counts_canonical_identities(
+ self, authors: list[tuple[str, str | None]], expected: int | None
+ ) -> None:
+ import json
+
+ from repowise.core.ingestion.git_indexer.enrich import count_active_contributors
+
+ metas = [{
+ "top_authors_json": json.dumps([
+ {"name": name, "email": email, "last_commit_ts": 1_700_000_000}
+ for name, email in authors
+ ])
+ }]
+ assert count_active_contributors(metas) == expected
+
+ def test_identity_keeps_latest_timestamp_across_files(self) -> None:
+ import json
+
+ from repowise.core.ingestion.git_indexer.enrich import count_active_contributors
+
+ anchor = 1_700_000_000
+ cutoff = anchor - 30 * 86400
+ metas = [
+ {"top_authors_json": json.dumps([
+ {"name": "Alice", "email": "[email protected]", "last_commit_ts": anchor},
+ {"name": "Bob", "email": "[email protected]", "last_commit_ts": cutoff},
+ ])},
+ {"top_authors_json": json.dumps([
+ {"name": "alice", "email": "[email protected]", "last_commit_ts": cutoff - 1},
+ {"name": "Carol", "email": "[email protected]", "last_commit_ts": cutoff - 1},
+ ])},
+ ]
+ assert count_active_contributors(metas, window_days=30) == 2
+
# ---------------------------------------------------------------------------
# 4. test_stable_classification