Get original repository branch name
Travis does not provide the original repository branch name on any environment variable. We are getting the information from the GitHub API instead. The misleading environment variable `TRAVIS_BRANCH` returns `master` instead: > TRAVIS_BRANCH: For builds not triggered by a pull request this is the name of the branch currently being built; whereas for builds triggered by a pull request this is the name of the branch targeted by the pull request (in many cases this will be master). Reference: http://docs.travis-ci.com/user/environment-variables/pull/80/head
parent
faba765a94
commit
dde679ff98
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
|
||||
|
||||
BRANCH_NAME=`curl -s $URL ^/dev/null \
|
||||
| grep -C 2 "head" \
|
||||
| grep \"ref\" \
|
||||
| cut -d':' -f2- \
|
||||
| sed -e 's/["|,]//g;s/^[ \t]//g'
|
||||
`
|
||||
|
||||
if [ -n "$BRANCH_NAME" ]; then
|
||||
echo $BRANCH_NAME
|
||||
else
|
||||
echo $TRAVIS_BRANCH
|
||||
fi
|
Loading…
Reference in New Issue