Last active
May 12, 2016 18:14
-
-
Save powellc/cd9b8d45c8210f20dca21e755aaa81ee to your computer and use it in GitHub Desktop.
Build a changelog from git commits
This file contains 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
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