Skip to content

Commit

Permalink
add option to insert changelog entry
Browse files Browse the repository at this point in the history
  • Loading branch information
eteq committed Dec 7, 2016
1 parent f0fae81 commit 863e79a
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions add_to_changelog.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ def main(argv=None):
parser.add_argument('--write', '-w', action='store_true', help='update the '
'referenced changelog (the first '
'argument) to include the generated '
'changelog at the top.')
'changelog at the top (or if -l is '
'set, it determines the location).')
parser.add_argument('--last-version', '-l', help='The name of the version '
'that this changelog entry should precede. If not '
'given, this changelog will go at the top', default='')

args = parser.parse_args(argv)

Expand All @@ -93,12 +97,30 @@ def main(argv=None):
newvers_head='-'*len(args.version),
package_list=pkg_list_str)
if args.write:
with open(args.changelog) as f:
old_changelog = f.read()
with open(args.changelog) as fr:
old_changelog = fr.read()
with open(args.changelog, 'w') as fw:
fw.write(new_changelog)
fw.write('\n')
fw.write(old_changelog)
if args.last_version:
header_match = None
for l in old_changelog.split('\n'):
if args.last_version + ' (' in l:
header_match = l + '\n'
elif header_match:
if '-'*len(args.last_version) in l:
fw.write('\n\n')
fw.write(new_changelog)
fw.write('\n\n\n')
fw.write(header_match)
fw.write(l)
fw.write('\n')
header_match = None
else:
fw.write(l)
fw.write('\n')
else:
fw.write(new_changelog)
fw.write('\n\n\n')
fw.write(old_changelog)

print(new_changelog)

Expand Down

0 comments on commit 863e79a

Please sign in to comment.