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 e2ec832
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ before_install:
- composer install
- composer require --prefer-source --dev squizlabs/php_codesniffer:~2.0
- composer create-project --prefer-source -s dev --no-interaction cakephp/app tests/test_app
- source tests/travis-github-pr-integration.sh
- cp tests/Fixture/composer.json tests/test_app/.
- cd tests/test_app
- composer require --prefer-source --dev cakephp/codeception:dev-$TRAVIS_BRANCH#$TRAVIS_COMMIT
Expand Down
21 changes: 21 additions & 0 deletions tests/travis-github-pr-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/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)

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

GITHUB_BRANCH_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/branches/$TRAVIS_PR_BRANCH
if [ $(curl -s --head --request GET $GITHUB_BRANCH_URL | grep "200 OK" > /dev/null) ]; then
TRAVIS_BRANCH=$TRAVIS_PR_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 e2ec832

Please sign in to comment.