Skip to content

Instantly share code, notes, and snippets.

@dharFr dharFr/README.md
Last active Mar 26, 2017

Embed
What would you like to do?
Open JIRA from the terminal

Setup

  • Copy/Paste the function defined in jira.sh in you .bash_profile or .bashrc
  • Export JIRA_ROOT variable in your environemnt (most likely in your .bash_profile/.bashrc as well) : export JIRA_ROOT='https://jira.yourdomain.com/'

Usage

jira [issue]

Without any parameter, it check if you're currently in a git repository and opens either the JIRA issue named by the current branch name or JIRA root domain. When a parameter is provided, opens the JIRA issue named by the parameter.

# JIRA link from the command-line
# Open JIRA according to either the current git branch or the provided parameter
#
# Usage: jira [options] open the current branch name as a JIRA issue
# or: jira [options] [issue] open the given JIRA issue
#
# Options:
# -h | --help : Display help
# -l | --link : Output issue URL to std out instead of opening it in the browser
#
# Setup:
# Set JIRA_ROOT variable in your environment before use
# e.g : export JIRA_ROOT='https://jira.yourdomain.com/'
#
# See : https://gist.github.com/dharFr/ff092917ffad831f9a38
function jira {
if [ -z $JIRA_ROOT ]; then
echo "Please set JIRA_ROOT variable in your environment";
echo " e.g : export JIRA_ROOT='https://jira.yourdomain.com/'";
return 1;
fi
usage() {
echo "JIRA link from the command-line"
echo "Open JIRA according to either the current git branch or the provided parameter"
echo ""
echo "Usage: jira [options] open the current branch name as a JIRA issue"
echo " or: jira [options] [issue] open the given JIRA issue"
echo ""
echo "Options: "
echo " -h | --help : Display help"
echo " -l | --link : Output issue URL to std out instead of opening it in the browser"
echo ""
echo "Setup: "
echo "Set JIRA_ROOT variable in your environment before use"
echo " e.g : export JIRA_ROOT='https://jira.yourdomain.com/'"
echo ""
echo "See : https://gist.github.com/dharFr/ff092917ffad831f9a38"
}
local __issue;
local __open=true;
local __branch=`git symbolic-ref --short HEAD 2> /dev/null`;
while [ "$1" != "" ]; do
case $1 in
-l | --link ) __open=false
;;
-h | --help ) usage
return 1
;;
* ) __issue=$1
;;
esac
shift
done
if [ -z $__issue ] && [ ! -z $__branch ]; then
__issue=$__branch
fi
local __url="${JIRA_ROOT}";
if [ ! -z $__issue ]; then
__url="${__url}browse/${__issue}";
fi
if $__open; then
open $__url;
else
echo $__url;
fi
}
@dharFr

This comment has been minimized.

Copy link
Owner Author

dharFr commented Apr 6, 2016

I often use it along with the handy jira2md function bellow, so I can jira2md | pbcopy and then paste the markdown link directly in a github comment for example.

# Markdown formatted JIRA link from the command-line
# output a markdown link to a JIRA issue according to either the current git branch or the provided parameter
#
# Usage: jira2md          open the current branch name as a JIRA issue
#    or: jira2md [issue]  open the given JIRA issue
function jira2md {
  local __link=`jira -l $1`
  local __label=`echo $__link | sed 's/^.*browse\///'`
  echo "[$__label]($__link)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.