c084a13df266ed78602d121127d66760ef2747df

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #4259 from apjanke/jira-prefix-and-help-and-stuff

jira: prefix variable dashboard, default action, and completion

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/jira/_jira b/plugins/jira/_jira
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..b0ea658e2f3ac23079fb19166509667407741ae2
  4--- /dev/null
  5+++ b/plugins/jira/_jira
  6@@ -0,0 +1,21 @@
  7+#compdef jira
  8+#autoload
  9+
 10+local -a _1st_arguments
 11+_1st_arguments=(
 12+  'new:create a new issue'
 13+  'dashboard:open the dashboard'
 14+  'reported:search for issues reported by a user'
 15+  'assigned:search for issues assigned to a user'
 16+)
 17+
 18+_arguments -C \
 19+  ':command:->command' \
 20+  '*::options:->options'
 21+
 22+case $state in
 23+  (command)
 24+    _describe -t commands "jira subcommand" _1st_arguments
 25+    return
 26+   ;;
 27+esac
 28diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh
 29index 9a89327028a8acb9d36dbcd10a7eaf343f29a41f..89559767f86b684ea0e47a69ea363e94acf11d12 100644
 30--- a/plugins/jira/jira.plugin.zsh
 31+++ b/plugins/jira/jira.plugin.zsh
 32@@ -1,90 +1,118 @@
 33-# To use: add a .jira-url file in the base of your project
 34-#         You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory
 35-#         .jira-url in the current directory takes precedence
 36+# CLI support for JIRA interaction
 37 #
 38-# If you use Rapid Board, set:
 39-#JIRA_RAPID_BOARD="true"
 40-# in you .zshrc
 41+# Setup: 
 42+#   Add a .jira-url file in the base of your project
 43+#   You can also set $JIRA_URL in your .zshrc or put .jira-url in your home directory
 44+#   A .jira-url in the current directory takes precedence. 
 45+#   The same goes with .jira-prefix and $JIRA_PREFIX.
 46 #
 47-# Setup: cd to/my/project
 48-#        echo "https://name.jira.com" >> .jira-url
 49-# Usage: jira           # opens a new issue
 50-#        jira ABC-123   # Opens an existing issue
 51-open_jira_issue () {
 52-  if [ -f .jira-url ]; then
 53+#   For example:
 54+#     cd to/my/project
 55+#     echo "https://name.jira.com" >> .jira-url
 56+#
 57+# Variables:
 58+#  $JIRA_RAPID_BOARD     - set to "true" if you use Rapid Board
 59+#  $JIRA_DEFAULT_ACTION  - action to do when `jira` is called witn no args
 60+#                          defaults to "new"
 61+#  $JIRA_NAME            - Your JIRA username. Used as default for assigned/reported
 62+#  $JIRA_PREFIX          - Prefix added to issue ID arguments
 63+#
 64+#
 65+# Usage: 
 66+#   jira            # Performs the default action
 67+#   jira new        # opens a new issue
 68+#   jira reported [username]
 69+#   jira assigned [username]
 70+#   jira dashboard
 71+#   jira ABC-123    # Opens an existing issue
 72+#   jira ABC-123 m  # Opens an existing issue for adding a comment
 73+
 74+: ${JIRA_DEFAULT_ACTION:=new}
 75+
 76+function jira() {
 77+  local action=${1:=$JIRA_DEFAULT_ACTION}
 78+
 79+  local jira_url jira_prefix
 80+  if [[ -f .jira-url ]]; then
 81     jira_url=$(cat .jira-url)
 82-  elif [ -f ~/.jira-url ]; then
 83+  elif [[ -f ~/.jira-url ]]; then
 84     jira_url=$(cat ~/.jira-url)
 85-  elif [[ "x$JIRA_URL" != "x" ]]; then
 86-    jira_url=$JIRA_URL
 87+  elif [[ -n "${JIRA_URL}" ]]; then
 88+    jira_url=${JIRA_URL}
 89   else
 90-    echo "JIRA url is not specified anywhere."
 91+    _jira_url_help
 92     return 1
 93   fi
 94 
 95-  if [ -f .jira-prefix ]; then
 96+  if [[ -f .jira-prefix ]]; then
 97     jira_prefix=$(cat .jira-prefix)
 98-  elif [ -f ~/.jira-prefix ]; then
 99+  elif [[ -f ~/.jira-prefix ]]; then
100     jira_prefix=$(cat ~/.jira-prefix)
101+  elif [[ -n "${JIRA_PREFIX}" ]]; then
102+    jira_prefix=${JIRA_PREFIX}
103   else
104     jira_prefix=""
105   fi
106 
107-  if [ -z "$1" ]; then
108+
109+  if [[ $action == "new" ]]; then
110     echo "Opening new issue"
111     open_command "${jira_url}/secure/CreateIssue!default.jspa"
112-  elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
113-    jira_query $@
114-  else 
115-    local addcomment=''
116+  elif [[ "$action" == "assigned" || "$action" == "reported" ]]; then
117+    _jira_query $@
118+  elif [[ "$action" == "dashboard" ]]; then
119+    echo "Opening dashboard"
120+    open_command "${jira_url}/secure/Dashboard.jspa"
121+  else
122+    # Anything that doesn't match a special action is considered an issue name
123+    local issue_arg=$action
124+    local issue="${jira_prefix}${issue_arg}"
125+    local url_fragment=''
126     if [[ "$2" == "m" ]]; then
127-      addcomment="#add-comment"
128-      echo "Add comment to issue #$1"
129+      url_fragment="#add-comment"
130+      echo "Add comment to issue #$issue"
131     else