From 66d48fcb7f1ed2ab3ee575fd6756ed41b6cda866 Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Mon, 28 Sep 2026 14:38:51 +0800 Subject: [PATCH] docs: refresh contributors and preserve historical credits (#5951) * docs: refresh contributors and preserve historical credits * fix: rank retained contributors by recovered commit counts * chore: remove contributor updater tests * docs: remove contributor history introduction --- README.md | 51 ++++++++++++---- scripts/update_readme_contributors.py | 87 +++++++++++++++++++++------ 2 files changed, 107 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index e4ed7f92e..e789b42af 100644 --- a/README.md +++ b/README.md @@ -404,10 +404,11 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem Athemis axelray-dev yorkhellen +yu-xin-c 04cb santhreal -yu-xin-c xcosmosbox +KDB-Wind kunalk16 chaohuang-ai zayfod @@ -416,11 +417,10 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem flobo3 hamb1y SergioSV96 -KDB-Wind morandot +michaelxer coldxiangyu163 boogieLing -michaelxer aiguozhi123456 pinhua33 pixan-ai @@ -430,6 +430,7 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem IlyaGusev T3chC0wb0y VITOHJL +KailBug macroadster Hinotoi-agent kingassune @@ -448,20 +449,24 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem HaisamAbbas anunay999 flaviovs +dajiaohuang C-Li Ho1yShif pjhoberman nghiahsgs Bahtya +ZhouJ-sh +bingqilinweimaotai +Shizoqua tangtaizong666 XJPeng12 yanghan-cyber -ZhouJ-sh Yuxin-Lou LeoFYH claude chris-alexander benlenarts +wzrayyy outlook84 Mrart ramonpaolo @@ -469,7 +474,6 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem tangjiabin yeyitech Flinn-X -bingqilinweimaotai Qinnnnnn HengWeiBin waelantar @@ -478,7 +482,6 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem masterlyj xgzlucario dzydzydzy7 -dajiaohuang concertypin WangCheng0116 yarikoptic @@ -486,6 +489,8 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem gongpx20069 tobrien Shiniese +zpljd258 +FanouZeng-TT shawnWXN sbyinin nne998 @@ -497,13 +502,11 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem who96 cyzlmh zhuzhh -zpljd258 cms19859230182-lang amplifierplus LZDQ wb213 shaun0927 -wzrayyy LHMQ878 Michael-lhh Mizarka @@ -518,6 +521,9 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem chtangwin dxtime ethanclaw +Naster17 +L4XB +Oxygen56 WufeiHalf stutiredboy stupidloud @@ -546,7 +552,6 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem honjiaxuan DeeJ4yNg danielphang -yanalialiuk zhouzhuojie zerone0x yrk111222 @@ -554,8 +559,6 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem suger-m mengyhang Liwx1014 -Shizoqua -KailBug 19emtuck tsubasakong wseng @@ -588,6 +591,14 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem pjbakker luojiaaoo NearlCrews +Krislu1221 +beemines +Wsp030914 +pengpengyi92 +LuckTerence +yankeguo +nolanchic +yanalialiuk yongPhone ZXGERIC erikmackinnon @@ -695,7 +706,6 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem kamalakarrao KEEPSLAMDUNK krisLu -Krislu1221 kyya rreben ATECHPCS @@ -766,6 +776,23 @@ Use nanobot for a real task, report what broke, and then pick a focused improvem RohitDayanand katafractari rudy-of-the-corner +fszcd +kkkhoo +chrischen-coder +cleverLucky +n1uz1 +shakewingo +Kuang-xianxin +0717lee +loseintwilight +AlfredChaos +BenWituka +gary23w +tilladam +DannyYTL +yaoruiquan +GUTYL +ZedingZhang

diff --git a/scripts/update_readme_contributors.py b/scripts/update_readme_contributors.py index 734b3f3d6..a6488abdf 100644 --- a/scripts/update_readme_contributors.py +++ b/scripts/update_readme_contributors.py @@ -6,8 +6,10 @@ from __future__ import annotations import argparse import json import os +import re from pathlib import Path -from typing import TypedDict, cast +from typing import NotRequired, TypedDict, cast +from urllib.parse import urlencode from urllib.request import Request, urlopen REPOSITORY = "HKUDS/nanobot" @@ -23,9 +25,23 @@ class Contributor(TypedDict): type: str html_url: str avatar_url: str + contributions: int + email: NotRequired[str] -def fetch_contributors() -> list[Contributor]: +class CommitAuthor(TypedDict): + email: str + + +class CommitData(TypedDict): + author: CommitAuthor + + +class Commit(TypedDict): + commit: CommitData + + +def fetch_pages(endpoint: str, **params: str) -> list[object]: headers = { "Accept": "application/vnd.github+json", "User-Agent": "nanobot-readme", @@ -34,28 +50,61 @@ def fetch_contributors() -> list[Contributor]: if token := os.environ.get("GITHUB_TOKEN"): headers["Authorization"] = f"Bearer {token}" - contributors: list[Contributor] = [] + entries: list[object] = [] page = 1 while True: - url = f"https://api.github.com/repos/{REPOSITORY}/contributors?per_page={PER_PAGE}&page={page}" + query = urlencode({**params, "per_page": PER_PAGE, "page": page}) + url = f"https://api.github.com/repos/{REPOSITORY}/{endpoint}?{query}" with urlopen(Request(url, headers=headers), timeout=30) as response: # noqa: S310 - batch = cast(list[Contributor], json.load(response)) - contributors.extend(batch) + batch = json.load(response) + if not isinstance(batch, list): + raise ValueError("Expected a GitHub API list response") + entries.extend(batch) if len(batch) < PER_PAGE: break page += 1 - return [ - contributor - for contributor in contributors - if contributor.get("login") - and contributor.get("type") != "Bot" - and not contributor["login"].lower().endswith("[bot]") - and contributor["login"].lower() not in MAINTAINERS - ] + return entries -def render_wall(contributors: list[Contributor]) -> str: +def fetch_contributors(previous_wall: str = "") -> list[Contributor]: + # Shapes follow the GitHub contributors and commits REST response schemas. + entries = cast(list[Contributor], fetch_pages("contributors", anon="1")) + contributors = { + c["login"].lower(): c for c in entries + if c.get("login") and c.get("type") != "Bot" + and not c["login"].lower().endswith("[bot]") + and c["login"].lower() not in MAINTAINERS + } + anonymous = {c["email"].lower(): c["contributions"] for c in entries + if c.get("type") == "Anonymous" and c.get("email")} + # The endpoint only links the first 500 author emails to accounts. Recover + # counts for existing credits from anonymous entries using attributed commits. + # https://docs.github.com/en/rest/repos/repos#list-repository-contributors + pattern = r'' + for html_url, avatar_url, login in re.findall(pattern, previous_wall): + key = login.lower() + if key in contributors or key in MAINTAINERS or key.endswith("[bot]"): + continue + commits = cast(list[Commit], fetch_pages("commits", author=login)) + emails = {c["commit"]["author"]["email"].lower() for c in commits} + count = sum(anonymous[email] for email in emails if email in anonymous) + if not count: + raise SystemExit(f"Cannot resolve contribution count for {login}; README unchanged") + contributors[key] = Contributor( + login=login, type="User", html_url=html_url, + avatar_url=avatar_url.removesuffix("&s=48"), contributions=count, + ) + return list(contributors.values()) + + +def render_wall(contributors: list[Contributor], previous_wall: str = "") -> str: + previous_order = { + login.lower(): i for i, login in enumerate(re.findall(r'alt="([^"]+)"', previous_wall)) + } + contributors = sorted(contributors, key=lambda c: ( + -c["contributions"], previous_order.get(c["login"].lower(), len(previous_order)), + )) avatars = [ ( f'' @@ -69,18 +118,18 @@ def render_wall(contributors: list[Contributor]) -> str: def update_readme(*, check: bool) -> bool: - current = README.read_text() + current = README.read_text(encoding="utf-8") before, separator, tail = current.partition(START) if not separator or END not in tail: raise SystemExit("README contributor markers are missing") - _, _, after = tail.partition(END) - updated = f"{before}{render_wall(fetch_contributors())}{after}" + previous_wall, _, after = tail.partition(END) + updated = f"{before}{render_wall(fetch_contributors(previous_wall), previous_wall)}{after}" if updated == current: return False if check: raise SystemExit("README contributor wall is out of date") - README.write_text(updated) + README.write_text(updated, encoding="utf-8") return True