From 82cc02fd0effd22c4e50cbb093668428ca37d20e Mon Sep 17 00:00:00 2001 From: iratusmachina Date: Sat, 20 Apr 2024 07:17:45 -0400 Subject: [PATCH] Refactoring draft notes generation --- .gitignore | 2 +- generate_notes.py | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 7a72e4e..f0d1f77 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ bin *.txt artifacts -bin \ No newline at end of file +draft_notes.md \ No newline at end of file diff --git a/generate_notes.py b/generate_notes.py index 98fc461..30c66aa 100644 --- a/generate_notes.py +++ b/generate_notes.py @@ -49,14 +49,20 @@ def draft(): # Get the current and previous tags tags = subprocess.check_output(["git", "tag", "--sort=creatordate"], text=True) - tags = [tag for tag in tags.split("\n") if tag] - tags.reverse() - current_tag, previous_tag, *_ = tags - formatted_lines = subprocess.check_output(["git", "log", f"{current_tag}...{previous_tag}", f'--pretty=format:"* %s"'], text=True) - lines = "\n".join([line.replace("\"", "") for line in formatted_lines.split("\n") if all(["merge" not in line.lower(), "changelog.md" not in line.lower()])]) - fw.write(lines) - fw.write("\n\n") - fw.write(f"Compare between recent changes: [{previous_tag[1:]}...{current_tag[1:]}]({remote_url}/compare/{previous_tag}...{current_tag})") + if tags: + tags = [tag for tag in tags.split("\n") if tag] + tags.reverse() + current_tag, previous_tag, *_ = tags + formatted_lines = subprocess.check_output(["git", "log", f"{current_tag}...{previous_tag}", f'--pretty=format:"* %s"'], text=True) + lines = "\n".join([line.replace("\"", "") for line in formatted_lines.split("\n") if all(["merge" not in line.lower(), "changelog.md" not in line.lower()])]) + fw.write(lines) + fw.write("\n\n") + fw.write(f"Compare between recent changes: [{previous_tag[1:]}...{current_tag[1:]}]({remote_url}/compare/{previous_tag}...{current_tag})") + else: + # first tag + formatted_lines = subprocess.check_output(["git", "log", f'--pretty=format:"* %s"'], text=True) + lines = "\n".join([line.replace("\"", "") for line in formatted_lines.split("\n") if all(["merge" not in line.lower(), "changelog.md" not in line.lower()])]) + fw.write(lines) except subprocess.CalledProcessError as e: print(f"Command failed with return code {e.returncode}")