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
|
#!/usr/bin/env python3
"""Extracts commit message for the last release from NEWS.md file.
"""
from itertools import dropwhile
import sys
with open('NEWS.md') as f:
contents = f.readlines()
if contents[0].startswith('## '):
name = contents[0][3:]
contents = contents[1:]
elif contents[1].startswith('---'):
name = contents[0]
contents = contents[2:]
else:
raise ValueError("Can't find release name")
name = name.strip()
print("Release", name)
# git wants a single newline between commit title and message body
print()
# meanwhile, markdown ignores newlines after a title
contents = dropwhile(lambda x: x.strip() == '', contents)
# Need to look up forward
contents = list(contents)
for line, nextline in zip(contents, contents[1:] + ['']):
if nextline.startswith('---') or line.startswith('## '):
break
elif nextline.startswith('===') or line.startswith('# '):
raise ValueError("Encountered title instead of release section")
print(line.strip())
|