mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-21 16:52:19 +09:00
[CI] (scripts/ci): rank unique release contributors by commit count
This commit is contained in:
1 parent
6306b28af5
commit
951f3735cd
1 file changed
+31
-8
+31
-8
@@ -10,6 +10,7 @@
|
|||||||
"""Validate and publish an annotated version tag after both required workflows succeed."""
|
"""Validate and publish an annotated version tag after both required workflows succeed."""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
from collections import Counter
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -237,21 +238,43 @@ def previous_release(github, tag, commit):
|
|||||||
|
|
||||||
|
|
||||||
def contributors(github, revision):
|
def contributors(github, revision):
|
||||||
authors = {}
|
representatives = {}
|
||||||
|
commit_counts = Counter()
|
||||||
data = git("log", "-z", "--format=%H%x00%aN%x00%aE", revision)
|
data = git("log", "-z", "--format=%H%x00%aN%x00%aE", revision)
|
||||||
fields = data.split("\0")
|
fields = data.split("\0")
|
||||||
for commit, name, email in zip(fields[::3], fields[1::3], fields[2::3]):
|
for commit, name, email in zip(fields[::3], fields[1::3], fields[2::3]):
|
||||||
authors.setdefault((name, email.casefold()), commit)
|
identity = (name, email.casefold())
|
||||||
credits = {}
|
representatives.setdefault(identity, commit)
|
||||||
for (name, _email), commit in authors.items():
|
commit_counts[identity] += 1
|
||||||
|
|
||||||
|
linked = {}
|
||||||
|
for identity, commit in representatives.items():
|
||||||
author = github.request(f"/commits/{commit}").get("author") or {}
|
author = github.request(f"/commits/{commit}").get("author") or {}
|
||||||
login = author.get("login", "")
|
login = author.get("login", "")
|
||||||
|
if LOGIN.fullmatch(login):
|
||||||
|
linked[identity] = login
|
||||||
|
|
||||||
|
# An unlinked author name can match a login confirmed by another commit.
|
||||||
|
known_logins = {login.casefold(): login for login in linked.values()}
|
||||||
|
labels = {}
|
||||||
|
totals = Counter()
|
||||||
|
for identity, count in commit_counts.items():
|
||||||
|
name = " ".join(identity[0].split())
|
||||||
|
login = linked.get(identity) or known_logins.get(name.removeprefix("@").casefold())
|
||||||
escaped_name = "".join(f"\\{char}" if char in "\\@<>&*_[`]" else char
|
escaped_name = "".join(f"\\{char}" if char in "\\@<>&*_[`]" else char
|
||||||
for char in " ".join(name.split()))
|
for char in name)
|
||||||
credit = f"@{login}" if LOGIN.fullmatch(login) else escaped_name
|
credit = f"@{login}" if login else escaped_name
|
||||||
if credit:
|
if credit:
|
||||||
credits.setdefault(credit.casefold(), credit)
|
key = credit.casefold()
|
||||||
return ", ".join(sorted(credits.values(), key=str.casefold))
|
labels.setdefault(key, credit)
|
||||||
|
totals[key] += count
|
||||||
|
|
||||||
|
rows = []
|
||||||
|
for key in sorted(totals, key=lambda key: (-totals[key], key)):
|
||||||
|
count = totals[key]
|
||||||
|
unit = "commit" if count == 1 else "commits"
|
||||||
|
rows.append(f"- {labels[key]} — {count:,} {unit}")
|
||||||
|
return "\n".join(rows)
|
||||||
|
|
||||||
|
|
||||||
def publish(github, tag, tag_sha, commit, notes, sender):
|
def publish(github, tag, tag_sha, commit, notes, sender):
|
||||||
|
|||||||
Reference in new issue
Block a user