forked from dask/dask-image
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_release_notes.py
More file actions
205 lines (172 loc) · 5.84 KB
/
generate_release_notes.py
File metadata and controls
205 lines (172 loc) · 5.84 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""Generate the release notes automatically from Github pull requests.
Start with:
```
export GH_TOKEN=<your-gh-api-token>
```
Then, for to include everything from a certain release to main:
```
python /path/to/generate_release_notes.py v0.14.0 main --version 0.15.0
```
Or two include only things between two releases:
```
python /path/to/generate_release_notes.py v.14.2 v0.14.3 --version 0.14.3
```
You should probably redirect the output with:
```
python /path/to/generate_release_notes.py [args] | tee release_notes.md
```
You'll require PyGitHub and tqdm, which you can install with:
```
pip install PyGithub>=1.44.1 twine>=3.1.1 tqdm
```
References
https://github.com/scikit-image/scikit-image/blob/master/tools/generate_release_notes.py
https://github.com/scikit-image/scikit-image/issues/3404
https://github.com/scikit-image/scikit-image/issues/3405
"""
import os
import argparse
from datetime import datetime
from collections import OrderedDict
from warnings import warn
from github import Github
try:
from tqdm import tqdm
except ImportError:
warn(
'tqdm not installed. This script takes approximately 5 minutes '
'to run. To view live progressbars, please install tqdm. '
'Otherwise, be patient.'
)
def tqdm(i, **kwargs):
return i
GH = "https://github.com"
GH_USER = 'dask'
GH_REPO = 'dask-image'
GH_TOKEN = os.environ.get('GH_TOKEN')
if GH_TOKEN is None:
raise RuntimeError(
"It is necessary that the environment variable `GH_TOKEN` "
"be set to avoid running into problems with rate limiting. "
"One can be acquired at https://github.com/settings/tokens.\n\n"
"You do not need to select any permission boxes while generating "
"the token."
)
g = Github(GH_TOKEN)
repository = g.get_repo(f'{GH_USER}/{GH_REPO}')
parser = argparse.ArgumentParser(usage=__doc__)
parser.add_argument('from_commit', help='The starting tag.')
parser.add_argument('to_commit', help='The head branch.')
parser.add_argument(
'--version', help="Version you're about to release.", default='0.2.0'
)
args = parser.parse_args()
for tag in repository.get_tags():
if tag.name == args.from_commit:
previous_tag = tag
break
else:
raise RuntimeError(f'Desired tag ({args.from_commit}) not found')
# For some reason, go get the github commit from the commit to get
# the correct date
github_commit = previous_tag.commit.commit
previous_tag_date = datetime.strptime(
github_commit.last_modified, '%a, %d %b %Y %H:%M:%S %Z'
)
all_commits = list(
tqdm(
repository.get_commits(sha=args.to_commit, since=previous_tag_date),
desc=f'Getting all commits between {args.from_commit} '
f'and {args.to_commit}',
)
)
all_hashes = set(c.sha for c in all_commits)
def add_to_users(users, new_user):
if new_user.name is None:
users[new_user.login] = new_user.login
else:
users[new_user.login] = new_user.name
authors = set()
committers = set()
reviewers = set()
users = {}
for commit in tqdm(all_commits, desc="Getting commiters and authors"):
if commit.committer is not None:
add_to_users(users, commit.committer)
committers.add(commit.committer.login)
if commit.author is not None:
add_to_users(users, commit.author)
authors.add(commit.author.login)
# remove these bots.
committers.discard("web-flow")
authors.discard("azure-pipelines-bot")
highlights = OrderedDict()
highlights['Highlights'] = {}
highlights['New Features'] = {}
highlights['Improvements'] = {}
highlights['Bug Fixes'] = {}
highlights['API Changes'] = {}
highlights['Deprecations'] = {}
highlights['Build Tools'] = {}
other_pull_requests = {}
for pull in tqdm(
g.search_issues(
f'repo:{GH_USER}/{GH_REPO} '
f'is:pull-request '
f'merged:>{previous_tag_date.isoformat()} '
'sort:created-asc'
),
desc='Pull Requests...',
):
pr = repository.get_pull(pull.number)
if pr.merge_commit_sha in all_hashes:
summary = pull.title
for review in pr.get_reviews():
if review.user is not None:
add_to_users(users, review.user)
reviewers.add(review.user.login)
for key, key_dict in highlights.items():
pr_title_prefix = (key + ': ').lower()
if summary.lower().startswith(pr_title_prefix):
key_dict[pull.number] = {
'summary': summary[len(pr_title_prefix):]
}
break
else:
other_pull_requests[pull.number] = {'summary': summary}
# add Other PRs to the ordered dict to make doc generation easier.
highlights['Other Pull Requests'] = other_pull_requests
# Now generate the release notes
title = (f'{args.version} ({datetime.today().strftime("%Y-%m-%d")})')
title += f'\n' + f'-' * len(title) #title underline of same length as title
print(title)
print(
f"""
We're pleased to announce the release of dask-image {args.version}!
"""
)
for section, pull_request_dicts in highlights.items():
print(f'{section}\n')
if len(pull_request_dicts.items()) == 0:
print()
for number, pull_request_info in pull_request_dicts.items():
print(f'* {pull_request_info["summary"]} (#{number})')
contributors = OrderedDict()
contributors['authors'] = authors
contributors['reviewers'] = reviewers
# ignore committers
# contributors['committers'] = committers
for section_name, contributor_set in contributors.items():
print()
if None in contributor_set:
contributor_set.remove(None)
committer_str = (
f'{len(contributor_set)} {section_name} added to this '
'release (alphabetical)'
)
print(committer_str)
print()
for c in sorted(contributor_set, key=lambda x: users[x].lower()):
commit_link = f"{GH}/{GH_USER}/{GH_REPO}/commits?author={c}"
print(f"* `{users[c]} <{commit_link}>`_ - @{c}")
print()