File: update-authors.py

package info (click to toggle)
golang-github-ncw-swift-v2 2.0.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 456 kB
  • sloc: sh: 61; python: 30; makefile: 4
file content (47 lines) | stat: -rwxr-xr-x 1,195 bytes parent folder | download
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
#!/usr/bin/env python3
"""
Update the README.md file with the authors from the git log
"""

import re
import subprocess

AUTHORS = "README.md"
IGNORE = [ "nick@raig-wood.com" ]

def load():
    """
    returns a set of emails already in authors
    """
    with open(AUTHORS) as fd:
        authors = fd.read()
    emails = set(re.findall(r"<(?!!--)(.*?)>", authors))
    emails.update(IGNORE)
    return emails

def add_email(name, email):
    """
    adds the email passed in to the end of authors
    """
    print("Adding %s <%s>" % (name, email))
    with open(AUTHORS, "a+") as fd:
        print("- %s <%s>" % (name, email), file=fd)
    subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS])
    
def main():
    out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"])

    previous = load()
    for line in out.split(b"\n"):
        line = line.decode("utf-8")
        line = line.strip()
        if line == "":
            continue
        name, email = line.split("|")
        if email in previous:
            continue
        previous.add(email)
        add_email(name, email)

if __name__ == "__main__":
    main()