-
-
Save jkereako/dc71f5301faefb4fdd047003ed03beac to your computer and use it in GitHub Desktop.
Opens the current branch name in JIRA.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# JIRA | |
# Copyright (c) 2018 - Jeff Kereakoglow | |
# | |
# Opens the current branch name in JIRA. | |
set -Eeuo pipefail | |
readonly COMPANY_NAME="yourdamncompanyname" | |
# Print out error messages to stderr. | |
function err() { | |
echo -e "\033[0;31mERROR: $@\033[0m" >&2; | |
} | |
function check_git() { | |
if ! git rev-parse --git-dir 1> /dev/null; then | |
err "Current directory is not tracked with Git"; exit 2; | |
fi; | |
} | |
function check_http_status() { | |
status=$(curl -s -o /dev/null -w "%{http_code}" "${url}") | |
# Don't attempt to open invalid URLs | |
if (( $status >= 400 && $status <= 599 )); then | |
err "URL ${url} cannot be found or JIRA is down"; exit 2; | |
fi | |
} | |
#-- Main | |
function main() { | |
args="$@" | |
check_git | |
base_url="https://${COMPANY_NAME}.atlassian.net/browse" | |
branch=$(git symbolic-ref --short HEAD) | |
# Branches often have prefixes like "feature/" or "bugfix/". Executing | |
# `basename` on the branch solves this problem. | |
ticket_id=$(basename $branch) | |
url="${base_url}/${ticket_id}" | |
check_http_status $url | |
echo "Opening ${url}" | |
open $url | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Opens the current branch name in JIRA.
First, the script verifies that the current directory tree is tracked with Git. If so, it verifies that Jira is reachable. If so, it opens Jira in your default browser.
Usage
It's meant to be simple:
Installation
Download the script and make it executable (
chmod +x jira
). I recommend to place this script in a subdirectory of home namedbin
. Create the directorybin
and then edit.zshrc
to add it to your path:Requirements
JIRA-1234
JIRA-1234-my-new-haircut
(Jira is smart enough to parse-out the ticket ID)feature/vinnybagadoughnuts/JIRA-1234