forked from espnet/espnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_release_note_from_milestone.py
More file actions
104 lines (90 loc) · 3.09 KB
/
make_release_note_from_milestone.py
File metadata and controls
104 lines (90 loc) · 3.09 KB
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
98
99
100
101
102
103
104
#!/usr/bin/env python3
"""Create release note from milestone with PyGithub."""
import argparse
from collections import defaultdict
import github
def main():
"""Make release note from milestone with PyGithub."""
# parse arguments
parser = argparse.ArgumentParser("release note generator")
parser.add_argument("--user", default="espnet")
parser.add_argument("--repo", default="espnet")
parser.add_argument("token", default=None, type=str)
parser.add_argument("milestone", default=None, type=str)
args = parser.parse_args()
# get repository object
g = github.Github(args.token)
repo = g.get_organization(args.user).get_repo(args.user)
# get milestone object
for m in repo.get_milestones(state="all"):
if m.title == args.milestone:
milestone = m
break
# get pull requests
pull_requests = []
for i in repo.get_issues(milestone, state="closed"):
try:
pr = i.as_pull_request()
if pr.merged:
pull_requests += [pr]
except github.UnknownObjectException:
continue
# make dict of closed pull requests per label and contributor list
pull_request_dict = defaultdict(list)
contributors = []
pickup_labels = [
"New Features",
"Enhancement",
"Recipe",
"Bugfix",
"Documentation",
"Refactoring",
]
for pr in pull_requests:
if pr.user.login not in contributors:
contributors.append(pr.user.login)
for label in pr.labels:
is_pickup = False
if label.name in pickup_labels:
pull_request_dict[label.name].append(pr)
is_pickup = True
break
if not is_pickup:
pull_request_dict["Others"].append(pr)
# make release note
ignore_labels = ["mergify", "auto-merge", "README"]
for pickup_label in pickup_labels + ["Others"]:
if pickup_label not in pull_request_dict:
continue
else:
pull_requests = pull_request_dict[pickup_label]
print(f"# {pickup_label}")
for pr in pull_requests:
sub_labels = [
l_.name
for l_ in pr.labels
if l_.name not in pickup_labels + ignore_labels
]
line = f"- [**{pickup_label}**]"
sub_line_a = ""
sub_line_b = ""
for sub_label in sub_labels:
if sub_label.startswith("ESPnet"):
sub_line_a += f"[**{sub_label}**]"
else:
sub_line_b += f"[**{sub_label}**]"
line += sub_line_a + sub_line_b
line += f" {pr.title} #{pr.number} by @{pr.user.login}"
print(line)
print()
print("# Acknowledgements")
print("Special thanks to ", end="")
for idx, contributor in enumerate(sorted(contributors), 1):
print("@" + contributor, end="")
if idx != len(contributors):
print(", ", end="")
else:
print(".")
print()
if __name__ == "__main__":
main()