Skip to content

Commit

Permalink
auto-generate change log during release
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 25, 2019
1 parent 805aa9f commit be2c76e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
49 changes: 49 additions & 0 deletions bin/mkchangelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import datetime
import re
import sys
import git

URL = 'https://github.com/miguelgrinberg/python-engineio'
merges = {}


def format_message(commit):
if commit.message.startswith('Version '):
return ''
if '#nolog' in commit.message:
return ''
if commit.message.startswith('Merge pull request'):
pr = commit.message.split('#')[1].split(' ')[0]
message = ' '.join([line for line in [line.strip() for line in commit.message.split('\n')[1:]] if line])
merges[message] = pr
return ''
if commit.message.startswith('Release '):
return '\n**{message}** - {date}\n'.format(
message=commit.message.strip(),
date=datetime.datetime.fromtimestamp(commit.committed_date).strftime('%Y-%m-%d'))
message = ' '.join([line for line in [line.strip() for line in commit.message.split('\n')] if line])
if message in merges:
message += ' #' + merges[message]
message = re.sub('\\(.*(#[0-9]+)\\)', '\\1', message)
message = re.sub('Fixes (#[0-9]+)', '\\1', message)
message = re.sub('fixes (#[0-9]+)', '\\1', message)
message = re.sub('#([0-9]+)', '[#\\1]({url}/issues/\\1)'.format(url=URL), message)
message += ' ([commit]({url}/commit/{sha}))'.format(url=URL, sha=str(commit))
if commit.author.name != 'Miguel Grinberg':
message += ' (thanks **{name}**!)'.format(name=commit.author.name)
return '- ' + message


def main(all=False):
repo = git.Repo()

for commit in repo.iter_commits():
if not all and commit.message.startswith('Release '):
break
message = format_message(commit)
if message:
print(message)


if __name__ == '__main__':
main(all=len(sys.argv) > 1 and sys.argv[1] == 'all')
20 changes: 20 additions & 0 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ if [[ "$VERSION" == "" ]]; then
echo "Usage: $0 <version>"
fi

# update change log
head -n 2 CHANGES.md > _CHANGES.md
echo "**Release $VERSION** - $(date +%F)" >> _CHANGES.md
echo "" >> _CHANGES.md
pip install gitpython
python bin/mkchangelog.py >> _CHANGES.md
echo "" >> _CHANGES.md
len=$(wc -l < CHANGES.md)
tail -n $(expr $len - 2) CHANGES.md >> _CHANGES.md
vim _CHANGES.md
set +e
grep -q ABORT _CHANGES.md
if [[ "$?" == "0" ]]; then
rm _CHANGES.md
echo "Aborted."
exit 1
fi
set -e
mv _CHANGES.md CHANGES.md

sed -i "" "s/^__version__ = '.*'$/__version__ = '$VERSION'/" $VERSION_FILE
rm -rf dist
pip install --upgrade pip wheel twine
Expand Down

0 comments on commit be2c76e

Please sign in to comment.