Skip to content

Instantly share code, notes, and snippets.

@powellc
Last active May 12, 2016 18:14
Show Gist options
  • Save powellc/cd9b8d45c8210f20dca21e755aaa81ee to your computer and use it in GitHub Desktop.
Save powellc/cd9b8d45c8210f20dca21e755aaa81ee to your computer and use it in GitHub Desktop.
Build a changelog from git commits
import re
import os
import git
semver_pattern = '(?:(\d+)\.)(?:(\d+)\.)(?:(\d+))'
BASE_DIR = os.getcwd()
g = git.cmd.Git(BASE_DIR)
commits = list(filter(None, g.log("--format=%B").splitlines()))
text = 'Change Log for <your project here>\n====================================\n\nDev\n---\r\n\n'
for commit in commits:
search = re.search(semver_pattern, commit)
if bool(search):
version = '.'.join([n for n in search.groups()])
text += '\r\n\n'
text += version + '\n'
text += '-----\n'
text += '\r\n'
if 'Merge branch' in commit or 'Merged in' in commit:
pass
else:
text += ' * ' + commit + '\n'
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment