Skip to content

Commit fa806c5

Browse files
authored
Merge pull request #176 from didi/release_notes
*add release_notes
2 parents 5c00689 + 2915d6b commit fa806c5

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

tools/release_notes.py

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd.
2+
# All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
17+
""" Create release notes with the issues from a milestone.
18+
python release_notes.py -c didi delta v.xxxxx
19+
"""
20+
21+
import argparse
22+
import urllib.request
23+
import json
24+
import collections
25+
26+
github_url = 'https://api.github.com/repos'
27+
28+
if __name__ == '__main__':
29+
30+
# Parse arguments
31+
32+
parser = argparse.ArgumentParser(
33+
description='Create a draft release with the issues from a milestone.'
34+
)
35+
36+
parser.add_argument(
37+
'user',
38+
metavar='user',
39+
type=str,
40+
help='github user'
41+
)
42+
43+
parser.add_argument(
44+
'repository',
45+
metavar='repository',
46+
type=str,
47+
help='githb repository'
48+
)
49+
50+
parser.add_argument(
51+
'milestone',
52+
metavar='name of milestone',
53+
type=str,
54+
help='name of used milestone'
55+
)
56+
57+
parser.add_argument(
58+
'-c', '--closed',
59+
help='Fetch closed milestones/issues',
60+
action='store_true'
61+
)
62+
63+
args = parser.parse_args()
64+
65+
# Fetch milestone id
66+
67+
url = "%s/%s/%s/milestones" % (
68+
github_url,
69+
args.user,
70+
args.repository
71+
)
72+
73+
headers = {
74+
'Origin': 'https://github.com',
75+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '
76+
'AppleWebKit/537.11 (KHTML, like Gecko) '
77+
'Chrome/23.0.1271.64 Safari/537.11',
78+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
79+
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
80+
'Accept-Encoding': 'none',
81+
'Accept-Language': 'en-US,en;q=0.8',
82+
'Connection': 'keep-alive'}
83+
84+
if args.closed:
85+
url += "?state=closed"
86+
req = urllib.request.Request(url, headers=headers)
87+
github_request = urllib.request.urlopen(req)
88+
89+
if not github_request:
90+
parser.error('Cannot read milestone list.')
91+
92+
decoder = json.JSONDecoder()
93+
94+
milestones = decoder.decode(github_request.read().decode('utf-8'))
95+
96+
print('parse milestones')
97+
98+
github_request.close()
99+
100+
milestone_id = None
101+
for milestone in milestones:
102+
if milestone['title'] == args.milestone:
103+
milestone_id = milestone['number']
104+
if not milestone_id:
105+
parser.error('Cannot find milestone')
106+
107+
url = '%s/%s/%s/issues?milestone=%d' % (
108+
github_url,
109+
args.user,
110+
args.repository,
111+
milestone_id
112+
)
113+
114+
if args.closed:
115+
url += "&state=closed"
116+
req = urllib.request.Request(url, headers=headers)
117+
github_request = urllib.request.urlopen(req)
118+
if not github_request:
119+
parser.error('Cannot read issue list.')
120+
121+
issues = decoder.decode(github_request.read().decode('utf-8'))
122+
print('parse issues')
123+
github_request.close()
124+
125+
final_data = []
126+
labels = []
127+
for issue in issues:
128+
129+
for label in issue['labels']:
130+
labels.append(label['name'])
131+
132+
final_data.append(' * **[%s]** - %s #%d by **@%s**\n' % (
133+
label['name'],
134+
issue['title'],
135+
issue['number'],
136+
issue['user']['login']
137+
))
138+
139+
dic = collections.defaultdict(set)
140+
for l_release in list(set(labels)):
141+
142+
for f_data in final_data:
143+
if l_release in f_data:
144+
dic[l_release].add(f_data)
145+
146+
for key, value in dic.items():
147+
print('# %s\n%s' % (key, ''.join(value)))

0 commit comments

Comments
 (0)