1 # CLI support for JIRA interaction
3 # See README.md for details
7 local action jira_url jira_prefix
10 elif [[ -f .jira-default-action ]]; then
11 action=$(cat .jira-default-action)
12 elif [[ -f ~/.jira-default-action ]]; then
13 action=$(cat ~/.jira-default-action)
14 elif [[ -n "${JIRA_DEFAULT_ACTION}" ]]; then
15 action=${JIRA_DEFAULT_ACTION}
20 if [[ -f .jira-url ]]; then
21 jira_url=$(cat .jira-url)
22 elif [[ -f ~/.jira-url ]]; then
23 jira_url=$(cat ~/.jira-url)
24 elif [[ -n "${JIRA_URL}" ]]; then
31 if [[ -f .jira-prefix ]]; then
32 jira_prefix=$(cat .jira-prefix)
33 elif [[ -f ~/.jira-prefix ]]; then
34 jira_prefix=$(cat ~/.jira-prefix)
35 elif [[ -n "${JIRA_PREFIX}" ]]; then
36 jira_prefix=${JIRA_PREFIX}
42 if [[ $action == "new" ]]; then
43 echo "Opening new issue"
44 open_command "${jira_url}/secure/CreateIssue!default.jspa"
45 elif [[ "$action" == "assigned" || "$action" == "reported" ]]; then
46 _jira_query ${@:-$action}
47 elif [[ "$action" == "myissues" ]]; then
48 echo "Opening my issues"
49 open_command "${jira_url}/issues/?filter=-1"
50 elif [[ "$action" == "dashboard" ]]; then
51 echo "Opening dashboard"
52 if [[ "$JIRA_RAPID_BOARD" == "true" ]]; then
53 open_command "${jira_url}/secure/RapidBoard.jspa"
55 open_command "${jira_url}/secure/Dashboard.jspa"
57 elif [[ "$action" == "tempo" ]]; then
59 open_command "${jira_url}/secure/Tempo.jspa"
60 elif [[ "$action" == "dumpconfig" ]]; then
61 echo "JIRA_URL=$jira_url"
62 echo "JIRA_PREFIX=$jira_prefix"
63 echo "JIRA_NAME=$JIRA_NAME"
64 echo "JIRA_RAPID_BOARD=$JIRA_RAPID_BOARD"
65 echo "JIRA_DEFAULT_ACTION=$JIRA_DEFAULT_ACTION"
67 # Anything that doesn't match a special action is considered an issue name
68 # but `branch` is a special case that will parse the current git branch
70 if [[ "$action" == "branch" ]]; then
71 # Get name of the branch
72 issue_arg=$(git rev-parse --abbrev-ref HEAD)
73 # Strip prefixes like feature/ or bugfix/
74 issue_arg=${issue_arg##*/}
75 # Strip suffixes starting with _
76 issue_arg=(${(s:_:)issue_arg})
77 issue_arg=${issue_arg[1]}
78 if [[ "$issue_arg" = ${jira_prefix}* ]]; then
81 issue="${jira_prefix}${issue_arg}"
84 issue_arg=${(U)action}
85 issue="${jira_prefix}${issue_arg}"
89 if [[ "$2" == "m" ]]; then
90 url_fragment="#add-comment"
91 echo "Add comment to issue #$issue"
93 echo "Opening issue #$issue"
95 open_command "${jira_url}/browse/${issue}${url_fragment}"
99 function _jira_url_help() {
101 error: JIRA URL is not specified anywhere.
103 Valid options, in order of precedence:
105 \$HOME/.jira-url file
106 \$JIRA_URL environment variable
110 function _jira_query() {
113 local jira_name lookup preposition query
114 if [[ "${verb}" == "reported" ]]; then
117 elif [[ "${verb}" == "assigned" ]]; then
121 echo "error: not a valid lookup: $verb" >&2
124 jira_name=${2:=$JIRA_NAME}
125 if [[ -z $jira_name ]]; then
126 echo "error: JIRA_NAME not specified" >&2
130 echo "Browsing issues ${verb} ${preposition} ${jira_name}"
131 query="${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC"
132 open_command "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${query}"