summaryrefslogtreecommitdiff
path: root/plugins/jira/jira.plugin.zsh
diff options
context:
space:
mode:
authorKen van der Eerden <15888558+Ken-vdE@users.noreply.github.com>2025-01-23 21:08:55 +0100
committerGitHub <noreply@github.com>2025-01-23 21:08:55 +0100
commit5fd2059e5eda17ee07501a21d47189d4b96d6ff3 (patch)
tree43f8a75ffcaa29876e83fe2fd2ed30ec324804a6 /plugins/jira/jira.plugin.zsh
parent85c49414926ad86f76d7bad3635f948bb5f883cb (diff)
downloadzsh-5fd2059e5eda17ee07501a21d47189d4b96d6ff3.tar.gz
zsh-5fd2059e5eda17ee07501a21d47189d4b96d6ff3.tar.bz2
zsh-5fd2059e5eda17ee07501a21d47189d4b96d6ff3.zip
feat(jira): allow branch name customization (#12850)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diffstat (limited to 'plugins/jira/jira.plugin.zsh')
-rw-r--r--plugins/jira/jira.plugin.zsh43
1 files changed, 25 insertions, 18 deletions
diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh
index 9bcf4cc7b..22e0c82c7 100644
--- a/plugins/jira/jira.plugin.zsh
+++ b/plugins/jira/jira.plugin.zsh
@@ -17,6 +17,30 @@ jira branch Opens an existing issue matching the current bra
EOF
}
+# If your branch naming convention deviates, you can partially override this plugin function
+# to determine the jira issue key based on your formatting.
+# See https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#partially-overriding-an-existing-plugin
+function jira_branch() {
+ # Get name of the branch
+ issue_arg=$(git rev-parse --abbrev-ref HEAD)
+ # Strip prefixes like feature/ or bugfix/
+ issue_arg=${issue_arg##*/}
+ # Strip suffixes starting with _
+ issue_arg=(${(s:_:)issue_arg})
+ # If there is only one part, it means that there is a different delimiter. Try with -
+ if [[ ${#issue_arg[@]} = 1 && ${issue_arg} == *-* ]]; then
+ issue_arg=(${(s:-:)issue_arg})
+ issue_arg="${issue_arg[1]}-${issue_arg[2]}"
+ else
+ issue_arg=${issue_arg[1]}
+ fi
+ if [[ "${issue_arg:l}" = ${jira_prefix:l}* ]]; then
+ echo "${issue_arg}"
+ else
+ echo "${jira_prefix}${issue_arg}"
+ fi
+}
+
function jira() {
emulate -L zsh
local action jira_url jira_prefix
@@ -91,24 +115,7 @@ function jira() {
# but `branch` is a special case that will parse the current git branch
local issue_arg issue
if [[ "$action" == "branch" ]]; then
- # Get name of the branch
- issue_arg=$(git rev-parse --abbrev-ref HEAD)
- # Strip prefixes like feature/ or bugfix/
- issue_arg=${issue_arg##*/}
- # Strip suffixes starting with _
- issue_arg=(${(s:_:)issue_arg})
- # If there is only one part, it means that there is a different delimiter. Try with -
- if [[ ${#issue_arg[@]} = 1 && ${issue_arg} == *-* ]]; then
- issue_arg=(${(s:-:)issue_arg})
- issue_arg="${issue_arg[1]}-${issue_arg[2]}"
- else
- issue_arg=${issue_arg[1]}
- fi
- if [[ "${issue_arg:l}" = ${jira_prefix:l}* ]]; then
- issue="${issue_arg}"
- else
- issue="${jira_prefix}${issue_arg}"
- fi
+ issue=$(jira_branch)
else
issue_arg=${(U)action}
issue="${jira_prefix}${issue_arg}"