jira.plugin.zsh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # To use: add a .jira-url file in the base of your project
  2. # You can also set JIRA_URL in your .zshrc or put .jira-url in your home directory
  3. # .jira-url in the current directory takes precedence
  4. #
  5. # If you use Rapid Board, set:
  6. #JIRA_RAPID_BOARD="true"
  7. # in you .zshrc
  8. #
  9. # Setup: cd to/my/project
  10. # echo "https://name.jira.com" >> .jira-url
  11. # Usage: jira # opens a new issue
  12. # jira ABC-123 # Opens an existing issue
  13. open_jira_issue () {
  14. local open_cmd
  15. if [[ "$OSTYPE" = darwin* ]]; then
  16. open_cmd='open'
  17. else
  18. open_cmd='xdg-open'
  19. fi
  20. if [ -f .jira-url ]; then
  21. jira_url=$(cat .jira-url)
  22. elif [ -f ~/.jira-url ]; then
  23. jira_url=$(cat ~/.jira-url)
  24. elif [[ "x$JIRA_URL" != "x" ]]; then
  25. jira_url=$JIRA_URL
  26. else
  27. echo "JIRA url is not specified anywhere."
  28. return 1
  29. fi
  30. if [ -f .jira-prefix ]; then
  31. jira_prefix=$(cat .jira-prefix)
  32. elif [ -f ~/.jira-prefix ]; then
  33. jira_prefix=$(cat ~/.jira-prefix)
  34. else
  35. jira_prefix=""
  36. fi
  37. if [ -z "$1" ]; then
  38. echo "Opening new issue"
  39. $open_cmd "${jira_url}/secure/CreateIssue!default.jspa"
  40. elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
  41. jira_query $@
  42. else
  43. echo "Opening issue #$1"
  44. if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
  45. $open_cmd "$jira_url/issues/$jira_prefix$1"
  46. else
  47. $open_cmd "$jira_url/browse/$jira_prefix$1"
  48. fi
  49. else
  50. local addcomment=''
  51. if [[ "$2" == "m" ]]; then
  52. addcomment="#add-comment"
  53. echo "Add comment to issue #$1"
  54. else
  55. echo "Opening issue #$1"
  56. fi
  57. if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
  58. $open_cmd "$jira_url/issues/$1$addcomment"
  59. else
  60. $open_cmd "$jira_url/browse/$1$addcomment"
  61. fi
  62. fi
  63. }
  64. jira_name () {
  65. if [[ -z "$1" ]]; then
  66. if [[ "x${JIRA_NAME}" != "x" ]]; then
  67. jira_name=${JIRA_NAME}
  68. else
  69. echo "JIRA_NAME not specified"
  70. return 1
  71. fi
  72. else
  73. jira_name=$@
  74. fi
  75. }
  76. jira_query () {
  77. verb="$1"
  78. if [[ "${verb}" = "reported" ]]; then
  79. lookup=reporter
  80. preposition=by
  81. elif [[ "${verb}" = "assigned" ]]; then
  82. lookup=assignee
  83. preposition=to
  84. else
  85. echo "not a valid lookup $verb"
  86. return 1
  87. fi
  88. shift 1
  89. jira_name $@
  90. if [[ $? = 1 ]]; then
  91. return 1
  92. fi
  93. echo "Browsing issues ${verb} ${preposition} ${jira_name}"
  94. $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"
  95. }
  96. alias jira='open_jira_issue'