Adapt changelog script for pr title styles

This commit is contained in:
Bnyro 2023-07-08 15:22:26 +02:00
parent 1ebb342537
commit e2b5b8d7ed

View File

@ -4,61 +4,34 @@
# read the file
TEXT=$(<"$1")
# remove weblate and dependencies
TEXT=$(printf "${TEXT[@]}" | sed 's/.*Weblate.*//g' | sed 's/.*dependency.*//g')
# the link containing the full commit history
FULLCHANGELOG=$(echo "$TEXT{@}" | tail -n 1)
NEWCONTRIBUTORS=$(echo "$TEXT{@}" | grep 'first contribution')
# remove everything related to weblate and dependencies
TEXT=$(printf "${TEXT[@]}" | sed -e 's/.*Weblate.*//g' -e 's/.*dependency.*//g' -e 's/^\*\*Full//g' -e 's/.*first contribution.*//g' -e 's/##.*//g')
# go through all the lines inside the file
readarray -t y <<< "${TEXT[@]}"
FIXES=()
FEATURES=()
IMPROVEMENTS=()
REPOCHANGES=()
for line in "${y[@]}" ; do
if [[ "$line" =~ [Ff]ix ]]; then
FIXES+=("$line")
elif [[ "$line" =~ [Oo]ption ]] || [[ "$line" =~ [Mm]inor ]]; then
IMPROVEMENTS+=("$line")
elif [[ "$line" =~ [Rr][Ee][Aa][Dd][Mm][Ee] ]] || [[ "$line" =~ [Ss]creenshots ]] || [[ "$line" =~ Clean( )?up ]]; then
REPOCHANGES+=("$line")
elif [[ "$line" =~ ^\*\*Full ]]; then
FULLCHANGELOG="$line"
elif ! [[ -z "$line" ]]; then
FEATURES+=("$line")
fi
done
# function for echoing all items of an array, one per line
echoall() {
for line in "$@"; do
echo "$line"
done
trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
# Print all the found and categorized changes
create_changelog() {
echo "## New features"
echoall "${FEATURES[@]}"
echo ""
echo "## Minor changes"
echoall "${IMPROVEMENTS[@]}"
echo ""
echo "## Bug fixes"
echoall "${FIXES[@]}"
echo ""
echo "## Repo changes"
echoall "${REPOCHANGES[@]}"
echo ""
echo "$FULLCHANGELOG"
trim "$(echo "$TEXT" | sort)"
[ "$NEWCONTRIBUTORS" ] && echo -e "\n\n## New contributors\n$NEWCONTRIBUTORS"
echo -e "\n\n$FULLCHANGELOG"
}
# generate a new changelog
CHANGELOG=$(create_changelog)
# write the changelog into the file
echo "$CHANGELOG" > "$1"
echo "Done."
# Output the generated changelog
echo "$CHANGELOG"