7cf892ecaa86f064aa3f78b9d5bee3b7db208ca4

Author
Andrew Janke <andrew@apjanke.net>
Committer
Andrew Janke <andrew@apjanke.net>
Date

Message

Add dashboard support and default-action configuration.
Some refactoring.

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh
  2index 842dff5c76f7f2a7076557094f41887fef8df899..a10feec3e1420a8e675864dadf96b536c7c425a0 100644
  3--- a/plugins/jira/jira.plugin.zsh
  4+++ b/plugins/jira/jira.plugin.zsh
  5@@ -1,61 +1,88 @@
  6-# To use: add a .jira-url file in the base of your project
  7-#         You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory
  8-#         .jira-url in the current directory takes precedence. The same goes with .jira-prefix
  9-#         and JIRA_PREFIX.
 10+# CLI support for JIRA interaction
 11 #
 12-# If you use Rapid Board, set:
 13-#JIRA_RAPID_BOARD="true"
 14-# in you .zshrc
 15+# Setup: 
 16+#   Add a .jira-url file in the base of your project
 17+#   You can also set $JIRA_URL in your .zshrc or put .jira-url in your home directory
 18+#   A .jira-url in the current directory takes precedence. 
 19+#   The same goes with .jira-prefix and $JIRA_PREFIX.
 20 #
 21-# Setup: cd to/my/project
 22-#        echo "https://name.jira.com" >> .jira-url
 23-# Usage: jira           # opens a new issue
 24-#        jira ABC-123   # Opens an existing issue
 25-open_jira_issue () {
 26-  if [ -f .jira-url ]; then
 27+#   For example:
 28+#     cd to/my/project
 29+#     echo "https://name.jira.com" >> .jira-url
 30+#
 31+# Variables:
 32+#  $JIRA_RAPID_BOARD     - set to "true" if you use Rapid Board
 33+#  $JIRA_DEFAULT_ACTION  - action to do when `jira` is called witn no args
 34+#                          defaults to "new"
 35+#  $JIRA_NAME            - Your JIRA username. Used as default for assigned/reported
 36+#  $JIRA_PREFIX          - Prefix added to issue ID arguments
 37+#
 38+#
 39+# Usage: 
 40+#   jira            # Performs the default action
 41+#   jira new        # opens a new issue
 42+#   jira reported [username]
 43+#   jira assigned [username]
 44+#   jira dashboard
 45+#   jira ABC-123    # Opens an existing issue
 46+#   jira ABC-123 m  # Opens an existing issue for adding a comment
 47+
 48+: ${JIRA_DEFAULT_ACTION:=new}
 49+
 50+function jira() {
 51+  local action=${1:=$JIRA_DEFAULT_ACTION}
 52+
 53+  local jira_url jira_prefix
 54+  if [[ -f .jira-url ]]; then
 55     jira_url=$(cat .jira-url)
 56-  elif [ -f ~/.jira-url ]; then
 57+  elif [[ -f ~/.jira-url ]]; then
 58     jira_url=$(cat ~/.jira-url)
 59-  elif [[ "${JIRA_URL}" != "" ]]; then
 60+  elif [[ -n "${JIRA_URL}" ]]; then
 61     jira_url=${JIRA_URL}
 62   else
 63     jira_url_help
 64     return 1
 65   fi
 66 
 67-  local jira_prefix
 68-  if [ -f .jira-prefix ]; then
 69+  if [[ -f .jira-prefix ]]; then
 70     jira_prefix=$(cat .jira-prefix)
 71-  elif [ -f ~/.jira-prefix ]; then
 72+  elif [[ -f ~/.jira-prefix ]]; then
 73     jira_prefix=$(cat ~/.jira-prefix)
 74-  elif [[ "${JIRA_PREFIX}" != "" ]]; then
 75+  elif [[ -n "${JIRA_PREFIX}" ]]; then
 76     jira_prefix=${JIRA_PREFIX}
 77   else
 78     jira_prefix=""
 79   fi
 80 
 81-  if [ -z "$1" ]; then
 82+
 83+  if [[ $action == "new" ]]; then
 84     echo "Opening new issue"
 85     open_command "${jira_url}/secure/CreateIssue!default.jspa"
 86-  elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
 87+  elif [[ "$action" == "assigned" || "$action" == "reported" ]]; then
 88     jira_query $@
 89+  elif [[ "$action" == "dashboard" ]]; then
 90+    echo "Opening dashboard"
 91+    open_command "${jira_url}/secure/Dashboard.jspa"
 92   else
 93-    local addcomment=''
 94+    # Anything that doesn't match a special action is considered an issue name
 95+    local issue_arg=$action
 96+    local issue="${jira_prefix}${issue_arg}"
 97+    local url_fragment=''
 98     if [[ "$2" == "m" ]]; then
 99-      addcomment="#add-comment"
100-      echo "Add comment to issue #$1"
101+      url_fragment="#add-comment"
102+      echo "Add comment to issue #$issue"
103     else
104-      echo "Opening issue #$1"