git-redmine 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. #
  3. # Copyright 2014 Savoir-faire Linux Inc.
  4. # Author: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
  5. # Licensed under the terms of the GNU GPL v3, or at your option, any later version.
  6. #
  7. # You can install this script as a Git subcommand with one of the 2 methods below:
  8. #
  9. # 1) git config alias.redmine '!tools/git-redmine'
  10. # 2) or put this script in your $PATH
  11. usage () {
  12. echo "Usage:"
  13. echo " $0 <url|open> [<git-rev>]"
  14. echo " $0 help"
  15. echo
  16. echo "Examples:"
  17. echo " git redmine open # open the Redmine ticket related to the current commit"
  18. echo " git redmine url HEAD~2"
  19. }
  20. test $# -ge 1 -a $# -le 2 || {
  21. echo "Invalid syntax."
  22. usage
  23. exit 1
  24. }
  25. test "$1" = "help" && {
  26. usage
  27. exit
  28. }
  29. REDMINE_URL=`git config redmine.url`
  30. test -n "$REDMINE_URL" || {
  31. echo "You must configure your Redmine URL, e.g.:"
  32. echo
  33. echo " git config redmine.url https://projects.savoirfairelinux.com"
  34. echo
  35. exit 1
  36. }
  37. ISSUE=`git show --summary --format=%b $2 | perl -n -e '/^(Refs|Issue:) #(\d+)$/ && print $2'`
  38. test -n "$ISSUE" || {
  39. echo "no issue ID!"
  40. exit 1
  41. }
  42. URL=$REDMINE_URL/issues/$ISSUE
  43. case $1 in
  44. url) echo $URL ;;
  45. open) xdg-open $URL ;;
  46. *) echo "Oops, bad command" ; usage ; exit 1 ;;
  47. esac
  48. exit