dotfiles/script/jira

39 lines
701 B
Bash
Executable File

#!/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
echo 'set $JIRADOMAIN first'
exit 1
fi
branchname="$(branchname)"
if [ ! $? -eq 0 ]; then
echo "branchname returned exit code: $?"
exit 1
fi
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:]')
url="$JIRADOMAIN/browse/$ticket"
if [ "$1" == "-b" ]; then
if [ $(uname -s) = "Linux" ]; then
progname="xdg-open"
else
progname="open" # macOS
fi
eval "$progname $url"
exit $?
fi
printf $url