Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Fix issue where TRAVIS_BRANCH incorrectly specifies the branch name o…
Browse files Browse the repository at this point in the history
…n PRs
  • Loading branch information
josegonzalez committed Feb 29, 2016
1 parent 37094a7 commit d883ff6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ php:
- 7.0

before_install:
- source tests/travis-github-pr-integration.sh
- if [ -f .git/shallow ]; then rm .git/shallow; fi
- composer install
- composer require --prefer-source --dev squizlabs/php_codesniffer:~2.0
Expand Down
25 changes: 25 additions & 0 deletions tests/travis-github-pr-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# 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)
echo $GITHUB_PR_BODY

if [[ $GITHUB_PR_BODY =~ \"ref\":\ *\"([a-zA-Z0-9_-]*)\" ]]; then
export TRAVIS_PR_BRANCH=${BASH_REMATCH[1]}
echo $TRAVIS_PR_BRANCH
else
return
fi

GITHUB_BRANCH_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/branches/$TRAVIS_PR_BRANCH
echo $GITHUB_BRANCH_URL
if [ $(curl -s --head --request GET $GITHUB_BRANCH_URL | grep "200 OK" > /dev/null) ]; then
TRAVIS_BRANCH=$TRAVIS_PR_BRANCH
echo $TRAVIS_BRANCH
if [[ $GITHUB_PR_BODY =~ \"repo\":.*\"clone_url\":\ *\"https://github\.com/([a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*)\.git.*\"base\" ]]; then
export TRAVIS_REPO_SLUG=${BASH_REMATCH[1]}
fi
fi

0 comments on commit d883ff6

Please sign in to comment.