mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-12 01:30:49 +01:00
changelog: tweaks
This commit is contained in:
parent
5dc5116b5b
commit
dc98e1fbd8
54
.github/changelog.py
vendored
54
.github/changelog.py
vendored
@ -3,10 +3,10 @@
|
|||||||
import subprocess, urllib.request, json, datetime
|
import subprocess, urllib.request, json, datetime
|
||||||
|
|
||||||
USE_GIT = True
|
USE_GIT = True
|
||||||
GIT_MAX_MERGES = 10 #maybe should use max date
|
GIT_MAX_MERGES = 10
|
||||||
JSON_MAX_MERGES = 10
|
JSON_MAX_MERGES = 10
|
||||||
JSON_LOCAL = True
|
JSON_LOCAL = True
|
||||||
|
MAKE_SHORT_CHANGELOG = False
|
||||||
|
|
||||||
def convert_git(stdout):
|
def convert_git(stdout):
|
||||||
lines = stdout.split('\n')
|
lines = stdout.split('\n')
|
||||||
@ -46,7 +46,15 @@ def convert_git(stdout):
|
|||||||
def load_git():
|
def load_git():
|
||||||
if not USE_GIT:
|
if not USE_GIT:
|
||||||
raise ValueError("git disabled")
|
raise ValueError("git disabled")
|
||||||
args = ['git','--no-pager','log', '--merges', '--max-count', str(GIT_MAX_MERGES), '--date=format:"%Y-%m-%d %H:%M:%S"']
|
|
||||||
|
args = ['git', 'describe', '--tags', '--abbrev=0']
|
||||||
|
proc = subprocess.run(args, capture_output=True)
|
||||||
|
if proc.returncode != 0:
|
||||||
|
raise ValueError("git exception")
|
||||||
|
latest_tag = proc.stdout.decode('utf-8').strip()
|
||||||
|
|
||||||
|
#args = ['git','--no-pager','log', '--merges', '--date=format:"%Y-%m-%d %H:%M:%S"', '--max-count', str(GIT_MAX_MERGES) ]
|
||||||
|
args = ['git','--no-pager','log', '--merges', '--date=format:"%Y-%m-%d %H:%M:%S"', '%s..HEAD' % (latest_tag)]
|
||||||
proc = subprocess.run(args, capture_output=True)
|
proc = subprocess.run(args, capture_output=True)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise ValueError("git exception")
|
raise ValueError("git exception")
|
||||||
@ -97,17 +105,25 @@ def load_json():
|
|||||||
return convert_json(data)
|
return convert_json(data)
|
||||||
|
|
||||||
|
|
||||||
def convert_items(items, lines):
|
def convert_items(items, lines, short_log):
|
||||||
for item in items:
|
for item in items:
|
||||||
message = item['message']
|
message = item['message']
|
||||||
date = item['date']
|
date = item['date']
|
||||||
|
|
||||||
header = "#### %s" % (date.replace('T',' ').replace('Z',''))
|
msg_from = None
|
||||||
|
ignore = False
|
||||||
subs = []
|
subs = []
|
||||||
msg_lines = iter([msg.strip() for msg in message.split('\n')])
|
msg_lines = iter([msg.strip() for msg in message.split('\n')])
|
||||||
for msg in msg_lines:
|
for msg in msg_lines:
|
||||||
if msg.lower().startswith('merge'):
|
if msg.lower().startswith('merge'):
|
||||||
|
if ' into ' in msg: #Merge branch ... into ...
|
||||||
|
ignore = True
|
||||||
|
break
|
||||||
|
try:
|
||||||
|
pos = msg.index(' from ')
|
||||||
|
msg_from = msg[pos + 6:].strip()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
continue
|
continue
|
||||||
if not msg: #always first?
|
if not msg: #always first?
|
||||||
continue
|
continue
|
||||||
@ -118,42 +134,56 @@ def convert_items(items, lines):
|
|||||||
msg = '- %s' % (msg[2:])
|
msg = '- %s' % (msg[2:])
|
||||||
subs.append(msg)
|
subs.append(msg)
|
||||||
|
|
||||||
|
if ignore:
|
||||||
|
continue
|
||||||
|
|
||||||
if not subs:
|
if not subs:
|
||||||
subs.append('- (not described)')
|
subs.append('- (not described)')
|
||||||
|
|
||||||
|
if short_log:
|
||||||
|
lines.extend(subs)
|
||||||
|
else:
|
||||||
|
header = "#### %s" % (date.replace('T',' ').replace('Z',''))
|
||||||
|
if msg_from:
|
||||||
|
header += ' (%s)' % (msg_from)
|
||||||
lines.append(header)
|
lines.append(header)
|
||||||
lines.extend(subs)
|
lines.extend(subs)
|
||||||
lines.append('')
|
lines.append('')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def write(lines):
|
def write(lines):
|
||||||
with open('changelog.txt', 'w', encoding="utf-8") as f:
|
with open('changelog.txt', 'w', encoding="utf-8") as f:
|
||||||
f.write('\n'.join(lines))
|
f.write('\n'.join(lines))
|
||||||
|
|
||||||
def get_lines():
|
def get_lines(short_log=False):
|
||||||
|
if short_log:
|
||||||
|
lines = []
|
||||||
|
else:
|
||||||
curr_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
curr_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
lines = [
|
lines = [
|
||||||
'### CHANGELOG',
|
'### CHANGELOG',
|
||||||
'(latest main changes on %s, skips smaller commits)' % (curr_date),
|
'(latest changes from previous release, generated on %s)' % (curr_date),
|
||||||
'',
|
'',
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
items = load_git()
|
items = load_git()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("error when generating git, using json:", e)
|
print("error when generating git, using json:", e)
|
||||||
items = load_json()
|
items = load_json()
|
||||||
convert_items(items, lines)
|
convert_items(items, lines, short_log)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("err", e)
|
print("err", e)
|
||||||
lines.append("(couldn't generate changelog)")
|
lines.append("(couldn't generate changelog)")
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def main():
|
def main(short_changelog=False):
|
||||||
lines = get_lines()
|
lines = get_lines(short_changelog)
|
||||||
write(lines)
|
write(lines)
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main(MAKE_SHORT_CHANGELOG)
|
||||||
|
Loading…
Reference in New Issue
Block a user