Created
December 5, 2016 19:22
-
-
Save nicoddemus/8fd168e1e6897864d8f22a9340709a7a to your computer and use it in GitHub Desktop.
Reads dates from git and updates CHANGELOG entries From pytest-dev/pytest#721
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, division, print_function, unicode_literals | |
import re | |
import subprocess | |
with open('CHANGELOG.rst') as f: | |
changelog_lines = f.readlines() | |
output = subprocess.check_output('git log --tags --simplify-by-decoration --pretty="format:%ci %d"', shell=True) | |
tags_and_dates = {} | |
for line in output.splitlines(): | |
m = re.search('\(tag: (.*)\)', line) | |
if not m: | |
continue | |
tag = m.group(1) | |
date = line.split()[0] | |
tags_and_dates[tag] = date | |
for index, changelog_line in enumerate(changelog_lines): | |
if changelog_line.strip() in tags_and_dates: | |
tag = changelog_line.strip() | |
date = tags_and_dates[tag] | |
new_line = '{} ({})\n'.format(tag, date) | |
changelog_lines[index] = new_line | |
changelog_lines[index + 1] = (len(new_line) - 1) * '=' + '\n' | |
print(new_line) | |
print(len(new_line) * '=') | |
print() | |
with open('CHANGELOG.rst', 'w') as f: | |
f.writelines(changelog_lines) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment