-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-authors
More file actions
executable file
·75 lines (61 loc) · 1.87 KB
/
get-authors
File metadata and controls
executable file
·75 lines (61 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
This script browses through git commit history (starting at latest tag), collects all authors of
commits and creates fragment for `towncrier`_ tool.
It's meant to be run during the release process, before generating the release notes.
Example::
$ python get_authors.py
.. _towncrier: https://github.com/hawkowl/towncrier/
Authors:
Aurelien Bompard
Michal Konecny
"""
import os
from argparse import ArgumentParser
from collections import defaultdict
from subprocess import check_output
EXCLUDE = ["Weblate (bot)"]
last_tag = (
check_output(["git", "tag", "--sort=creatordate"], text=True)
.strip()
.split("\n")[-1]
)
args_parser = ArgumentParser()
args_parser.add_argument(
"until",
nargs="?",
default="HEAD",
help="Consider all commits until this one (default: %(default)s).",
)
args_parser.add_argument(
"since",
nargs="?",
default=last_tag,
help="Consider all commits since this one (default: %(default)s).",
)
args = args_parser.parse_args()
authors = {}
commit_counts = defaultdict(int)
log_range = args.since + ".." + args.until
print(f"Scanning commits in range {log_range}")
output = check_output(["git", "log", log_range, "--format=%ae\t%an"], text=True)
for line in output.splitlines():
email, fullname = line.split("\t")
email = email.split("@")[0].replace(".", "")
commit_counts[email] += 1
if email in authors:
continue
authors[email] = fullname
for nick, fullname in authors.items():
if fullname in EXCLUDE or fullname.endswith("[bot]"):
continue
filename = f"{nick}.author"
if os.path.exists(filename):
continue
commit_count = commit_counts[nick]
print(
f"Adding author {fullname} ({nick}, {commit_count} commit{'' if commit_count < 2 else 's'})"
)
with open(filename, "w") as f:
f.write(fullname)
f.write("\n")