tools-python icon indicating copy to clipboard operation
tools-python copied to clipboard

added an authors file

Open SKalt opened this issue 5 years ago • 0 comments

Adressesses #113. Authors are added in order of the number of commits contributed from most to least, with recency breaking ties. I used each contributor's most recent email address.

Code used to generate authors list
from subprocess import run, PIPE
from collections import Counter, OrderedDict


def get_authors():
    return run(
        "git log --use-mailmap --format=format:'%aN#<%aE>'".split(" "),
        stdout=PIPE,
    ).stdout.decode()


def get_authors_list():
    return [auth.split("#") for auth in get_authors().split("\n")]


def by_recency(authors):
    order = OrderedDict()
    for name, email in authors:
        result = order.get(name, [])
        result.append(email)
        order[name] = result
    return "\n".join([f"{i} {order[i][0]}" for i in order])


def by_commit_count(authors):
    count = Counter()
    name_emails = {}
    for name, email in authors:
        count[name] += 1
        if name not in name_emails:
            name_emails[name] = email
    by_count = [*count.items()]
    by_count.sort(key=lambda x: x[1])
    by_count = by_count[::-1]
    return "\n".join(
        " ".join((name, name_emails[name])) for name, count in by_count
    )


if __name__ == "__main__":
    with open("AUTHORS", "w") as target:
        target.write(by_commit_count(get_authors_list()))

Signed-off-by: Steven Kalt [email protected]

SKalt avatar Oct 21 '19 19:10 SKalt