@@ -9,7 +9,7 @@ from collections import defaultdict
9
9
from pathlib import Path
10
10
from typing import Literal
11
11
12
- from git import Repo
12
+ from git import Commit , Repo
13
13
from git .diff import Diff
14
14
15
15
import weblate .utils .version
@@ -19,11 +19,14 @@ ROOT_DIR = Path(__file__).parent.parent
19
19
20
20
CategoryType = Literal ["code" , "translations" , "docs" ]
21
21
22
+ IGNORE_AUTHORS : set [str ] = {"GitHub" , "Anonymous" , "Hosted Weblate" }
23
+
22
24
CATEGORIES : dict [CategoryType , str ] = {
23
25
"code" : "Code contributions" ,
24
26
"translations" : "Translations contributions" ,
25
27
"docs" : "Documentation contributions" ,
26
28
}
29
+
27
30
TEMPLATE = """
28
31
{label}
29
32
.. only:: not gettext
@@ -50,6 +53,27 @@ def get_diff_categories(diff: list[Diff]) -> set[CategoryType]:
50
53
return categories
51
54
52
55
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
+
53
77
def get_contributors () -> dict [CategoryType , list [str ]]:
54
78
contributors : dict [CategoryType , list [str ]] = defaultdict (list )
55
79
repo = Repo .init (ROOT_DIR )
@@ -58,17 +82,13 @@ def get_contributors() -> dict[CategoryType, list[str]]:
58
82
commits = list (repo .iter_commits (f"{ recent_tag } ..HEAD" ))
59
83
previous = recent_tag .object .object
60
84
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 :
68
87
diff = previous .diff (commit .tree )
69
88
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 )
72
92
previous = commit .tree
73
93
return contributors
74
94
0 commit comments