forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontributors.py
50 lines (38 loc) · 1.33 KB
/
contributors.py
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
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import annotations
import argparse
import subprocess
from pathlib import Path
def create_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Generate contributor list")
parser.add_argument(
"-s", "--since", help="Contributors since this revision, e.g. the Git tag `release_2.8.0`"
)
return parser
def main() -> None:
args = create_parser().parse_args()
if args.since:
print(" " + "\n ".join(sorted_contributors(range=f"{args.since}..HEAD")))
else:
update_contributors_md()
def sorted_contributors(range: str) -> list[str]:
contributors = set(
subprocess.run(
["git", "log", "--use-mailmap", "--format=format:%aN", range],
stdout=subprocess.PIPE,
check=True,
)
.stdout.decode()
.splitlines()
)
contributors -= {"dependabot[bot]"}
return sorted(contributors)
def update_contributors_md() -> None:
Path("CONTRIBUTORS.md").write_text(
"Created by running `./pants run build-support/bin/contributors.py`.\n\n+ "
+ "\n+ ".join(sorted_contributors(range="HEAD"))
+ "\n"
)
if __name__ == "__main__":
main()