File: update-authors

package info (click to toggle)
ccache 4.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 5,192 kB
  • sloc: cpp: 47,336; asm: 28,570; sh: 8,709; ansic: 5,357; python: 685; perl: 68; makefile: 23
file content (69 lines) | stat: -rwxr-xr-x 1,564 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3

"""Update doc/AUTHORS.adoc with Git commit authors.

Authors include those specified by "Co-authored-by:" in commit messages.
"""

import re
from functools import cmp_to_key
from locale import LC_ALL, setlocale, strcoll
from pathlib import Path
from subprocess import run

ANONYMOUS = {
    "6d5CfLQ3dYAb",
    "bengtj",
    "cupu",
    "DarkShadow44",
    "Delgan",
    "Doekin",
    "DS",
    "dsilakov",
    "dsrowell",
    "gitmodimo",
    "kingiler",
    "Kreijstal",
    "kzlar",
    "luzpaz",
    "Mikhail B",
    "Moritz",
    "R43Qi8krC",
    "rblx-kbuck",
    "RW",
    "senhtry",
    "vsplesk",
}

AUTHORS_ADOC = Path(__file__).parents[1] / "doc/AUTHORS.adoc"


def git(*args):
    return run(["git", *args], capture_output=True, check=True, text=True).stdout


def main():
    setlocale(LC_ALL, "en_US.utf8")

    primary_authors = set(git("log", "--format=%aN").splitlines())

    git_log = git("log", "--format=%b")
    co_authors = set(re.findall(r"Co-authored-by: ([^<]+) <.*", git_log))

    authors = (primary_authors | co_authors) - ANONYMOUS

    authors_lines = AUTHORS_ADOC.read_text().splitlines()
    with AUTHORS_ADOC.open("w") as f:
        in_list = False
        for line in authors_lines:
            if line.startswith("* "):
                in_list = True
            else:
                if in_list:
                    for author in sorted(authors, key=cmp_to_key(strcoll)):
                        f.write(f"* {author}\n")
                    in_list = False
                f.write(f"{line}\n")


main()