-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script for extracting changelog from commit messages
- Loading branch information
1 parent
fdf04ee
commit 0783221
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/python3 | ||
import pygit2 | ||
import sys | ||
import re | ||
from collections import defaultdict | ||
|
||
repo = pygit2.Repository(".") | ||
|
||
until = repo.revparse_single(f'refs/tags/{sys.argv[1]}').id | ||
|
||
walker = repo.walk(repo.head.target) | ||
walker.simplify_first_parent() | ||
|
||
changelog_re = re.compile(r"changelog:\s+(.+?)/(.+?):\s+(.+?)(?:(?:\n\n)|$)", flags=re.DOTALL) | ||
|
||
lines = defaultdict(lambda: defaultdict(list)) | ||
|
||
def fix_spelling(word) : | ||
if word in ("Enhacements", "Enhnacements") : | ||
return "Enhancements" | ||
return word.title() | ||
|
||
for commit in walker : | ||
if commit.id == until : | ||
break | ||
#print(commit.message) | ||
m = changelog_re.findall(commit.message.strip()) | ||
for r in m : | ||
cat, subcat, msg = r | ||
msg = msg.replace("\n", " ") | ||
line = f" - {msg} ({commit.id})" | ||
lines[fix_spelling(cat)][fix_spelling(subcat)].append(line) | ||
|
||
for cat, subcats in lines.items() : | ||
print("##", cat) | ||
print() | ||
for subcat, items in subcats.items() : | ||
print("###", subcat) | ||
print() | ||
for item in items : | ||
print(item) | ||
print() | ||
print() | ||
|