jira.plugin.zsh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 [[ $(uname -s) == '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. fi
  50. }
  51. jira_name () {
  52. if [[ -z "$1" ]]; then
  53. if [[ "x${JIRA_NAME}" != "x" ]]; then
  54. jira_name=${JIRA_NAME}
  55. else
  56. echo "JIRA_NAME not specified"
  57. return 1
  58. fi
  59. else
  60. jira_name=$@
  61. fi
  62. }
  63. jira_query () {
  64. verb="$1"
  65. if [[ "${verb}" = "reported" ]]; then
  66. lookup=reporter
  67. preposition=by
  68. elif [[ "${verb}" = "assigned" ]]; then
  69. lookup=assignee
  70. preposition=to
  71. else
  72. echo "not a valid lookup $verb"
  73. return 1
  74. fi
  75. shift 1
  76. jira_name $@
  77. if [[ $? = 1 ]]; then
  78. return 1
  79. fi
  80. echo "Browsing issues ${verb} ${preposition} ${jira_name}"
  81. $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"
  82. }
  83. alias jira='open_jira_issue'