jira.plugin.zsh 2.3 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. if [ -f .jira-url ]; then
  15. jira_url=$(cat .jira-url)
  16. elif [ -f ~/.jira-url ]; then
  17. jira_url=$(cat ~/.jira-url)
  18. elif [[ "x$JIRA_URL" != "x" ]]; then
  19. jira_url=$JIRA_URL
  20. else
  21. echo "JIRA url is not specified anywhere."
  22. return 1
  23. fi
  24. if [ -f .jira-prefix ]; then
  25. jira_prefix=$(cat .jira-prefix)
  26. elif [ -f ~/.jira-prefix ]; then
  27. jira_prefix=$(cat ~/.jira-prefix)
  28. else
  29. jira_prefix=""
  30. fi
  31. if [ -z "$1" ]; then
  32. echo "Opening new issue"
  33. open_command "${jira_url}/secure/CreateIssue!default.jspa"
  34. elif [[ "$1" = "assigned" || "$1" = "reported" ]]; then
  35. jira_query $@
  36. else
  37. local addcomment=''
  38. if [[ "$2" == "m" ]]; then
  39. addcomment="#add-comment"
  40. echo "Add comment to issue #$1"
  41. else
  42. echo "Opening issue #$1"
  43. fi
  44. if [[ "x$JIRA_RAPID_BOARD" = "xtrue" ]]; then
  45. open_command "$jira_url/issues/$jira_prefix$1$addcomment"
  46. else
  47. open_command "$jira_url/browse/$jira_prefix$1$addcomment"
  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_command "${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'