fix(scripts): accept legacy consecutive-hyphen GitHub logins in add_contributor

GitHub's current signup rules forbid consecutive hyphens, but legacy
accounts with them exist and are valid (Roger--Han, hit live during the
July 24 sweep — the mapping had to be written by hand). Accept any
alphanumeric/hyphen login that doesn't start or end with a hyphen.
This commit is contained in:
teknium1 2026-07-24 21:50:23 -07:00 committed by Teknium
parent 4ba71e6aa4
commit 4aab4c28d7
2 changed files with 14 additions and 1 deletions

View file

@ -25,7 +25,11 @@ REPO_ROOT = Path(__file__).resolve().parent.parent
EMAILS_DIR = REPO_ROOT / "contributors" / "emails"
_EMAIL_RE = re.compile(r"^[^/\\\s]+@[^/\\\s]+$")
_LOGIN_RE = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}$")
# GitHub's *current* signup rules forbid consecutive hyphens, but legacy
# accounts with them exist and are valid (e.g. Roger--Han, verified via the
# users API July 2026). Accept any alphanumeric/hyphen login that doesn't
# start or end with a hyphen, max 39 chars.
_LOGIN_RE = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$")
def read_mapping_file(path: Path) -> str | None:

View file

@ -114,6 +114,15 @@ def test_add_rejects_invalid_email_and_login(emails_dir):
)
def test_add_accepts_legacy_consecutive_hyphen_login(emails_dir):
# Legacy GitHub accounts with consecutive hyphens are real (Roger--Han);
# current signup rules forbid them but existing logins remain valid.
assert add_contributor("roger.hanhong@gmail.com", "Roger--Han") == 0
assert (emails_dir / "roger.hanhong@gmail.com").read_text(
encoding="utf-8"
).strip().endswith("Roger--Han")
def test_add_strips_at_prefix(emails_dir):
assert add_contributor("z@z.com", "@zeta") == 0
assert read_mapping_file(emails_dir / "z@z.com") == "zeta"