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

Commit d883ff6

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

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ php:
88
- 7.0
99

1010
before_install:
11+
- source tests/travis-github-pr-integration.sh
1112
- if [ -f .git/shallow ]; then rm .git/shallow; fi
1213
- composer install
1314
- composer require --prefer-source --dev squizlabs/php_codesniffer:~2.0
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
echo $GITHUB_PR_BODY
9+
10+
if [[ $GITHUB_PR_BODY =~ \"ref\":\ *\"([a-zA-Z0-9_-]*)\" ]]; then
11+
export TRAVIS_PR_BRANCH=${BASH_REMATCH[1]}
12+
echo $TRAVIS_PR_BRANCH
13+
else
14+
return
15+
fi
16+
17+
GITHUB_BRANCH_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/branches/$TRAVIS_PR_BRANCH
18+
echo $GITHUB_BRANCH_URL
19+
if [ $(curl -s --head --request GET $GITHUB_BRANCH_URL | grep "200 OK" > /dev/null) ]; then
20+
TRAVIS_BRANCH=$TRAVIS_PR_BRANCH
21+
echo $TRAVIS_BRANCH
22+
if [[ $GITHUB_PR_BODY =~ \"repo\":.*\"clone_url\":\ *\"https://github\.com/([a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*)\.git.*\"base\" ]]; then
23+
export TRAVIS_REPO_SLUG=${BASH_REMATCH[1]}
24+
fi
25+
fi

0 commit comments

Comments
 (0)