github.com/artpar/rclone@v1.67.3/bin/update-authors.py (about) 1 #!/usr/bin/env python3 2 """ 3 Update the authors.md file with the authors from the git log 4 """ 5 6 import re 7 import subprocess 8 9 AUTHORS = "docs/content/authors.md" 10 IGNORE = "bin/.ignore-emails" 11 12 def load(filename): 13 """ 14 returns a set of emails already in the file 15 """ 16 with open(filename) as fd: 17 authors = fd.read() 18 return set(re.findall(r"<(.*?)>", authors)) 19 20 def add_email(name, email): 21 """ 22 adds the email passed in to the end of authors.md 23 """ 24 print("Adding %s <%s>" % (name, email)) 25 with open(AUTHORS, "a+") as fd: 26 print(" * %s <%s>" % (name, email), file=fd) 27 subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS]) 28 29 def main(): 30 # Add emails from authors 31 out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"]) 32 out = out.decode("utf-8") 33 34 ignored = load(IGNORE) 35 previous = load(AUTHORS) 36 previous.update(ignored) 37 for line in out.split("\n"): 38 line = line.strip() 39 if line == "": 40 continue 41 name, email = line.split("|") 42 if email in previous: 43 continue 44 previous.add(email) 45 add_email(name, email) 46 47 # Add emails from Co-authored-by: lines 48 out = subprocess.check_output(["git", "log", '-i', '--grep', 'Co-authored-by:', "master"]) 49 out = out.decode("utf-8") 50 co_authored_by = re.compile(r"(?i)Co-authored-by:\s+(.*?)\s+<([^>]+)>$") 51 52 for line in out.split("\n"): 53 line = line.strip() 54 m = co_authored_by.search(line) 55 if not m: 56 continue 57 name, email = m.group(1), m.group(2) 58 name = name.strip() 59 email = email.strip() 60 if email in previous: 61 continue 62 previous.add(email) 63 add_email(name, email) 64 65 if __name__ == "__main__": 66 main()