forked from mamedev/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakewn.py
executable file
·272 lines (229 loc) · 9.28 KB
/
makewn.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/python
##
## license:BSD-3-Clause
## copyright-holders:Vas Crabb
import argparse
import getpass
import git
import pygithub3
import re
import sys
releasetag_pat = re.compile('^mame0([0-9]+)$')
nowhatsnew_pat = re.compile('.*([[(]n/?w[])].*|[\s,]n/?w$)')
bullet_pat = re.compile('^([-*]\s*)?(.+)$')
credit_pat = re.compile('^.+\s\[.+\]$')
markdown_url_pat = re.compile('\[([^]]+)\]\(([^)])+\)')
softlist_pat = re.compile('soft(ware)? ?list')
notworking_pat = re.compile('not[_ ]working')
longdash_pat = re.compile('^-{2,}$')
new_working_parents = []
new_broken_parents = []
new_working_clones = []
new_broken_clones = []
def print_wrapped(stream, paragraph, level):
wrapcol = 132
if level == -1:
prefix = ''
indent = ' '
elif level == 0:
prefix = '-'
indent = ' '
elif level == 1:
prefix = ' * '
indent = ' '
else:
prefix = ' - '
indent = ' '
if nowhatsnew_pat.match(paragraph) is None:
while paragraph:
if (len(prefix) + len(paragraph)) > wrapcol:
pos = paragraph.rfind(' ', 0, wrapcol + 1 - len(prefix))
if pos < 0:
pos = paragraph.find(' ', wrapcol + 1 - len(prefix))
if pos >= 0:
if paragraph[-1] == ']':
opening = paragraph.rfind(' [')
if (opening >= 0) and (opening < pos):
pos = opening
line = paragraph[0:pos].strip()
paragraph = paragraph[pos:].strip()
else:
line = paragraph
paragraph = ''
stream.write(('%s%s\n' % (prefix, line)).encode('UTF-8'))
prefix = indent
def format_paragraph(stream, paragraph, level, author, first):
if first and (credit_pat.match(paragraph) is None):
paragraph = '%s [%s]' % (paragraph, author)
print_wrapped(stream, paragraph, level)
def append_line(paragraph, line):
if paragraph:
return '%s %s' % (paragraph, line)
else:
return line
def check_new_machines(line):
line = line.lower()
if line.startswith('new') and (softlist_pat.match(line) is None):
clone = line.find('clone') >= 0
if notworking_pat.match(line) is not None:
working = line.find('promot') >= 0
else:
working = True
if clone:
return new_working_clones if working else new_broken_clones
else:
return new_working_parents if working else new_broken_parents
else:
return None
def format_entry(stream, message, author, checkmachines):
machines = None
first = True
paragraph = ''
level = 0
bullet = ''
for line in message.splitlines():
line = line.strip().replace('\t', ' ')
if not line:
if paragraph:
machines = None
if first and (nowhatsnew_pat.match(paragraph) is not None):
return
format_paragraph(stream, paragraph, level, author, first)
paragraph = ''
first = False
elif machines is not None:
paragraph = ''
temp = check_new_machines(line)
if temp is not None:
machines = temp
elif longdash_pat.match(line) is None:
if credit_pat.match(line) is None:
machines.append('%s [%s]' % (line, author))
else:
machines.append(line)
elif (line[0] == '-') or (line[0] == '*'):
if paragraph:
if first and (nowhatsnew_pat.match(paragraph) is not None):
return
format_paragraph(stream, paragraph, level, author, first)
paragraph = ''
first = False
if not bullet:
level = 1
elif bullet != line[0]:
level = 1 if level == 2 else 2
bullet = line[0]
line = bullet_pat.sub('\\2', line)
paragraph = append_line(paragraph, line)
else:
if checkmachines:
machines = check_new_machines(line)
if machines:
if paragraph:
if nowhatsnew_pat.match(paragraph) is None:
format_paragraph(stream, paragraph, level, author, first)
first = False
paragraph = ''
paragraph = append_line(paragraph, line)
else:
if not paragraph:
level = 0 if first else 1
bullet = ''
paragraph = append_line(paragraph, line)
if paragraph:
if first and (nowhatsnew_pat.match(paragraph) is not None):
return
format_paragraph(stream, paragraph, level, author, first)
paragraph = ''
first = False
if not first:
stream.write('\n'.encode('UTF-8'))
def format_commit(stream, commit):
author = commit.author.name
if not author:
author = commit.author.email
format_entry(stream, commit.message, author, True)
def print_log(stream, repo, revisions):
commits = repo.iter_commits(revisions, reverse=True)
for commit in commits:
if len(commit.parents) == 1:
format_commit(stream, commit)
def get_most_recent_tag(repo):
result = None
best = 0
for tag in repo.tags:
match = releasetag_pat.match(tag.name)
if match is not None:
num = long(match.group(1))
if num > best:
result = tag
return result
def get_latest_tagged_commit(api):
pat = re.compile('^mame0[0-9]+$')
for page in api.repos.list_tags():
for tag in page:
if pat.match(tag.name) is not None:
return api.git_data.commits.get(tag.commit.sha)
def fresher_pull_requests(api, commit):
for page in api.pull_requests.list(state='closed'):
for pr in page:
if (pr.merged_at is not None) and (pr.merged_at > commit.committer.date):
yield pr
def print_fresh_pull_requests(api, stream, commit):
for pr in fresher_pull_requests(api, commit):
if pr.title and (pr.title[-1] == unichr(0x2026)) and pr.body and (pr.body[0] == unichr(0x2026)):
message = pr.title[:-1] + pr.body[1:]
elif pr.body:
message = '%s\n%s' % (pr.title, pr.body)
else:
message = pr.title
message = markdown_url_pat.sub('\\1', message)
format_entry(stream, message, pr.user['login'], True)
def print_section_heading(stream, heading):
stream.write(('%s\n%s\n' % (heading, '-' * len(heading))).encode('UTF-8'))
def print_source_changes(stream, repo, api, tag):
print_section_heading(stream, 'Source Changes')
print_log(stream, repo, '%s..release0%ld' % (tag.name, (long(releasetag_pat.sub('\\1', tag.name)) + 1)))
print_fresh_pull_requests(api, stream, api.git_data.commits.get(tag.commit.hexsha))
stream.write('\n'.encode('UTF-8'))
def print_new_machines(stream, title, machines):
if machines:
print_section_heading(stream, title)
for machine in machines:
print_wrapped(stream, bullet_pat.sub('\\2', machine), -1)
stream.write('\n\n'.encode('UTF-8'))
def parse_args():
parser = argparse.ArgumentParser(description='Write preliminary whatsnew.')
parser.add_argument('-c', '--clone', metavar='<path>', type=str, help='local repository clone')
parser.add_argument('-u', '--user', metavar='<username>', type=str, help='github username')
parser.add_argument('-o', '--out', metavar='<file>', type=str, help='output file')
parser.add_argument('-a', '--append', action='store_const', const=True, default=False, help='append to output file')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
if args.user is not None:
ghuser = args.user
else:
ghuser = raw_input('github username: ')
if args.out is not None:
stream = open(args.out, 'a' if args.append else 'w')
else:
stream = sys.stdout
repo = git.Repo(args.clone if args.clone is not None else '.')
api = pygithub3.Github(user='mamedev', repo='mame', login=ghuser, password=getpass.getpass('github password: '))
tag = get_most_recent_tag(repo)
print_section_heading(stream, '0.%s' % (long(releasetag_pat.sub('\\1', tag.name)) + 1))
stream.write('\n\n'.encode('UTF-8'))
print_section_heading(stream, 'MAMETesters Bugs Fixed')
stream.write('\n\n'.encode('UTF-8'))
print_source_changes(stream, repo, api, tag)
print_new_machines(stream, 'New machines added or promoted from NOT_WORKING status', new_working_parents);
print_new_machines(stream, 'New clones added or promoted from NOT_WORKING status', new_working_clones);
print_new_machines(stream, 'New machines marked as NOT_WORKING', new_broken_parents);
print_new_machines(stream, 'New clones marked as NOT_WORKING', new_broken_clones);
print_section_heading(stream, 'New WORKING software list additions')
stream.write('\n\n'.encode('UTF-8'))
print_section_heading(stream, 'New NOT_WORKING software list additions')
stream.write('\n\n'.encode('UTF-8'))
print_section_heading(stream, 'Translations added or modified')
stream.write('\n\n'.encode('UTF-8'))