From b9c4e2e82337594c2899db1f9ca005bb02fe20cd Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Fri, 31 Mar 2023 18:49:59 +1300 Subject: feat(changelog): provide links in changelog (#11578) --- tools/changelog.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 2 deletions(-) (limited to 'tools/changelog.sh') diff --git a/tools/changelog.sh b/tools/changelog.sh index a5cc468f2..5f7a14d03 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -157,6 +157,89 @@ function parse-commit { fi } +################################ +# SUPPORTS HYPERLINKS FUNCTION # +################################ + +# The code for checking if a terminal supports hyperlinks is copied from install.sh + +# The [ -t 1 ] check only works when the function is not called from +# a subshell (like in `$(...)` or `(...)`, so this hack redefines the +# function at the top level to always return false when stdout is not +# a tty. +if [ -t 1 ]; then + is_tty() { + true + } +else + is_tty() { + false + } +fi + +# This function uses the logic from supports-hyperlinks[1][2], which is +# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0. +# [1] https://github.com/zkat/supports-hyperlinks +# [2] https://crates.io/crates/supports-hyperlinks +# +# Copyright (c) 2021 Kat Marchán +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +supports_hyperlinks() { + # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass) + if [ -n "$FORCE_HYPERLINK" ]; then + [ "$FORCE_HYPERLINK" != 0 ] + return $? + fi + + # If stdout is not a tty, it doesn't support hyperlinks + is_tty || return 1 + + # DomTerm terminal emulator (domterm.org) + if [ -n "$DOMTERM" ]; then + return 0 + fi + + # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc) + if [ -n "$VTE_VERSION" ]; then + [ $VTE_VERSION -ge 5000 ] + return $? + fi + + # If $TERM_PROGRAM is set, these terminals support hyperlinks + case "$TERM_PROGRAM" in + Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + esac + + # kitty supports hyperlinks + if [ "$TERM" = xterm-kitty ]; then + return 0 + fi + + # Windows Terminal also supports hyperlinks + if [ -n "$WT_SESSION" ]; then + return 0 + fi + + # Konsole supports hyperlinks, but it's an opt-in setting that can't be detected + # https://github.com/ohmyzsh/ohmyzsh/issues/10964 + # if [ -n "$KONSOLE_VERSION" ]; then + # return 0 + # fi + + return 1 +} + ############################# # RELEASE CHANGELOG DISPLAY # ############################# @@ -208,7 +291,13 @@ function display-release { local hash="${1:-$hash}" case "$output" in raw) printf '%s' "$hash" ;; - text) printf '\e[33m%s\e[0m' "$hash" ;; # red + text) + local text="\e[33m$hash\e[0m"; # red + if supports_hyperlinks; then + printf "\e]8;;%s\a%s\e]8;;\a" "https://github.com/ohmyzsh/ohmyzsh/commit/$hash" $text; + else + echo $text; + fi ;; md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$hash" "$hash" ;; esac } @@ -272,7 +361,12 @@ function display-release { case "$output" in raw) printf '%s' "$subject" ;; # In text mode, highlight (#) and dim text between `backticks` - text) sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" ;; + text) + if supports_hyperlinks; then + sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g' <<< "$subject" + else + sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" + fi ;; # In markdown mode, link to (#) issues md) sed -E 's|#([0-9]+)|[#\1](https://github.com/ohmyzsh/ohmyzsh/issues/\1)|g' <<< "$subject" ;; esac -- cgit v1.2.3-70-g09d2 From c7bb88f9ad3eb742aecca2e36b615819cead10f4 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 3 Apr 2023 23:27:14 +0200 Subject: fix(changelog): ignore lines containing whitespace in breaking change commits --- tools/changelog.sh | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools/changelog.sh') diff --git a/tools/changelog.sh b/tools/changelog.sh index 5f7a14d03..1af74e42d 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -106,6 +106,9 @@ function parse-commit { message="${match[1]}" # remove CR characters (might be inserted in GitHub UI commit description form) message="${message//$'\r'/}" + # remove lines containing only whitespace + local nlnl=$'\n\n' + message="${message//$'\n'[[:space:]]##$'\n'/$nlnl}" # skip next paragraphs (separated by two newlines or more) message="${message%%$'\n\n'*}" # ... and replace newlines with spaces -- cgit v1.2.3-70-g09d2 From bbda81fe4b338f00bbf7c7f33e6d1b12d067dc05 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 13 Sep 2023 19:23:41 +0200 Subject: fix(changelog): fix regression for unstyled code in commit subjects --- tools/changelog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/changelog.sh') diff --git a/tools/changelog.sh b/tools/changelog.sh index 1af74e42d..6d768963e 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -366,7 +366,7 @@ function display-release { # In text mode, highlight (#) and dim text between `backticks` text) if supports_hyperlinks; then - sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g' <<< "$subject" + sed -E $'s|#([0-9]+)|\e]8;;https://github.com/ohmyzsh/ohmyzsh/issues/\\1\a\e[32m#\\1\e[0m\e]8;;\a|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" else sed -E $'s|#([0-9]+)|\e[32m#\\1\e[0m|g;s|`([^`]+)`|`\e[2m\\1\e[0m`|g' <<< "$subject" fi ;; -- cgit v1.2.3-70-g09d2