jira.plugin.zsh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. local addcomment=''
  44. if [[ "$2" == "m" ]]; then
  45. addcomment="#add-comment"
  46. echo "Add comment to issue #$1"
  47. else
  48. echo "Opening issue #$1"
  49. fi
  50. if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
  51. $open_cmd "$jira_url/issues/$jira_prefix$1$addcomment"
  52. else
  53. $open_cmd "$jira_url/browse/$jira_prefix$1$addcomment"
  54. fi
  55. fi
  56. }
  57. jira_name () {
  58. if [[ -z "$1" ]]; then
  59. if [[ "x${JIRA_NAME}" != "x" ]]; then
  60. jira_name=${JIRA_NAME}
  61. else
  62. echo "JIRA_NAME not specified"
  63. return 1
  64. fi
  65. else
  66. jira_name=$@
  67. fi
  68. }
  69. jira_query () {
  70. verb="$1"
  71. if [[ "${verb}" = "reported" ]]; then
  72. lookup=reporter
  73. preposition=by
  74. elif [[ "${verb}" = "assigned" ]]; then
  75. lookup=assignee
  76. preposition=to
  77. else
  78. echo "not a valid lookup $verb"
  79. return 1
  80. fi
  81. shift 1
  82. jira_name $@
  83. if [[ $? = 1 ]]; then
  84. return 1
  85. fi
  86. echo "Browsing issues ${verb} ${preposition} ${jira_name}"
  87. $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"
  88. }
  89. alias jira='open_jira_issue'