480f1ecd965c730890492ac9384fe50e193fd98f

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Merge branch 'update/jira-plugin'

Closes #6506
Closes #6950
Closes #7962

Diff

 1diff --git a/plugins/jira/README.md b/plugins/jira/README.md
 2index 091dccb97dd3db8a1e265c76fa4486bc8395fd86..a211e34e0042b1f1403925353e261f2e8863700c 100644
 3--- a/plugins/jira/README.md
 4+++ b/plugins/jira/README.md
 5@@ -23,6 +23,9 @@ jira reported [username]  # queries for issues reported by a user
 6 jira assigned [username]  # queries for issues assigned to a user
 7 jira myissues   # queries for you own issues
 8 jira branch     # opens an existing issue matching the current branch name
 9+                # The branch name may have prefixes ending in "/": "feature/MP-1234",
10+                # and also suffixes starting with "_": "MP-1234_fix_dashboard"
11+                # In both these cases, the issue opened will be "MP-1234"
12 jira ABC-123    # opens an existing issue
13 jira ABC-123 m  # opens an existing issue for adding a comment
14 ```
15diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh
16index e706948e9f5fbe0829d07bec90d61ae04112afd1..cb46f540b9b117d69d44c9b11f4b27303b3c5d5d 100644
17--- a/plugins/jira/jira.plugin.zsh
18+++ b/plugins/jira/jira.plugin.zsh
19@@ -63,25 +63,33 @@ function jira() {
20   else
21     # Anything that doesn't match a special action is considered an issue name
22     # but `branch` is a special case that will parse the current git branch
23+    local issue_arg issue
24     if [[ "$action" == "branch" ]]; then
25-      local issue_arg=$(git rev-parse --abbrev-ref HEAD)
26-      local issue="${jira_prefix}${issue_arg}"
27+      # Get name of the branch
28+      issue_arg=$(git rev-parse --abbrev-ref HEAD)
29+      # Strip prefixes like feature/ or bugfix/
30+      issue_arg=${issue_arg##*/}
31+      # Strip suffixes starting with _
32+      issue_arg=(${(s:_:)issue_arg})
33+      issue_arg=${issue_arg[1]}
34+      if [[ "$issue_arg" = ${jira_prefix}* ]]; then
35+        issue="${issue_arg}"
36+      else
37+        issue="${jira_prefix}${issue_arg}"
38+      fi
39     else
40-      local issue_arg=$action
41-      local issue="${jira_prefix}${issue_arg}"
42+      issue_arg=${(U)action}
43+      issue="${jira_prefix}${issue_arg}"
44     fi
45-    local url_fragment=''
46+
47+    local url_fragment
48     if [[ "$2" == "m" ]]; then
49       url_fragment="#add-comment"
50       echo "Add comment to issue #$issue"
51     else
52       echo "Opening issue #$issue"
53     fi
54-    if [[ "$JIRA_RAPID_BOARD" == "true" ]]; then
55-      open_command "${jira_url}/issues/${issue}${url_fragment}"
56-    else
57-      open_command "${jira_url}/browse/${issue}${url_fragment}"
58-    fi
59+    open_command "${jira_url}/browse/${issue}${url_fragment}"
60   fi
61 }
62