Get PR URL and Branch using GitHub API

This commit is contained in:
Derek Stavis 2015-10-01 00:40:22 -03:00
parent e40f2d3ceb
commit 0b2a51a93f
3 changed files with 14 additions and 17 deletions

View File

@ -9,7 +9,7 @@ env:
- OMF_REPO_BRANCH="$TRAVIS_BRANCH"
before_install:
- export OMF_REPO_BRANCH=`tools/branch-name.sh`
- source tools/travis-github-pr-integration.sh
- docker build -t fish . < Dockerfile
before_script:

View File

@ -1,16 +0,0 @@
#!/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

View File

@ -0,0 +1,13 @@
# Return if we are not in a Pull Request
[[ "$TRAVIS_PULL_REQUEST" = "false" ]] && return
GITHUB_PR_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
GITHUB_PR_BODY=$(curl -s $GITHUB_PR_URL 2>/dev/null)
if [[ $GITHUB_PR_BODY =~ \"ref\":\ *\"([a-zA-Z0-9_-]*)\" ]]; then
export OMF_REPO_BRANCH=${BASH_REMATCH[1]}
fi
if [[ $GITHUB_PR_BODY =~ \"repo\":.*\"clone_url\":\ *\"(https://github\.com/[a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*\.git).*\"base\" ]]; then
export OMF_REPO_URI=${BASH_REMATCH[1]}
fi