From f341c8c20646bd82d5d84fae32f68b760e0f1be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Tue, 7 Sep 2021 17:08:46 +0200 Subject: [PATCH] feat(changelog): print BREAKING CHANGE messages in a prettier way --- tools/changelog.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/changelog.sh b/tools/changelog.sh index b4b8d0c9e..966e91c25 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -181,6 +181,12 @@ function display-release { return 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 # Format the hash according to output format @@ -220,18 +226,13 @@ function display-release { #* Uses $scopes (A) and $hash from outer scope 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 [[ $max_scope -eq 0 ]]; then return fi # Get how much padding is required for this scope + local padding=0 padding=$(( max_scope < ${#scope} ? 0 : max_scope - ${#scope} )) padding="${(r:$padding:: :):-}" @@ -290,11 +291,15 @@ function display-release { md) fmt:header "BREAKING CHANGES ⚠" 3 ;; esac - local hash subject + local hash message + local wrap_width=$(( (COLUMNS < 100 ? COLUMNS : 100) - 3 )) for hash message in ${(kv)breaking}; do - echo " - $(fmt:hash) $(fmt:scope)$(fmt:subject "${message}")" - done | sort - echo + # Format the BREAKING CHANGE message by word-wrapping it at maximum 100 characters + # (use $COLUMNS if smaller than 100), and adding a 3-space left padding. + 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 {