Skip to content

Commit b46dc0f

Browse files
auto-generate change log during release
1 parent 7348d92 commit b46dc0f

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

bin/mkchangelog.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import datetime
2+
import re
3+
import sys
4+
import git
5+
6+
URL = 'https://github.com/miguelgrinberg/python-socketio'
7+
merges = {}
8+
9+
10+
def format_message(commit):
11+
if commit.message.startswith('Version '):
12+
return ''
13+
if '#nolog' in commit.message:
14+
return ''
15+
if commit.message.startswith('Merge pull request'):
16+
pr = commit.message.split('#')[1].split(' ')[0]
17+
message = ' '.join([line for line in [line.strip() for line in commit.message.split('\n')[1:]] if line])
18+
merges[message] = pr
19+
return ''
20+
if commit.message.startswith('Release '):
21+
return '\n**{message}** - {date}\n'.format(
22+
message=commit.message.strip(),
23+
date=datetime.datetime.fromtimestamp(commit.committed_date).strftime('%Y-%m-%d'))
24+
message = ' '.join([line for line in [line.strip() for line in commit.message.split('\n')] if line])
25+
if message in merges:
26+
message += ' #' + merges[message]
27+
message = re.sub('\\(.*(#[0-9]+)\\)', '\\1', message)
28+
message = re.sub('Fixes (#[0-9]+)', '\\1', message)
29+
message = re.sub('fixes (#[0-9]+)', '\\1', message)
30+
message = re.sub('#([0-9]+)', '[#\\1]({url}/issues/\\1)'.format(url=URL), message)
31+
message += ' ([commit]({url}/commit/{sha}))'.format(url=URL, sha=str(commit))
32+
if commit.author.name != 'Miguel Grinberg':
33+
message += ' (thanks **{name}**!)'.format(name=commit.author.name)
34+
return '- ' + message
35+
36+
37+
def main(all=False):
38+
repo = git.Repo()
39+
40+
for commit in repo.iter_commits():
41+
if not all and commit.message.startswith('Release '):
42+
break
43+
message = format_message(commit)
44+
if message:
45+
print(message)
46+
47+
48+
if __name__ == '__main__':
49+
main(all=len(sys.argv) > 1 and sys.argv[1] == 'all')

bin/release

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,32 @@ if [[ "$VERSION" == "" ]]; then
77
echo "Usage: $0 <version>"
88
fi
99

10+
# update change log
11+
head -n 2 CHANGES.md > _CHANGES.md
12+
echo "**Release $VERSION** - $(date +%F)" >> _CHANGES.md
13+
echo "" >> _CHANGES.md
14+
pip install gitpython
15+
python bin/mkchangelog.py >> _CHANGES.md
16+
echo "" >> _CHANGES.md
17+
len=$(wc -l < CHANGES.md)
18+
tail -n $(expr $len - 2) CHANGES.md >> _CHANGES.md
19+
vim _CHANGES.md
20+
set +e
21+
grep -q ABORT _CHANGES.md
22+
if [[ "$?" == "0" ]]; then
23+
rm _CHANGES.md
24+
echo "Aborted."
25+
exit 1
26+
fi
27+
set -e
28+
mv _CHANGES.md CHANGES.md
29+
1030
sed -i "" "s/^__version__ = '.*'$/__version__ = '$VERSION'/" $VERSION_FILE
1131
rm -rf dist
1232
pip install --upgrade pip wheel twine
1333
python setup.py sdist bdist_wheel --universal
1434

15-
git add $VERSION_FILE
35+
git add $VERSION_FILE CHANGES.md
1636
git commit -m "Release $VERSION"
1737
git tag -f v$VERSION
1838
git push --tags origin master

0 commit comments

Comments
 (0)