2021-07-19 13:19:04 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# jira - jump to a Jira ticket in the browser, based on Git branch name convention.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [ -z "$JIRADOMAIN" ]; then
|
2023-10-07 08:43:32 +00:00
|
|
|
# shellcheck disable=SC2016
|
2021-07-19 13:19:04 +00:00
|
|
|
echo 'set $JIRADOMAIN first'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-07 08:43:32 +00:00
|
|
|
if ! branchname="$(branchname)"; then
|
2021-07-20 07:52:24 +00:00
|
|
|
echo "branchname returned exit code: $?"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-07-19 13:19:04 +00:00
|
|
|
if ! echo "$branchname" | grep -q "/"; then
|
|
|
|
echo "no ticket number found in branch name: $branchname"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ticket=$(echo "$branchname" | cut -d "/" -f1 | tr '[:lower:]' '[:upper:]')
|
2021-07-20 07:52:24 +00:00
|
|
|
url="$JIRADOMAIN/browse/$ticket"
|
|
|
|
|
|
|
|
if [ "$1" == "-b" ]; then
|
2023-10-07 08:43:32 +00:00
|
|
|
if [ "$(uname -s)" = "Linux" ]; then
|
2021-07-20 07:52:24 +00:00
|
|
|
progname="xdg-open"
|
|
|
|
else
|
|
|
|
progname="open" # macOS
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval "$progname $url"
|
|
|
|
exit $?
|
2021-07-19 13:19:04 +00:00
|
|
|
fi
|
|
|
|
|
2023-10-07 08:43:32 +00:00
|
|
|
printf "%s" "$url"
|