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

Commit e2ec832

Browse files
committed
Fix issue where TRAVIS_BRANCH incorrectly specifies the branch name on PRs
1 parent 37094a7 commit e2ec832

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ before_install:
1212
- composer install
1313
- composer require --prefer-source --dev squizlabs/php_codesniffer:~2.0
1414
- composer create-project --prefer-source -s dev --no-interaction cakephp/app tests/test_app
15+
- source tests/travis-github-pr-integration.sh
1516
- cp tests/Fixture/composer.json tests/test_app/.
1617
- cd tests/test_app
1718
- composer require --prefer-source --dev cakephp/codeception:dev-$TRAVIS_BRANCH#$TRAVIS_COMMIT
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Return if we are not in a Pull Request
4+
[[ "$TRAVIS_PULL_REQUEST" = "false" ]] && return
5+
6+
GITHUB_PR_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
7+
GITHUB_PR_BODY=$(curl -s $GITHUB_PR_URL 2>/dev/null)
8+
9+
if [[ $GITHUB_PR_BODY =~ \"ref\":\ *\"([a-zA-Z0-9_-]*)\" ]]; then
10+
export TRAVIS_PR_BRANCH=${BASH_REMATCH[1]}
11+
else
12+
return
13+
fi
14+
15+
GITHUB_BRANCH_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/branches/$TRAVIS_PR_BRANCH
16+
if [ $(curl -s --head --request GET $GITHUB_BRANCH_URL | grep "200 OK" > /dev/null) ]; then
17+
TRAVIS_BRANCH=$TRAVIS_PR_BRANCH
18+
if [[ $GITHUB_PR_BODY =~ \"repo\":.*\"clone_url\":\ *\"https://github\.com/([a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*)\.git.*\"base\" ]]; then
19+
export TRAVIS_REPO_SLUG=${BASH_REMATCH[1]}
20+
fi
21+
fi

0 commit comments

Comments
 (0)