forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_contributors.py
97 lines (84 loc) · 2.47 KB
/
get_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from github import Github
from subprocess import check_output
import shlex
from tqdm import tqdm
import click
from collections import defaultdict
@click.command()
@click.option(
"--access-token",
required=True,
help="""
Github Access token that has repo:public_repo and user:read:user permission.
Create them at https://github.com/settings/tokens/new
""",
)
@click.option(
"--prev-release-commit",
required=True,
help="Last commit SHA of the previous release.",
)
@click.option(
"--curr-release-commit",
required=True,
help="Last commit SHA of the current release.",
)
def run(access_token, prev_release_commit, curr_release_commit):
print("Writing commit descriptions to 'commits.txt'...")
check_output(
(
f"git log {prev_release_commit}..{curr_release_commit} "
f"--pretty=format:'%s' > commits.txt"
),
shell=True,
)
# Generate command
cmd = []
cmd.append(
(
f"git log {prev_release_commit}..{curr_release_commit} "
f'--pretty=format:"%s" '
f' | grep -Eo "#(\d+)"'
)
)
joined = " && ".join(cmd)
cmd = f"bash -c '{joined}'"
cmd = shlex.split(cmd)
print("Executing", cmd)
# Sort the PR numbers
pr_numbers = [int(line.lstrip("#")) for line in check_output(cmd).decode().split()]
print("PR numbers", pr_numbers)
# Use Github API to fetch the
g = Github(access_token)
ray_repo = g.get_repo("ray-project/ray")
logins = set()
for num in tqdm(pr_numbers):
try:
logins.add(ray_repo.get_pull(num).user.login)
except Exception as e:
print(e)
print()
print("Here's the list of contributors")
print("=" * 10)
print()
print("@" + ", @".join(logins))
print()
print("=" * 10)
# Organize commits
NO_CATEGORY = "[NO_CATEGORY]"
def get_category(line):
if line[0] == "[":
return (line.split("]")[0].strip(" ") + "]").upper()
else:
return NO_CATEGORY
commits = defaultdict(list)
with open("commits.txt") as file:
for line in file.readlines():
commits[get_category(line)].append(line.strip())
with open("commits.txt", "a") as file:
for category, commit_msgs in commits.items():
file.write("\n{}\n".format(category))
for commit_msg in commit_msgs:
file.write("{}\n".format(commit_msg))
if __name__ == "__main__":
run()