From b1da3bbc6f5e26cd0b06cd858e696d4f47f340d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Mon, 6 Jul 2015 22:00:53 +0200 Subject: [PATCH 1/6] Adding ability to add JIRA_PREFIX as an env variable (e.g. in .zshrc) and minor refactor to bash curly variable braces --- plugins/jira/jira.plugin.zsh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index ca540c84..a22e1936 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -1,6 +1,7 @@ # To use: add a .jira-url file in the base of your project # You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory -# .jira-url in the current directory takes precedence +# .jira-url in the current directory takes precedence. The same goes with .jira-prefix +# and JIRA_PREFIX. # # If you use Rapid Board, set: #JIRA_RAPID_BOARD="true" @@ -22,8 +23,8 @@ open_jira_issue () { jira_url=$(cat .jira-url) elif [ -f ~/.jira-url ]; then jira_url=$(cat ~/.jira-url) - elif [[ "x$JIRA_URL" != "x" ]]; then - jira_url=$JIRA_URL + elif [[ "${JIRA_URL}" != "" ]]; then + jira_url=${JIRA_URL} else echo "JIRA url is not specified anywhere." return 1 @@ -33,6 +34,8 @@ open_jira_issue () { jira_prefix=$(cat .jira-prefix) elif [ -f ~/.jira-prefix ]; then jira_prefix=$(cat ~/.jira-prefix) + elif [[ "${JIRA_PREFIX}" != "" ]]; then + jira_prefix=${JIRA_PREFIX} else jira_prefix="" fi @@ -51,7 +54,7 @@ open_jira_issue () { echo "Opening issue #$1" fi - if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then + if [[ "$JIRA_RAPID_BOARD" = "true" ]]; then $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment" else $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment" @@ -61,7 +64,7 @@ open_jira_issue () { jira_name () { if [[ -z "$1" ]]; then - if [[ "x${JIRA_NAME}" != "x" ]]; then + if [[ "${JIRA_NAME}" != "" ]]; then jira_name=${JIRA_NAME} else echo "JIRA_NAME not specified" From 88a30a3e2f3089556fe40c719f4cbed8426a144e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 7 Jul 2015 18:50:23 +0200 Subject: [PATCH 2/6] Changing string comparison for more zsh-like --- plugins/jira/jira.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index a22e1936..042fcd7a 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -54,7 +54,7 @@ open_jira_issue () { echo "Opening issue #$1" fi - if [[ "$JIRA_RAPID_BOARD" = "true" ]]; then + if [[ "$JIRA_RAPID_BOARD" == "true" ]]; then $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment" else $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment" From 1e99168627eef4c61114cb0572047473b7cb56be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 7 Jul 2015 19:56:22 +0200 Subject: [PATCH 3/6] Changing indents to be more consistent (2 spaces) --- plugins/jira/jira.plugin.zsh | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index 042fcd7a..769bf236 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -76,24 +76,24 @@ jira_name () { } jira_query () { - verb="$1" - if [[ "${verb}" = "reported" ]]; then - lookup=reporter - preposition=by - elif [[ "${verb}" = "assigned" ]]; then - lookup=assignee - preposition=to - else - echo "not a valid lookup $verb" - return 1 - fi - shift 1 - jira_name $@ - if [[ $? = 1 ]]; then - return 1 - fi - echo "Browsing issues ${verb} ${preposition} ${jira_name}" - $open_cmd "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC" + verb="$1" + if [[ "${verb}" = "reported" ]]; then + lookup=reporter + preposition=by + elif [[ "${verb}" = "assigned" ]]; then + lookup=assignee + preposition=to + else + echo "not a valid lookup $verb" + return 1 + fi + shift 1 + jira_name $@ + if [[ $? = 1 ]]; then + return 1 + fi + echo "Browsing issues ${verb} ${preposition} ${jira_name}" + $open_cmd "${jira_url}/secure/IssueNavigator.jspa?reset=true&jqlQuery=${lookup}+%3D+%22${jira_name}%22+AND+resolution+%3D+unresolved+ORDER+BY+priority+DESC%2C+created+ASC" } alias jira='open_jira_issue' From 37f45eb621b04a1286ac1667b7474111e6e0b4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 7 Jul 2015 20:03:58 +0200 Subject: [PATCH 4/6] Making variables local in jira plugin --- plugins/jira/jira.plugin.zsh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index 769bf236..7839e2a8 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -19,6 +19,7 @@ open_jira_issue () { open_cmd='xdg-open' fi + local jira_url if [ -f .jira-url ]; then jira_url=$(cat .jira-url) elif [ -f ~/.jira-url ]; then @@ -30,6 +31,7 @@ open_jira_issue () { return 1 fi + local jira_prefix if [ -f .jira-prefix ]; then jira_prefix=$(cat .jira-prefix) elif [ -f ~/.jira-prefix ]; then @@ -45,7 +47,7 @@ open_jira_issue () { $open_cmd "${jira_url}/secure/CreateIssue!default.jspa" elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then jira_query $@ - else + else local addcomment='' if [[ "$2" == "m" ]]; then addcomment="#add-comment" @@ -53,11 +55,11 @@ open_jira_issue () { else echo "Opening issue #$1" fi - + if [[ "$JIRA_RAPID_BOARD" == "true" ]]; then - $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment" + $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment" else - $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment" + $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment" fi fi } @@ -76,7 +78,11 @@ jira_name () { } jira_query () { + local jira_name + local verb verb="$1" + local lookup + local preposition if [[ "${verb}" = "reported" ]]; then lookup=reporter preposition=by From b1772c5333fcc43610ade75384d9cf87c8ccde61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 7 Jul 2015 20:07:13 +0200 Subject: [PATCH 5/6] More consistent curly braces variables --- plugins/jira/jira.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index 7839e2a8..566e1f1f 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -57,9 +57,9 @@ open_jira_issue () { fi if [[ "$JIRA_RAPID_BOARD" == "true" ]]; then - $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment" + $open_cmd "${jira_url}/issues/${jira_prefix}${1}${addcomment}" else - $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment" + $open_cmd "${jira_url}/browse/${jira_prefix}${1}${addcomment}" fi fi } From ad4675cb0a8f732abef7b9a2b3df2141afbf79aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 7 Jul 2015 20:26:00 +0200 Subject: [PATCH 6/6] Concise local variables declarations --- plugins/jira/jira.plugin.zsh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/jira/jira.plugin.zsh b/plugins/jira/jira.plugin.zsh index 566e1f1f..22984549 100644 --- a/plugins/jira/jira.plugin.zsh +++ b/plugins/jira/jira.plugin.zsh @@ -78,11 +78,8 @@ jira_name () { } jira_query () { - local jira_name - local verb - verb="$1" - local lookup - local preposition + local verb="$1" + local jira_name lookup preposition if [[ "${verb}" = "reported" ]]; then lookup=reporter preposition=by