Refactor contributor extraction logic

We can now also generate a rst file which we can use in the documentation repo
This commit is contained in:
Roland Geider
2026-05-13 19:14:12 +02:00
parent 25bf2156d3
commit 9a682b8881
3 changed files with 282 additions and 137 deletions

1
.gitignore vendored
View File

@@ -86,6 +86,7 @@ venv-wger
/extras/docker/open-food-facts/dump/off/*
/extras/authors/commits_cache/
/extras/authors/*-AUTHORS.md
/extras/authors/*.rst
/extras/scripts/*.json
/extras/open-food-facts/dump/
/.claude/

View File

@@ -2,7 +2,7 @@
Thank you all for contributing to the project, you are true heroes! 🫶
*Generated on 2026-04-10*
*Generated on 2026-05-13*
---
@@ -10,29 +10,31 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Roland Geider - [https://github.com/rolandgeider](https://github.com/rolandgeider)
- Github-actions - [https://github.com/invalid-email-address](https://github.com/invalid-email-address)
- bigjimmy333 - [https://github.com/BigJimmy333](https://github.com/BigJimmy333)
- pankaj-basnet - [https://github.com/pankaj-basnet](https://github.com/pankaj-basnet)
- Luca van der Wijngaart - [https://github.com/lvdwijngaart](https://github.com/lvdwijngaart)
- kiranannadatha8 - [https://github.com/kiranannadatha8](https://github.com/kiranannadatha8)
- Luca van der Wijngaart - [https://github.com/lvdwijngaart](https://github.com/lvdwijngaart)
- OTijmen - [https://github.com/OTijmen](https://github.com/OTijmen)
- betterrrrr - [https://github.com/betterrrrr](https://github.com/betterrrrr)
- Sarthak - [https://github.com/sg172003](https://github.com/sg172003)
- Imad Rahhali - [https://github.com/ImadRahhali](https://github.com/ImadRahhali)
- MadoctheHadoc - [https://github.com/MadoctheHadoc](https://github.com/MadoctheHadoc)
- Ilya - [https://github.com/Really-Fun](https://github.com/Really-Fun)
- shihab - [https://github.com/shihabhasan0161](https://github.com/shihabhasan0161)
- infektyd - [https://github.com/infektyd](https://github.com/infektyd)
- Sam Tucker-Davis - [https://github.com/stuckvgn](https://github.com/stuckvgn)
- Sam Tucker-Davis - [https://github.com/samtuckerdavis](https://github.com/samtuckerdavis)
- Stavros Kois - [https://github.com/stavros-k](https://github.com/stavros-k)
- AlexisBirling3
- Sam - [https://github.com/stuckvgn](https://github.com/stuckvgn)
- stuckvgn - [https://github.com/stuckvgn](https://github.com/stuckvgn)
- stuckvgn
- Francisco - [https://github.com/franchsli](https://github.com/franchsli)
- cryptbrn - [https://github.com/cryptbrn](https://github.com/cryptbrn)
- ndimoro - [https://github.com/ndimoro](https://github.com/ndimoro)
- yontank - [https://github.com/yontank](https://github.com/yontank)
- Justin - [https://github.com/justin-pinheiro](https://github.com/justin-pinheiro)
- Justin Pinheiro - [https://github.com/justin-pinheiro](https://github.com/justin-pinheiro)
- Mannai
- Frenzy-code - [https://github.com/Frenzy-code](https://github.com/Frenzy-code)
- tbouri - [https://github.com/tbouri](https://github.com/tbouri)
- HairyCrabW - [https://github.com/HairyCrabW](https://github.com/HairyCrabW)
- HairyCrabW - [https://github.com/hangyiw](https://github.com/hangyiw)
- Jeremy - [https://github.com/zru-1](https://github.com/zru-1)
- Yousef - [https://github.com/yza-cmu](https://github.com/yza-cmu)
- Chidinma Obiekwe - [https://github.com/DidiNDexter](https://github.com/DidiNDexter)
@@ -53,27 +55,20 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Cam Cecil - [https://github.com/scrapcode](https://github.com/scrapcode)
- Ali Rahbar - [https://github.com/crypto-a](https://github.com/crypto-a)
- Joshua Shelley - [https://github.com/navyjosh](https://github.com/navyjosh)
- Joshua - [https://github.com/navyjosh](https://github.com/navyjosh)
- Ali Rahbar - [https://github.com/crypto-a](https://github.com/crypto-a)
- eyjhb - [https://github.com/eyJhb](https://github.com/eyJhb)
- Matthew Harrison - [https://github.com/Maralai](https://github.com/Maralai)
- Josh - [https://github.com/FlyingNimbusCloud](https://github.com/FlyingNimbusCloud)
- kmoy1 - [https://github.com/kmoy1](https://github.com/kmoy1)
- Kevin Moy - [https://github.com/kmoy1](https://github.com/kmoy1)
- Victor B
- Taylor Fuller - [https://github.com/taylor-hileman](https://github.com/taylor-hileman)
- JLaField - [https://github.com/JLaField](https://github.com/JLaField)
- JLaField - [https://github.com/JLaField](https://github.com/JLaField)
- bbk - [https://github.com/bbkz](https://github.com/bbkz)
- Maniues - [https://github.com/Maniues](https://github.com/Maniues)
- <ebwinters [at] comcast.net> - [https://github.com/ebwinters](https://github.com/ebwinters)
- ebwinters [at] comcast.net - [https://github.com/ebwinters](https://github.com/ebwinters)
- Roelof Rietbroek - [https://github.com/strawpants](https://github.com/strawpants)
- bbkz - [https://github.com/bbkz](https://github.com/bbkz)
- Jayanth Bontha - [https://github.com/JayanthBontha](https://github.com/JayanthBontha)
- JayanthBontha - [https://github.com/JayanthBontha](https://github.com/JayanthBontha)
- Brandon-Lu737 - [https://github.com/Brandon-z-lu](https://github.com/Brandon-z-lu)
- Ben Southcott - [https://github.com/blsouthcott](https://github.com/blsouthcott)
- Ben Southcott - [https://github.com/blsouthcott](https://github.com/blsouthcott)
- bingyingchu - [https://github.com/bingyingchu](https://github.com/bingyingchu)
- Alexandra Rhodes - [https://github.com/arhodes130](https://github.com/arhodes130)
- koenb - [https://github.com/berniekoen](https://github.com/berniekoen)
@@ -83,7 +78,6 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Rohan Karan - [https://github.com/RohanKaran](https://github.com/RohanKaran)
- Adam Petík - [https://github.com/AdamPetik](https://github.com/AdamPetik)
- Tom Bowyer - [https://github.com/ImTheTom](https://github.com/ImTheTom)
- Tom Bowyer - [https://github.com/ImTheTom](https://github.com/ImTheTom)
- Ingo Terpelle
- olijzenga - [https://github.com/olijzenga](https://github.com/olijzenga)
- kade - [https://github.com/kp5431](https://github.com/kp5431)
@@ -100,7 +94,6 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- grkm - [https://github.com/gorkemarslan](https://github.com/gorkemarslan)
- Oğuz Ersen
- Ayush Kumar - [https://github.com/Gr8ayu](https://github.com/Gr8ayu)
- Ayush Kumar - [https://github.com/Gr8ayu](https://github.com/Gr8ayu)
- J. Lavoie
- Allan Nordhøy - [https://github.com/comradekingu](https://github.com/comradekingu)
- Leninux - [https://github.com/RedRudeBoy](https://github.com/RedRudeBoy)
@@ -119,11 +112,9 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Aaron Kimbrell - [https://github.com/aronwk-aaron](https://github.com/aronwk-aaron)
- Lydia Xing - [https://github.com/lydiaxing](https://github.com/lydiaxing)
- nikithamurikinati - [https://github.com/nikithamurikinati](https://github.com/nikithamurikinati)
- nikithamurikinati - [https://github.com/nikithamurikinati](https://github.com/nikithamurikinati)
- Noah Pinter - [https://github.com/nopinter](https://github.com/nopinter)
- Harlene Samra - [https://github.com/harlenesamra](https://github.com/harlenesamra)
- Noah Pinter - [https://github.com/nopinter](https://github.com/nopinter)
- <justinec [at] unix.andrew.cmu.edu> - [https://github.com/jcho17](https://github.com/jcho17)
- justinec [at] unix.andrew.cmu.edu - [https://github.com/jcho17](https://github.com/jcho17)
- derekli - [https://github.com/derekli17](https://github.com/derekli17)
- Austin Leung - [https://github.com/austin-leung](https://github.com/austin-leung)
- ryowright - [https://github.com/ryowright](https://github.com/ryowright)
@@ -147,7 +138,6 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Veltarn - [https://github.com/Veltarn](https://github.com/Veltarn)
- Anjalie Kini
- gmmoraes - [https://github.com/Zutzsa](https://github.com/Zutzsa)
- Peter van der Does - [https://github.com/petervanderdoes](https://github.com/petervanderdoes)
- Daniel Topal - [https://github.com/dtopal](https://github.com/dtopal)
- Mbarak Mbigo - [https://github.com/Mbarak-Mbigo](https://github.com/Mbarak-Mbigo)
- alois
@@ -156,7 +146,6 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Boniface Mwenda
- Malcolm Jones - [https://github.com/DeveloperMal](https://github.com/DeveloperMal)
- Jacob Stoebel
- Roland Geider
- alelevinas
- ywecur - [https://github.com/ywecur](https://github.com/ywecur)
- Verdi R-D - [https://github.com/azend](https://github.com/azend)
@@ -171,18 +160,15 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Yuyu Aung - [https://github.com/yuyu-aung](https://github.com/yuyu-aung)
- matheus - [https://github.com/marchiore](https://github.com/marchiore)
- Tushar Gupta - [https://github.com/Tushar-Gupta](https://github.com/Tushar-Gupta)
- Tushar Gupta - [https://github.com/Tushar-Gupta](https://github.com/Tushar-Gupta)
- Helen Sherwood-Taylor - [https://github.com/helenst](https://github.com/helenst)
- Sean Hussey - [https://github.com/seanhussey](https://github.com/seanhussey)
- Roland Geider
- dashdrum - [https://github.com/dashdrum](https://github.com/dashdrum)
- Roland Geider
## Translators
### Arabic (Saudi Arabia)
- E. Ta.
- E. Ta. - [https://github.com/j-neko](https://github.com/j-neko)
- MR - [https://github.com/MyaserAL-Healy](https://github.com/MyaserAL-Healy)
- SlyBat - [https://github.com/AW-G](https://github.com/AW-G)
- Hissabat Manager - [https://github.com/Chinguetti-Quizz](https://github.com/Chinguetti-Quizz)
@@ -224,8 +210,8 @@ Thank you all for contributing to the project, you are true heroes! 🫶
### Czech
- greeenos - [https://github.com/greeenos](https://github.com/greeenos)
- Fjuro - [https://github.com/Fjuro](https://github.com/Fjuro)
- Fjuro
- CaptainDolphy - [https://github.com/CaptainDolphy](https://github.com/CaptainDolphy)
- Roman Kalivoda - [https://github.com/RKCZ](https://github.com/RKCZ)
- Zrnek - [https://github.com/TomasZmek](https://github.com/TomasZmek)
@@ -263,6 +249,7 @@ Thank you all for contributing to the project, you are true heroes! 🫶
### French
- Laurent Rousseau
- Thomas Peyrot - [https://github.com/Thomas-PEYROT](https://github.com/Thomas-PEYROT)
- Justin Pinheiro - [https://github.com/justin-pinheiro](https://github.com/justin-pinheiro)
- Paul Bonneau - [https://github.com/paulbonneau](https://github.com/paulbonneau)
@@ -279,10 +266,12 @@ Thank you all for contributing to the project, you are true heroes! 🫶
### German
- Roland Geider - [https://github.com/rolandgeider](https://github.com/rolandgeider)
- Hosted Weblate user 150360
- Emil
- Elias Lang - [https://github.com/elias170105](https://github.com/elias170105)
- Traladarer
- Richard Mrosk - [https://github.com/EtheriousNight](https://github.com/EtheriousNight)
- Roland Geider - [https://github.com/rolandgeider](https://github.com/rolandgeider)
- kvnrmnn - [https://github.com/rmnn92](https://github.com/rmnn92)
- Tobias Lechner - [https://github.com/Lxchnxr](https://github.com/Lxchnxr)
- becothas - [https://github.com/becothas](https://github.com/becothas)
@@ -383,10 +372,10 @@ Thank you all for contributing to the project, you are true heroes! 🫶
### Portuguese
- Edson Wolf - [https://github.com/edsonblwolf](https://github.com/edsonblwolf)
- Ninguém Mesmo
- Edson Wolf - [https://github.com/edsonblwolf](https://github.com/edsonblwolf)
- Luiz Felipe Guidorizzi de Oliveira - [https://github.com/EvilMonark](https://github.com/EvilMonark)
- Wilton Rodrigues
- Wilton Rodrigues - [https://github.com/FinTech-crypto](https://github.com/FinTech-crypto)
- Guilherme Salomão - [https://github.com/salomaoparkour](https://github.com/salomaoparkour)
- Douglas Gabriel Ochner - [https://github.com/dochner](https://github.com/dochner)
- Guilherme G. Schardong - [https://github.com/schardong](https://github.com/schardong)
@@ -462,17 +451,12 @@ Thank you all for contributing to the project, you are true heroes! 🫶
- Oğuz Ersen - [https://github.com/oersen](https://github.com/oersen)
- Cem Avcı - [https://github.com/cem256](https://github.com/cem256)
- Oğuz Ersen
- Allan Nordhøy - [https://github.com/comradekingu](https://github.com/comradekingu)
### Ukrainian
- Максим Горпиніч
- Максим Горпиніч - [https://github.com/Maksim2005UA](https://github.com/Maksim2005UA)
- Максим Горпиніч
- Максим Горпиніч
- kvinto - [https://github.com/badsystem](https://github.com/badsystem)
- Dan - [https://github.com/Kefir2105](https://github.com/Kefir2105)
- Dan
- Tymofii Lytvynenko
- Artem - [https://github.com/defaultpage](https://github.com/defaultpage)

View File

@@ -4,6 +4,7 @@ import json
import os
import re
import shutil
from dataclasses import dataclass
from getpass import getpass
from pathlib import Path
@@ -16,15 +17,45 @@ import requests
# ]
# ///
# Run with "uv run generate_authors_api.py"
# Run with "uv run generate_authors_api.py". To generate a token, go to https://github.com/settings/tokens
ORGANIZATION = 'wger-project'
REPOSITORIES = ['wger', 'flutter', 'react', 'docker', 'docs']
COMMITS_PER_PAGE = 100
CACHE_DIR = Path('commits_cache')
# Commit authors whose contributions we don't credit (matched as substrings).
BOT_AUTHORS = ('dependabot', 'github-actions')
def get_github_token():
@dataclass
class Person:
"""A contributor or translator, normalized from GitHub commit data."""
name: str
email: str
username: str = ''
"""GitHub login, empty when the email isn't linked to a GitHub account"""
def __post_init__(self):
# Some commits have a raw email address in the author "name" field.
if '@' in self.name:
self.name = self.name.replace('@', ' [at] ')
@property
def github_url(self) -> str:
"""GitHub profile URL if the person has a linked account, empty otherwise."""
return f'https://github.com/{self.username}' if self.username else ''
@property
def identity_key(self) -> tuple[str, str]:
"""Stable key for cross-repo deduplication: by username when known, else email."""
return ('user', self.username) if self.username else ('email', self.email)
def get_github_token() -> str:
token = os.getenv('GITHUB_TOKEN')
if not token:
token = getpass('Enter your GitHub token: ')
@@ -32,133 +63,179 @@ def get_github_token():
return token
def fetch_commits_from_github(repo_name, github_token):
def fetch_commits_from_github(repo_name: str, token: str) -> list[dict]:
"""Fetch commits with an incremental, append-only cache.
On first run, paginates the whole history and caches each API response.
On later runs, reads the latest cached commit's date and uses GitHub's
``since`` query parameter to fetch only commits newer than that.
"""
repo_cache_dir = CACHE_DIR / repo_name
repo_cache_dir.mkdir(parents=True, exist_ok=True)
# Load any cached commits from previous runs
cached_pages = sorted(
repo_cache_dir.glob('page_*.json'),
key=lambda p: int(p.stem.split('_')[1]),
)
cached_commits: list[dict] = []
for cache_file in cached_pages:
with open(cache_file) as f:
cached_commits.extend(json.load(f))
# If we have a cache, only request commits newer than the latest one
since_param = None
if cached_commits:
latest_iso = max(c['commit']['author']['date'] for c in cached_commits)
# +1s so the boundary commit isn't returned again (GitHub's `since` is inclusive)
cutoff = datetime.datetime.fromisoformat(
latest_iso.replace('Z', '+00:00')
) + datetime.timedelta(seconds=1)
since_param = cutoff.strftime('%Y-%m-%dT%H:%M:%SZ')
print(f'Cache: {len(cached_commits)} commits loaded, fetching anything since {since_param}')
url = f'https://api.github.com/repos/{ORGANIZATION}/{repo_name}/commits'
headers = {'Authorization': f'token {github_token}'} if github_token else {}
commits = []
# Get total commit count
try:
response = requests.get(url, headers=headers, params={'per_page': COMMITS_PER_PAGE})
response.raise_for_status()
link_header = response.headers.get('Link')
if link_header:
links = link_header.split(', ')
for link in links:
if 'rel="last"' in link:
match = re.search(r'[?&]page=(\d+)', link)
if match:
total_pages = int(match.group(1))
break
else:
total_pages = 1 # if the last page is not found, assume one page.
else:
total_pages = 1
except requests.exceptions.RequestException as e:
print(f'Error getting total commits: {e}')
return []
# print(f"Total pages: {total_pages}")
for page in range(1, total_pages + 1):
# page += 1
cache_file = repo_cache_dir / f'page_{page}.json'
if cache_file.exists():
with open(cache_file, 'r') as f:
data = json.load(f)
commits.extend(data)
print(f'Loaded cached page {page}')
continue
headers = {'Authorization': f'token {token}'} if token else {}
base_params: dict = {'per_page': COMMITS_PER_PAGE}
if since_param:
base_params['since'] = since_param
# Paginate until we run out of results
new_commits: list[dict] = []
page = 1
while True:
try:
response = requests.get(
url, headers=headers, params={'page': page, 'per_page': COMMITS_PER_PAGE}
)
response = requests.get(url, headers=headers, params={**base_params, 'page': page})
response.raise_for_status()
data = response.json()
if not data:
break
print(f'Fetching commits from API for page {page}')
with open(cache_file, 'w') as f:
json.dump(data, f, indent=4)
commits.extend(data)
except requests.exceptions.RequestException as e:
print(f'Error fetching commits: {e}')
return cached_commits # still return what we have
if not data:
break
new_commits.extend(data)
print(f'Fetched page {page} ({len(data)} commits)')
if len(data) < COMMITS_PER_PAGE:
break
page += 1
return commits
# Append the new commits as additional cache files (oldest pages keep their numbers)
if new_commits:
next_seq = len(cached_pages) + 1
for i in range(0, len(new_commits), COMMITS_PER_PAGE):
chunk = new_commits[i : i + COMMITS_PER_PAGE]
with open(repo_cache_dir / f'page_{next_seq}.json', 'w') as f:
json.dump(chunk, f, indent=4)
next_seq += 1
print(f'Cached {len(new_commits)} new commits')
return cached_commits + new_commits
def extract_contributors(repo_name, github_token):
"""Retrieves contributors and translators from the GitHub API."""
def extract_contributors(
repo_name: str, token: str
) -> tuple[list[Person], dict[str, list[Person]]]:
"""Retrieves contributors and translators from the GitHub API.
contributors = {}
translators = {}
Returns a flat list of contributors and a dict of language -> translators.
Both are pre-deduplicated within the repo by author email.
"""
commits = fetch_commits_from_github(repo_name, github_token)
# Use dicts keyed by email for per-repo pre-dedupe, then return as lists
# so callers don't depend on the internal key.
contributors: dict[str, Person] = {}
translators: dict[str, dict[str, Person]] = {}
for commit in commits:
for commit in fetch_commits_from_github(repo_name, token):
commit_message = commit['commit']['message']
# Author is null if the commit was done by weblate and the translator is not a GitHub user
author = commit.get('author', {})
author_username = author.get('login', '') if author else ''
author_name = commit['commit']['author']['name']
author_email = commit['commit']['author']['email']
# commit['author'] (the GitHub user) is null when the committer isn't
# linked to a GitHub account. The inner commit.author fields always
# carry the raw git name/email from the commit object.
github_author = commit.get('author', {})
username = github_author.get('login', '') if github_author else ''
name = commit['commit']['author']['name']
email = commit['commit']['author']['email']
if 'dependabot' in author_name:
if any(bot in name for bot in BOT_AUTHORS):
continue
if 'github-actions' in author_name:
continue
# Weblate's bot account commits on behalf of the actual translator —
# linking to the bot's GitHub profile would be misleading.
if username == 'weblate':
username = ''
if '@' in author_name:
author_name = f'<{author_name.replace("@", " [at] ")}>'
person = Person(name=name, email=email, username=username)
if 'Translated using Weblate' in commit_message:
language_match = re.search(r'Translated using Weblate \((.+)\)', commit_message)
if language_match:
language = language_match.group(1)
if language not in translators:
translators[language] = {}
translators[language][author_email] = {
'email': author_email,
'name': author_name,
'username': author_username,
}
language_match = re.search(r'Translated using Weblate \((.+)\)', commit_message)
if language_match:
language = language_match.group(1)
translators.setdefault(language, {})[email] = person
else:
contributors[author_email] = {
'email': author_email,
'username': author_username,
'name': author_name,
}
return contributors, translators
contributors[email] = person
return (
list(contributors.values()),
{lang: list(people.values()) for lang, people in translators.items()},
)
def generate_markdown(data: dict) -> str | None:
"""Generate the markdown for a single contributor or translator."""
def deduplicate(people: list[Person]) -> list[Person]:
"""
Merge entries that refer to the same person.
profile = f'https://github.com/{data.get("username", "")}'
entry = f'{data["name"]} - [{profile}]({profile})' if data['username'] else data['name']
Pass 1: same GitHub username (or same email when no username) → one entry,
preferring the one with a username.
if entry == '':
Pass 2: drop no-username entries whose name matches a known username entry.
Catches the case where the same person committed from both their
GitHub-linked email *and* an unlinked one.
Trade-off: two distinct contributors with identical names but different
link states will collapse into one; with diverse real names this should be
rare in practice.
"""
# Pass 1: identity-based dedupe (username when available, else email)
seen: dict[tuple[str, str], Person] = {}
for p in people:
key = p.identity_key
if key not in seen or (p.username and not seen[key].username):
seen[key] = p
# Pass 2: collapse no-username entries onto same-named username entries
named = {p.name.lower() for p in seen.values() if p.username}
return [p for p in seen.values() if p.username or p.name.lower() not in named]
def generate_markdown(p: Person) -> str | None:
"""Generate a single markdown bullet for a contributor or translator."""
if not p.name:
return None
if p.username:
return f'- {p.name} - [{p.github_url}]({p.github_url})\n'
return f'- {p.name}\n'
return f'- {entry}\n'
def generate_rst_entry(p: Person) -> str | None:
"""Generate a single RST bullet for a contributor or translator."""
if not p.name:
return None
if p.username:
return f'* {p.name} — {p.github_url}\n'
return f'* {p.name}\n'
def generate_authors_file(
repo_name, contributors: dict, translators: dict, output_file='AUTHORS.md'
repo_name: str,
contributors: list[Person],
translators: dict[str, list[Person]],
output_file: str = 'AUTHORS.md',
):
"""Generates a Markdown file with contributors and translators."""
"""Generates a Markdown file with contributors and translators for one repo."""
filename = f'{repo_name}-{output_file}'
with open(filename, 'w') as f:
@@ -169,8 +246,8 @@ def generate_authors_file(
f.write('## Contributors\n\n')
if contributors:
for author_email, data in contributors.items():
entry = generate_markdown(data)
for p in deduplicate(contributors):
entry = generate_markdown(p)
if entry:
f.write(entry)
else:
@@ -178,11 +255,11 @@ def generate_authors_file(
f.write('\n## Translators\n')
if translators:
for language, translator_data in sorted(translators.items()):
for language, people in sorted(translators.items()):
f.write('\n')
f.write(f'### {language}\n\n')
for author_email, data in translator_data.items():
entry = generate_markdown(data)
for p in deduplicate(people):
entry = generate_markdown(p)
if entry:
f.write(entry)
else:
@@ -191,34 +268,117 @@ def generate_authors_file(
print(f'{filename} generated successfully.')
def generate_contributors_rst(contributors: list[Person], output_file: str = 'contributors.rst'):
"""Cross-repo, deduplicated contributors list as RST (for the docs site)."""
sorted_entries = sorted(deduplicate(contributors), key=lambda p: p.name.lower())
with open(output_file, 'w') as f:
f.write(':orphan:\n\n')
f.write('.. _contributors:\n\n')
f.write('Contributors\n')
f.write('============\n\n')
f.write(f'*Generated on {datetime.date.today()}*\n\n')
f.write(
'Aggregated code contributors across all wger repositories '
'(server, react frontend, flutter mobile app, docker, docs).\n'
'Thank you all for contributing to the project, you are true heroes! 🫶\n\n'
)
for p in sorted_entries:
entry = generate_rst_entry(p)
if entry:
f.write(entry)
print(f'{output_file} generated successfully.')
def generate_translators_rst(
translators: dict[str, list[Person]],
output_file: str = 'translators.rst'
):
"""Cross-repo, deduplicated translators list as RST, grouped by language."""
with open(output_file, 'w') as f:
f.write(':orphan:\n\n')
f.write('.. _translators:\n\n')
f.write('Translators\n')
f.write('===========\n\n')
f.write(f'*Generated on {datetime.date.today()}*\n\n')
f.write(
'Thanks to everyone who has helped translate wger into other languages. '
'Contributions are made via `Weblate <https://hosted.weblate.org/engage/wger>`_ '
'and are collected here from all wger repositories.\n\n'
)
for language in sorted(translators.keys()):
f.write(f'{language}\n')
f.write('-' * len(language) + '\n\n')
sorted_people = sorted(
deduplicate(translators[language]), key=lambda p: p.name.lower()
)
for p in sorted_people:
entry = generate_rst_entry(p)
if entry:
f.write(entry)
f.write('\n')
print(f'{output_file} generated successfully.')
if __name__ == '__main__':
github_token = get_github_token()
all_contributors: list[Person] = []
all_translators: dict[str, list[Person]] = {}
for repo in REPOSITORIES:
print(f'*** Processing {repo} ***')
generate_authors_file(repo, *extract_contributors(repo, github_token))
print(f'')
contributors, translators = extract_contributors(repo, github_token)
generate_authors_file(repo, contributors, translators)
all_contributors.extend(contributors)
for lang, people in translators.items():
all_translators.setdefault(lang, []).extend(people)
print()
generate_contributors_rst(all_contributors)
generate_translators_rst(all_translators)
print('Done! 🥳')
print('')
print('This script can copy the generated AUTHORS.md files to their correct locations.')
print('This script can copy the generated files to their correct locations.')
print('- wger-AUTHORS.md -> ../../AUTHORS.md')
print('- <repo>-AUTHORS.md -> ../../../<repo>/AUTHORS.md')
print('- contributors.rst, translators.rst -> ../../../docs/docs/')
copy_files = input('Copy files? (yes/no): ').strip().lower()
if copy_files == 'yes':
print('Copying files...')
# Copy markdown files
shutil.copy('wger-AUTHORS.md', '../../AUTHORS.md')
print('Copied wger-AUTHORS.md to ../../AUTHORS.md')
for repo in REPOSITORIES:
#This repo
if repo == 'wger':
continue
# The other ones
try:
shutil.copy(f'{repo}-AUTHORS.md', f'../../../{repo}/AUTHORS.md')
print(f'Copied {repo}-AUTHORS.md to ../../../{repo}/AUTHORS.md')
except FileNotFoundError as e:
print(f'Error copying {repo}-AUTHORS.md: {e}')
# Copy rst files
for rst_file in ('contributors.rst', 'translators.rst'):
try:
shutil.copy(rst_file, f'../../../docs/docs/{rst_file}')
print(f'Copied {rst_file} to ../../../docs/docs/{rst_file}')
except FileNotFoundError as e:
print(f'Error copying {rst_file}: {e}')
print('Files copied successfully.')
else:
print('Files were not copied.')