Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Release notes script #51

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions scripts/release_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Creates a JSON formatted list of release notes. It follows the same format
# as in the GitHub API.
#
# Changes are split into categories:
# - `breaking_changes`, has the list of breaking changes
# - `bug_fixes`,
# - `new_features`,
# - `other`
#
# USAGE: pass an initial and final reference to generate release notes
# `release_notes.py v0.6.1 v0.7.0` will generate the release notes for versions between v0.6.1 and v0.7.0
#
# Motivation: While GitHub generates the release notes between releases, this tool can generate release notes between any two references.


import json
import subprocess
import sys
from dataclasses import dataclass


@dataclass
class ReleaseNotes:
breaking_changes: list[str]
bug_fixes: list[str]
new_features: list[str]
other: list[str]

def to_json(self) -> str:
json_map = {
"breaking_changes": self.breaking_changes,
"bug_fixes": self.bug_fixes,
"new_features": self.new_features,
"other": self.other,
}
return json.dumps(json_map)


def parse_git_log(initial_tag: str, final_tag: str):
git_output = subprocess.Popen(
["git", "--no-pager", "log", "--oneline", f"{initial_tag}..{final_tag}"],
bufsize=0,
stdout=subprocess.PIPE,
)
release_notes = ReleaseNotes(
breaking_changes=[], bug_fixes=[], new_features=[], other=[]
)
while True:
line = git_output.stdout.readline().decode("utf-8")
if not line:
break
# Remove commit SHA
line = line[(line.index(" ") + 1) :]
if line.startswith("feat!:"):
release_notes.breaking_changes.append(line)
elif line.startswith("fix:"):
release_notes.bug_fixes.append(line)
elif line.startswith("feat:"):
release_notes.new_features.append(line)
else:
release_notes.other.append(line)

git_output.stdout.close()
git_output.wait()
print(release_notes.to_json())


if __name__ == "__main__":
parse_git_log(sys.argv[1], sys.argv[2])
6 changes: 5 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading