2019-09-07 05:08:48 +08:00
|
|
|
#!/usr/bin/env python3
|
2017-04-25 03:36:06 +08:00
|
|
|
"""
|
|
|
|
Update the authors.md file with the authors from the git log
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
AUTHORS = "docs/content/authors.md"
|
2020-05-05 00:38:25 +08:00
|
|
|
IGNORE = "bin/.ignore-emails"
|
2017-04-25 03:36:06 +08:00
|
|
|
|
2020-05-05 00:38:25 +08:00
|
|
|
def load(filename):
|
2017-04-25 03:36:06 +08:00
|
|
|
"""
|
2020-05-05 00:38:25 +08:00
|
|
|
returns a set of emails already in the file
|
2017-04-25 03:36:06 +08:00
|
|
|
"""
|
2020-05-05 00:38:25 +08:00
|
|
|
with open(filename) as fd:
|
2017-04-25 03:36:06 +08:00
|
|
|
authors = fd.read()
|
2020-05-05 00:38:25 +08:00
|
|
|
return set(re.findall(r"<(.*?)>", authors))
|
2017-04-25 03:36:06 +08:00
|
|
|
|
|
|
|
def add_email(name, email):
|
|
|
|
"""
|
|
|
|
adds the email passed in to the end of authors.md
|
|
|
|
"""
|
2019-09-07 05:08:48 +08:00
|
|
|
print("Adding %s <%s>" % (name, email))
|
2017-04-25 03:36:06 +08:00
|
|
|
with open(AUTHORS, "a+") as fd:
|
2019-09-07 05:08:48 +08:00
|
|
|
print(" * %s <%s>" % (name, email), file=fd)
|
2017-04-25 03:36:06 +08:00
|
|
|
subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS])
|
|
|
|
|
|
|
|
def main():
|
2023-11-17 00:55:48 +08:00
|
|
|
# Add emails from authors
|
2017-04-25 03:36:06 +08:00
|
|
|
out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"])
|
2019-09-07 05:08:48 +08:00
|
|
|
out = out.decode("utf-8")
|
2017-04-25 03:36:06 +08:00
|
|
|
|
2020-05-05 00:38:25 +08:00
|
|
|
ignored = load(IGNORE)
|
|
|
|
previous = load(AUTHORS)
|
|
|
|
previous.update(ignored)
|
2017-04-25 03:36:06 +08:00
|
|
|
for line in out.split("\n"):
|
|
|
|
line = line.strip()
|
|
|
|
if line == "":
|
|
|
|
continue
|
|
|
|
name, email = line.split("|")
|
|
|
|
if email in previous:
|
|
|
|
continue
|
|
|
|
previous.add(email)
|
|
|
|
add_email(name, email)
|
|
|
|
|
2023-11-17 00:55:48 +08:00
|
|
|
# Add emails from Co-authored-by: lines
|
|
|
|
out = subprocess.check_output(["git", "log", '-i', '--grep', 'Co-authored-by:', "master"])
|
|
|
|
out = out.decode("utf-8")
|
|
|
|
co_authored_by = re.compile(r"(?i)Co-authored-by:\s+(.*?)\s+<([^>]+)>$")
|
|
|
|
|
|
|
|
for line in out.split("\n"):
|
|
|
|
line = line.strip()
|
|
|
|
m = co_authored_by.search(line)
|
|
|
|
if not m:
|
|
|
|
continue
|
|
|
|
name, email = m.group(1), m.group(2)
|
|
|
|
name = name.strip()
|
|
|
|
email = email.strip()
|
|
|
|
if email in previous:
|
|
|
|
continue
|
|
|
|
previous.add(email)
|
|
|
|
add_email(name, email)
|
|
|
|
|
2017-04-25 03:36:06 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|