Skip to content

Commit 0de3380

Browse files
committed
feat(scripts): include co-authored-by in contributors
1 parent a88c880 commit 0de3380

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

scripts/list-contributors

+30-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from collections import defaultdict
99
from pathlib import Path
1010
from typing import Literal
1111

12-
from git import Repo
12+
from git import Commit, Repo
1313
from git.diff import Diff
1414

1515
import weblate.utils.version
@@ -19,11 +19,14 @@ ROOT_DIR = Path(__file__).parent.parent
1919

2020
CategoryType = Literal["code", "translations", "docs"]
2121

22+
IGNORE_AUTHORS: set[str] = {"GitHub", "Anonymous", "Hosted Weblate"}
23+
2224
CATEGORIES: dict[CategoryType, str] = {
2325
"code": "Code contributions",
2426
"translations": "Translations contributions",
2527
"docs": "Documentation contributions",
2628
}
29+
2730
TEMPLATE = """
2831
{label}
2932
.. only:: not gettext
@@ -50,6 +53,27 @@ def get_diff_categories(diff: list[Diff]) -> set[CategoryType]:
5053
return categories
5154

5255

56+
def is_valid_author(author: str) -> bool:
57+
return (
58+
"(bot)" not in author
59+
and "[bot]" not in author
60+
and "add-on" not in author
61+
and author not in IGNORE_AUTHORS
62+
)
63+
64+
65+
def get_commit_authors(commit: Commit) -> set[str]:
66+
authors: list[str] = [str(commit.author)]
67+
if commit.committer:
68+
authors.append(str(commit.committer))
69+
authors.extend(
70+
line[15:].split("<")[0].strip()
71+
for line in str(commit.message).splitlines()
72+
if line.lower().startswith("co-authored-by:")
73+
)
74+
return {author for author in authors if is_valid_author(author)}
75+
76+
5377
def get_contributors() -> dict[CategoryType, list[str]]:
5478
contributors: dict[CategoryType, list[str]] = defaultdict(list)
5579
repo = Repo.init(ROOT_DIR)
@@ -58,17 +82,13 @@ def get_contributors() -> dict[CategoryType, list[str]]:
5882
commits = list(repo.iter_commits(f"{recent_tag}..HEAD"))
5983
previous = recent_tag.object.object
6084
for commit in reversed(commits):
61-
author = str(commit.author)
62-
if (
63-
"(bot)" not in author
64-
and "[bot]" not in author
65-
and "add-on" not in author
66-
and author != "Anonymous"
67-
):
85+
authors = get_commit_authors(commit)
86+
if authors:
6887
diff = previous.diff(commit.tree)
6988
for category in get_diff_categories(diff):
70-
if author not in contributors[category]:
71-
contributors[category].append(author)
89+
for author in authors:
90+
if author not in contributors[category]:
91+
contributors[category].append(author)
7292
previous = commit.tree
7393
return contributors
7494

0 commit comments

Comments
 (0)