feat(changelog): print BREAKING CHANGE messages in a prettier way

This commit is contained in:
Marc Cornellà 2021-09-07 17:08:46 +02:00
parent af271c9e38
commit f341c8c206
No known key found for this signature in database
GPG Key ID: 0314585E776A9C1B

View File

@ -181,6 +181,12 @@ function display-release {
return return
fi fi
# Get length of longest scope for padding
local max_scope=0
for hash in ${(k)scopes}; do
max_scope=$(( max_scope < ${#scopes[$hash]} ? ${#scopes[$hash]} : max_scope ))
done
##* Formatting functions ##* Formatting functions
# Format the hash according to output format # Format the hash according to output format
@ -220,18 +226,13 @@ function display-release {
#* Uses $scopes (A) and $hash from outer scope #* Uses $scopes (A) and $hash from outer scope
local scope="${1:-${scopes[$hash]}}" local scope="${1:-${scopes[$hash]}}"
# Get length of longest scope for padding
local max_scope=0 padding=0
for hash in ${(k)scopes}; do
max_scope=$(( max_scope < ${#scopes[$hash]} ? ${#scopes[$hash]} : max_scope ))
done
# If no scopes, exit the function # If no scopes, exit the function
if [[ $max_scope -eq 0 ]]; then if [[ $max_scope -eq 0 ]]; then
return return
fi fi
# Get how much padding is required for this scope # Get how much padding is required for this scope
local padding=0
padding=$(( max_scope < ${#scope} ? 0 : max_scope - ${#scope} )) padding=$(( max_scope < ${#scope} ? 0 : max_scope - ${#scope} ))
padding="${(r:$padding:: :):-}" padding="${(r:$padding:: :):-}"
@ -290,11 +291,15 @@ function display-release {
md) fmt:header "BREAKING CHANGES ⚠" 3 ;; md) fmt:header "BREAKING CHANGES ⚠" 3 ;;
esac esac
local hash subject local hash message
local wrap_width=$(( (COLUMNS < 100 ? COLUMNS : 100) - 3 ))
for hash message in ${(kv)breaking}; do for hash message in ${(kv)breaking}; do
echo " - $(fmt:hash) $(fmt:scope)$(fmt:subject "${message}")" # Format the BREAKING CHANGE message by word-wrapping it at maximum 100 characters
done | sort # (use $COLUMNS if smaller than 100), and adding a 3-space left padding.
echo message="$(fmt -w $wrap_width <<< "$message" | sed 's/^/ /')"
# Display hash and scope first, and then the full message with newline separators
echo " - $(fmt:hash) $(fmt:scope)\n\n$(fmt:subject "$message")\n"
done
} }
function display:type { function display:type {