Skip to content

Commit

Permalink
DEV: Improve CHANGELOG generation
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Apr 21, 2022
1 parent 80c59c9 commit 34a35ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ maint:
pip-compile -U requirements/dev.in
pip-compile -U requirements/docs.in

changelog:
python make_changelog.py

upload:
make clean
python setup.py sdist bdist_wheel && twine upload -s dist/*
Expand Down
14 changes: 11 additions & 3 deletions make_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main(changelog_path: str):
today = datetime.now()
header = f"Version {new_version}, {today:%Y-%m-%d}\n"
header = header + "-" * (len(header) - 1) + "\n"
trailer = f"Full Changelog: https://github.com/py-pdf/PyPDF2/compare/{git_tag}...{new_version}"
trailer = f"\nFull Changelog: https://github.com/py-pdf/PyPDF2/compare/{git_tag}...{new_version}\n\n"
new_entry = header + changes + trailer
print(new_entry)

Expand Down Expand Up @@ -107,15 +107,23 @@ def get_most_recent_git_tag():
def get_git_commits_since_tag(git_tag) -> List[Change]:
commits = str(
subprocess.check_output(
["git", "--no-pager", "log", f"{git_tag}..HEAD", "--oneline"],
[
"git",
"--no-pager",
"log",
f"{git_tag}..HEAD",
'--pretty=format:"%h%x09%s"',
],
stderr=subprocess.STDOUT,
)
).strip("'b\\n")
return [parse_commit_line(line) for line in commits.split("\\n")]


def parse_commit_line(line) -> Change:
commit_hash, rest = line[: len("d5a5eea")], line[len("d5a5eea") :]
if "\\t" not in line:
raise ValueError(f"Invalid commit line: {line}")
commit_hash, rest = line.split("\\t", 1)
if ":" in rest:
prefix, message = rest.split(":", 1)
else:
Expand Down

0 comments on commit 34a35ac

Please sign in to comment.