feat(collaborators, fetcher, languages): update collaborator display limit and enhance language widget rendering

This commit is contained in:
shay
2026-02-18 13:56:42 -05:00
parent dc6de9c2a9
commit e4c9f91190
3 changed files with 68 additions and 6 deletions
+36
View File
@@ -33,6 +33,10 @@ class GitHubDataSource(Protocol):
"""Fetch commits from repositories."""
...
def fetch_commit_count(self, username: str, since_date: str = None) -> int:
"""Fetch total commit count using search API."""
...
def fetch_repo_contributors(self, repo_name: str, min_commits: int) -> list:
"""Fetch contributors for a specific repository."""
...
@@ -138,6 +142,38 @@ class DirectAPISource:
return all_commits
def fetch_commit_count(self, username: str, since_date: str = None) -> int:
"""
Fetch total commit count using GitHub search API.
Args:
username: GitHub username
since_date: ISO date string (YYYY-MM-DD) to filter commits after this date
Returns:
Total number of commits
"""
try:
# Build search query
query = f"author:{username}"
if since_date:
query += f" author-date:>={since_date}"
resp = requests.get(
f"{self.base}/search/commits",
headers={**self.headers, "Accept": "application/vnd.github.cloak-preview+json"},
params={"q": query, "per_page": 1},
timeout=API_TIMEOUT
)
if resp.ok:
data = resp.json()
return data.get("total_count", 0)
except Exception as e:
print(f"Warning: Failed to fetch commit count via search API: {e}")
return 0
def fetch_repo_contributors(self, repo_name: str, min_commits: int = 1) -> list:
"""
Fetch contributors for a specific repository.
+3 -3
View File
@@ -10,7 +10,7 @@ def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str
t = THEMES[theme_name]
items = ""
for i, c in enumerate(collabs[:5]):
for i, c in enumerate(collabs[:4]):
y = i * 50
avatar_el = ""
@@ -24,7 +24,7 @@ def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str
font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
font-size="14" font-weight="600" fill="white">{escape(c.username[0].upper())}</text>'''
bar_max = max((x.shared_commits for x in collabs[:5]), default=1) or 1
bar_max = max((x.shared_commits for x in collabs[:4]), default=1) or 1
bar_w = c.shared_commits / bar_max * 120
items += f'''
@@ -40,5 +40,5 @@ def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str
</rect>
</g>'''
total_h = len(collabs[:5]) * 50 + 48
total_h = len(collabs[:4]) * 50 + 48
return card_wrapper(items, 380, total_h, t, "Top Collaborators")
+29 -3
View File
@@ -9,10 +9,31 @@ from ..utils import escape, card_wrapper
def render_languages_widget(languages: list[LanguageData], theme_name: str = "dark") -> str:
"""Renders the languages donut chart widget."""
t = THEMES[theme_name]
langs = sorted(languages, key=lambda l: -l.percentage)[:6]
if not langs:
top_langs = sorted(languages, key=lambda l: -l.percentage)[:5]
if not top_langs:
return ""
# Ensure percentages always sum to exactly 100% for a complete circle
total_percentage = sum(lang.percentage for lang in top_langs)
langs = list(top_langs)
# Add "Other" category if there are remaining languages
if total_percentage < 99.9 and len(languages) > 5:
other_percentage = 100 - total_percentage
from ..models import LanguageData
langs.append(LanguageData(
language="Other",
percentage=round(other_percentage, 1),
loc=0
))
elif total_percentage < 99.9:
# If we have <= 5 languages total but they don't sum to 100%,
# adjust the percentages proportionally to sum to 100%
if total_percentage > 0:
factor = 100 / total_percentage
for lang in langs:
lang.percentage = round(lang.percentage * factor, 1)
# Calculate center position to align with legend
legend_start = 20
legend_height = len(langs) * 22
@@ -26,7 +47,12 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da
offset = 0
for i, lang in enumerate(langs):
color = LANG_COLORS.get(lang.language, FOCUS_COLORS[i % len(FOCUS_COLORS)])
# Use gray for "Other" category
if lang.language == "Other":
color = t["text_secondary"]
else:
color = LANG_COLORS.get(lang.language, FOCUS_COLORS[i % len(FOCUS_COLORS)])
dash = circumference * lang.percentage / 100
gap = circumference - dash