47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
import csv
|
|
import json
|
|
import subprocess
|
|
|
|
# True source of truth: the repo's git history, author by author.
|
|
out = subprocess.run(
|
|
["git", "log", "--format=%an"], capture_output=True, text=True, check=True
|
|
).stdout
|
|
counts = {}
|
|
for line in out.splitlines():
|
|
counts[line] = counts.get(line, 0) + 1
|
|
|
|
# Deterministic order: count desc, author asc.
|
|
rows = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0]))
|
|
|
|
with open("commits-by-author.tsv", "w", encoding="utf-8") as fh:
|
|
w = csv.writer(fh, delimiter="\t", lineterminator="\n")
|
|
w.writerow(["author", "commits"])
|
|
for author, commits in rows:
|
|
w.writerow([author, commits])
|
|
|
|
total = sum(c for _, c in rows)
|
|
with open("commits-by-author.json", "w", encoding="utf-8") as fh:
|
|
json.dump(
|
|
{
|
|
"generated_utc": "2026-10-29T17:00:00Z",
|
|
"source": "git log --format=%an",
|
|
"total_commits": total,
|
|
"authors": len(rows),
|
|
"rows": [{"author": a, "commits": c} for a, c in rows],
|
|
},
|
|
fh,
|
|
indent=2,
|
|
)
|
|
fh.write("\n")
|
|
|
|
with open("commits-by-author.md", "w", encoding="utf-8") as fh:
|
|
fh.write(
|
|
"# Commit-author census\n\nLive extract of commit authorship from the repository at\nrevision `9aba6df` (HEAD), generated 2026-10-29 17:00Z (UTC).\n\n| rank | author | commits |\n|---|---|---|\n"
|
|
)
|
|
for i, (author, commits) in enumerate(rows, 1):
|
|
fh.write(f"| {i} | {author} | {commits} |\n")
|
|
fh.write(f"\nTotal commits: {total} | authors: {len(rows)}\n")
|
|
|
|
print("total_commits:", total)
|
|
print("authors:", len(rows))
|