From 287bb5e88699fedf0354babcfc936691790791e1 Mon Sep 17 00:00:00 2001 From: andersonbosa Date: Sun, 12 May 2024 13:57:20 -0300 Subject: [PATCH] chore: Remove moshell.sh/tools/changelog.sh script This commit removes the moshell.sh/tools/changelog.sh script, which was used to generate changelogs. This script is no longer needed because the changelog is now generated using the 'changelog.yaml' configuration file. --- moshell.sh/tools/changelog.sh | 103 ---------------------------------- 1 file changed, 103 deletions(-) delete mode 100755 moshell.sh/tools/changelog.sh diff --git a/moshell.sh/tools/changelog.sh b/moshell.sh/tools/changelog.sh deleted file mode 100755 index b3129c8..0000000 --- a/moshell.sh/tools/changelog.sh +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env bash -# -# Author: @andersonbosa -# Description: This script generates a changelog based on Git commit history. -# It identifies the last release commit, parses the commit messages, and -# categorizes them into different sections based on semantic keys. The resulting -# changelog is formatted and saved to a specified file location. -# - -ABSOLUTE_SCRIPT_FILE_PATH="${BASH_SOURCE:-$0}" -ABSOLUTE_SCRIPT_DIR_PATH=$(dirname "$ABSOLUTE_SCRIPT_FILE_PATH") - -function __moshell:tools::changelog::get_last_release_commit() { - local release_version_regex="$1" - - if [[ -z "$release_version_regex" ]]; then - local default_regex="release([0-9]\+\.[0-9]\+\.[0-9]\+)" - release_version_regex=$default_regex - fi - - local awk_query_first_item_on_the_row='NR==1' - local last_release_commit=$(git log --grep=$release_version_regex --pretty=format:"%H" | awk "$awk_query_first_item_on_the_row") - - echo "$last_release_commit" -} - -# Function to add header levels based on the key -function __moshell:tools::changelog::parse_commit_format() { - local commit_hash="$1" - local author="$2" - local date="$3" - shift 3 # Shifts the first 3 arguments - local commit_message="$@" - local link_to_repository="https://github.com/andersonbosa/moshell.sh" - - # Specify the list of keys to include in the changelog - declare -a semantic_keys=("build" "chore" "docs" "feat" "fix" "perf" "refactor" "style" "test" "release") - - case "$commit_message" in - release*) - cat < - [Commit $commit_hash]($link_to_repository/commit/$commit_hash)\r -EOF - ;; - *) - echo -e "\n- $commit_message\r" - ;; - esac -} - -function __moshell:tools::changelog::parse_line_to_changelog() { - local line="$@" - - local fields_delimiter="," - IFS="$fields_delimiter" read -r -a fields <<<"$line" - - local commit_hash="${fields[0]}" - local author="${fields[1]}" - local date="${fields[2]}" - local message="${fields[3]}" - - # echo -e $commit_hash $author $date $message - __moshell:tools::changelog::parse_commit_format $commit_hash $author $date $message -} - -function __moshell:tools::changelog::main() { - LAST_RELEASE_COMMIT=$(__moshell:tools::changelog::get_last_release_commit) - - local changelog_file="$_MOSHELL_DIR_BASE_PATH/../docs/CHANGELOG.md" - local changelog_file_content_backup="" - if [ -f "$changelog_file" ]; then - changelog_file_content_backup=$(cat "$changelog_file") - fi - - # Cleans/init the file - echo '' >"$changelog_file" - - local tmp_file=$(mktemp) - git log --pretty=format:"%h,%an,%as,%s" "$LAST_RELEASE_COMMIT..HEAD" >"$tmp_file" - - local tmp_file_reversed=$(mktemp) - awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' $tmp_file >$tmp_file_reversed - # TODO: add awk as script dependency - - while IFS=$line_delimiter read -r line; do - parsed_line=$(__moshell:tools::changelog::parse_line_to_changelog $line) - # echo -e "parsed_line: $parsed_line" - # echo -e "line: $line" - echo -e "$parsed_line" >>$changelog_file - done <<<$(cat $tmp_file) - - rm $tmp_file $tmp_file_reversed &>/dev/null - # cat $tmp_file - # echo "------" - # cat $reversed_tmp_file #&>/dev/null - - echo -e "\r$changelog_file_content_backup" >>"$changelog_file" - # echo "[+] Changelog generated and saved to: '$changelog_file'" -} - -__moshell:tools::changelog::main