feat(changelog): provide links in changelog (#11578)

This commit is contained in:
Guy Sartorelli 2023-03-31 18:49:59 +13:00 committed by GitHub
parent 7837ba6a99
commit b9c4e2e823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 (#<issue>) 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 (#<issue>) issues
md) sed -E 's|#([0-9]+)|[#\1](https://github.com/ohmyzsh/ohmyzsh/issues/\1)|g' <<< "$subject" ;;
esac