Advertisement
Guest User

Untitled

a guest
Dec 21st, 2011
2,991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/bin/bash
  2. # allows you to send pull requests from the command line
  3. # usage: git req username [comparetobranch]
  4. # or: git req username -m 'message'
  5. # put somewhere in your PATH as git-req and make executable
  6.  
  7. usage()
  8. {
  9. cat << EOF
  10. usage: $0 options
  11.  
  12. Sends a pull request via github
  13.  
  14. OPTIONS:
  15. -h Show this message
  16. -f Force a pull request
  17. EOF
  18. }
  19.  
  20. FORCE=
  21.  
  22. while getopts "hf" OPTION
  23. do
  24. case $OPTION in
  25. h) usage; exit;;
  26. f) FORCE=1;;
  27. esac
  28. done
  29. shift $(($OPTIND - 1))
  30.  
  31. GITUNCOMMITTED=$(git status | sed -n 2p) && GITUNCOMMITTED=${GITUNCOMMITTED:0:7}
  32. if [ "$GITUNCOMMITTED" != 'nothing' ]
  33. then
  34. echo -ne 'Error: Woah, woah, woah. There are uncommitted changes!\n'
  35. exit $?
  36. fi
  37. GITBRANCH=$(git symbolic-ref HEAD | cut -d/ -f3)
  38. GITUNPUSHED=$(git log origin/$GITBRANCH..$GITBRANCH --pretty=oneline --abbrev-commit)
  39. if [ "$GITUNPUSHED" != '' ]
  40. then
  41. echo -ne 'Error: Push your changes!\n'
  42. exit $?
  43. fi
  44. GITUSER=$(git config github.user)
  45. GITPROJECT=$(grep 'url =' .git/config | sed -n 1p | sed -e 's/.*url = git@github.com:'$GITUSER'.*[/]\(.*\).git$/\1/')
  46. GITTOKEN=$(git config github.token)
  47. if [ $(echo "${#2}") != '0' ]
  48. then
  49. if [ "$2" != '-m' ]
  50. then
  51. GITCOMPR="http://github.com/$GITUSER/$GITPROJECT/compare/$2...$GITBRANCH"
  52. else
  53. GITCOMPR=$3
  54. fi
  55. else
  56. GITCOMPR=''
  57. fi
  58. GITPULLREQ=$(curl -Flogin=$GITUSER -Ftoken=$GITTOKEN -Fmessage[to][]=$1 -Fmessage[body]="$GITCOMPR" "http://github.com/$GITUSER/$GITPROJECT/pull_request/$GITBRANCH" 2> /dev/null | sed -e 's/.*You are.*/OK/')
  59. if [ $GITPULLREQ != 'OK' ]
  60. then
  61. echo -ne 'Could not complete pull request.\n'
  62. else
  63. echo -ne 'Pull request sent to '$1'.\n'
  64. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement