From 65b5d0e86b4a6d0beed50155dd02edb57dab4a29 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Fri, 30 Aug 2024 12:39:49 +0200 Subject: [PATCH] update generate_changelog.sh --- generate_changelog.sh | 47 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/generate_changelog.sh b/generate_changelog.sh index ccc9a67..7ccfa4f 100755 --- a/generate_changelog.sh +++ b/generate_changelog.sh @@ -28,7 +28,50 @@ echo -ne "# [${version}](${url}/tree/${current}) ($date)\n\n[Full Changelog](${u if [ "$version" = "$tag" ]; then # on a tag # Fetch release notes using GitHub CLI releaseNotes=$(gh release view "$tag" --json body -q ".body") - echo -ne "## Release Notes\n\n ${releaseNotes} \n\n## Commits\n\n" >> "CHANGELOG.md" + echo -ne "## Release Notes\n${releaseNotes}\n" >> "CHANGELOG.md" fi -git shortlog --no-merges --reverse "$previous..$current" | sed -e '/^\w/G' -e 's/^ /- /' >> "CHANGELOG.md" +# Create temporary file to store shortlog output +tempFile=$(mktemp) + +# Append commits to temporary file +git shortlog --no-merges --reverse "$previous..$current" > "$tempFile" + +# Initialize arrays to hold categorized commits +featureCommits=() +bugfixCommits=() + +# Read the temporary file line by line +while IFS= read -r line; do + # Strip leading whitespace and extract commit message + commitMessage=$(echo "$line" | sed -e 's/^\s*[^ ]\+ //') + + # Check for commit suffixes + if echo "$line" | grep -q "\[Feature\]"; then + # Remove suffix and add to features array + featureCommits+=("- ${commitMessage//\[Feature\]/}") + elif echo "$line" | grep -q "\[Bugfix\]"; then + # Remove suffix and add to bugfixes array + bugfixCommits+=("- ${commitMessage//\[Bugfix\]/}") + fi +done < "$tempFile" + +# Clean up temporary file +rm "$tempFile" + +# Write results to changelog +{ + if [ ${#featureCommits[@]} -ne 0 ]; then + echo -ne "### Features\n" + for commit in "${featureCommits[@]}"; do + echo "$commit" + done + fi + + if [ ${#bugfixCommits[@]} -ne 0 ]; then + echo -ne "### Bug Fixes\n" + for commit in "${bugfixCommits[@]}"; do + echo "$commit" + done + fi +} >> "CHANGELOG.md" \ No newline at end of file