mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(collaborators, fetcher, languages): update collaborator display limit and enhance language widget rendering
This commit is contained in:
@@ -33,6 +33,10 @@ class GitHubDataSource(Protocol):
|
|||||||
"""Fetch commits from repositories."""
|
"""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:
|
def fetch_repo_contributors(self, repo_name: str, min_commits: int) -> list:
|
||||||
"""Fetch contributors for a specific repository."""
|
"""Fetch contributors for a specific repository."""
|
||||||
...
|
...
|
||||||
@@ -138,6 +142,38 @@ class DirectAPISource:
|
|||||||
|
|
||||||
return all_commits
|
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:
|
def fetch_repo_contributors(self, repo_name: str, min_commits: int = 1) -> list:
|
||||||
"""
|
"""
|
||||||
Fetch contributors for a specific repository.
|
Fetch contributors for a specific repository.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str
|
|||||||
t = THEMES[theme_name]
|
t = THEMES[theme_name]
|
||||||
items = ""
|
items = ""
|
||||||
|
|
||||||
for i, c in enumerate(collabs[:5]):
|
for i, c in enumerate(collabs[:4]):
|
||||||
y = i * 50
|
y = i * 50
|
||||||
avatar_el = ""
|
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-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif"
|
||||||
font-size="14" font-weight="600" fill="white">{escape(c.username[0].upper())}</text>'''
|
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
|
bar_w = c.shared_commits / bar_max * 120
|
||||||
|
|
||||||
items += f'''
|
items += f'''
|
||||||
@@ -40,5 +40,5 @@ def render_collaborators_widget(collabs: list[CollaboratorData], theme_name: str
|
|||||||
</rect>
|
</rect>
|
||||||
</g>'''
|
</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")
|
return card_wrapper(items, 380, total_h, t, "Top Collaborators")
|
||||||
|
|||||||
@@ -9,10 +9,31 @@ from ..utils import escape, card_wrapper
|
|||||||
def render_languages_widget(languages: list[LanguageData], theme_name: str = "dark") -> str:
|
def render_languages_widget(languages: list[LanguageData], theme_name: str = "dark") -> str:
|
||||||
"""Renders the languages donut chart widget."""
|
"""Renders the languages donut chart widget."""
|
||||||
t = THEMES[theme_name]
|
t = THEMES[theme_name]
|
||||||
langs = sorted(languages, key=lambda l: -l.percentage)[:6]
|
top_langs = sorted(languages, key=lambda l: -l.percentage)[:5]
|
||||||
if not langs:
|
if not top_langs:
|
||||||
return ""
|
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
|
# Calculate center position to align with legend
|
||||||
legend_start = 20
|
legend_start = 20
|
||||||
legend_height = len(langs) * 22
|
legend_height = len(langs) * 22
|
||||||
@@ -26,7 +47,12 @@ def render_languages_widget(languages: list[LanguageData], theme_name: str = "da
|
|||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
for i, lang in enumerate(langs):
|
for i, lang in enumerate(langs):
|
||||||
|
# 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)])
|
color = LANG_COLORS.get(lang.language, FOCUS_COLORS[i % len(FOCUS_COLORS)])
|
||||||
|
|
||||||
dash = circumference * lang.percentage / 100
|
dash = circumference * lang.percentage / 100
|
||||||
gap = circumference - dash
|
gap = circumference - dash
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user