-
Notifications
You must be signed in to change notification settings - Fork 1
Use direct avatars.githubusercontent.com URL for contributor avatars #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
f5a537c
10ab2bf
88b4073
6524835
ca23512
c945a26
cf61618
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| """Fetch contributor stats from all NextCommunity repos and update the leaderboard.""" | ||
|
|
||
| import html | ||
| import os | ||
| import re | ||
| import sys | ||
| import urllib.error | ||
| import urllib.parse | ||
| import urllib.request | ||
| import json | ||
| from bisect import bisect_right | ||
|
|
@@ -16,6 +18,9 @@ | |
| LEADERBOARD_START = "<!-- LEADERBOARD:START -->" | ||
| LEADERBOARD_END = "<!-- LEADERBOARD:END -->" | ||
| SITE_REPO_NAME = "NextCommunity.github.io" | ||
|
|
||
| # GitHub usernames: alphanumeric and single hyphens, 1-39 characters. | ||
| _GITHUB_LOGIN_RE = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$") | ||
| DOTGITHUB_REPO_NAME = ".github" | ||
|
|
||
| # Self-documenting record for each commit entry collected across all repos. | ||
|
|
@@ -707,6 +712,24 @@ def build_leaderboard(token=None): | |
| return sorted_contributors, had_errors, levels_data | ||
|
|
||
|
|
||
| def _contributor_cell(login): | ||
| """Return a pure-HTML table cell with avatar and username link. | ||
|
|
||
| ``login`` is validated against GitHub's username pattern before use. | ||
| Raises ``ValueError`` if the login contains unexpected characters. | ||
| """ | ||
| if not _GITHUB_LOGIN_RE.match(login): | ||
| raise ValueError(f"Invalid GitHub login: {login!r}") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raising a Consider validating the login earlier in the pipeline (e.g., in |
||
| safe_login = urllib.parse.quote(login, safe="") | ||
| escaped_login = html.escape(login) | ||
| return ( | ||
| f'<a href="https://github.com/{safe_login}">' | ||
| f'<img src="https://avatars.githubusercontent.com/{safe_login}?s=64"' | ||
| f' width="32" height="32" alt="{escaped_login}\'s avatar"><br>' | ||
| f"@{escaped_login}</a>" | ||
| ) | ||
|
|
||
|
|
||
| def generate_markdown(contributors, levels_data): | ||
| """Generate a gamified markdown leaderboard from contributor data.""" | ||
| rank_badges = {1: "🥇", 2: "🥈", 3: "🥉"} | ||
|
|
@@ -767,8 +790,9 @@ def generate_markdown(contributors, levels_data): | |
| commits_display += f" · 🤝 {coauthored}" | ||
| commits_display += f" · 📦 {repos_count}" | ||
|
|
||
| contributor_cell = _contributor_cell(login) | ||
| lines.append( | ||
| f"| {rank} | [@{login}](https://github.com/{login})" | ||
| f"| {rank} | {contributor_cell}" | ||
| f" | {level} | {rarity_display} | {commits_display}" | ||
| f" | {prog} | {streak_display}" | ||
| f" | {badges} | {points_display} |" | ||
|
|
@@ -812,8 +836,9 @@ def generate_markdown(contributors, levels_data): | |
| breakdown_parts.append(f"📁 {other_c}") | ||
| breakdown = " · ".join(breakdown_parts) if breakdown_parts else "—" | ||
|
|
||
| contributor_cell = _contributor_cell(login) | ||
| lines.append( | ||
| f"| {i} | [@{login}](https://github.com/{login})" | ||
| f"| {i} | {contributor_cell}" | ||
| f" | {first_date} | {last_date}" | ||
| f" | {days_active} | {cpd}" | ||
| f" | {breakdown} | Top {pctile}% |" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.