- Install jq
- Create git remote access token
- Add token to .gitconfig
[user]
email = xxx
user = xxx
token = xxxxxxxxxx
- Define the PR function
#
## git pull request
#
function pr(){
title=$1
msg=$2
whoami=`whoami`
if [ -z "$title" -o -z "$msg" ]; then
echo Usage: ${whoami}$ pr "\"Pull Request Title\"" "\"PR comment message (add 'reviewer: @yid' to hook with hipchat)\""
return 0;
fi
headBranch=`git rev-parse --abbrev-ref HEAD`
repo=`git remote -v | head -n 1 | awk -F'/' '{print $2}' | awk -F'.' '{print $1}'`
token=`git config user.token`
repos=`curl -s -u ${token}:x-oauth-basic -H "Accept: application/vnd.github.moondragon-preview+json" -H "Content-Type: application/json" -k https://git.corp.yahoo.com/api/v3/repos/$whoami/$repo | jq -r ".parent.full_name"`
# get pull request result
url=`curl -k -s -u $token:x-oauth-basic -H "Accept: application/vnd.github.moondragon-preview+json" -H "Content-Type: application/json" -d "{\"title\":\"${title}\",\"body\":\"${msg}\",\"head\":\"${whoami}:${headBranch}\",\"base\":\"master\"}" -k https://git.corp.yahoo.com/api/v3/repos/$repos/pulls | jq -r ".html_url"`
if [ $url == "null" ]; then
echo "execute command fail, please check your repos status."
else
echo $url
fi
}
- Try to create PR:
>> git commit -am "update conf"; git push origin dev; pr "update conf" "hi @yutu"
https://github.com/<upstream>/<repo>/pull/96