Use TRAVIS_BRANCH environment variable

Ref #713
develop
lethosor 2015-10-30 22:58:58 -04:00
parent 7da3c65079
commit aa2ada4cbc
1 changed files with 4 additions and 19 deletions

@ -1,11 +1,7 @@
import json, os, sys
if sys.version.startswith('2'):
from urllib2 import urlopen, HTTPError
else:
from urllib.request import urlopen
from urllib.error import HTTPError
try:
import os, sys
repo = os.environ.get('TRAVIS_REPO_SLUG', 'dfhack/dfhack').lower()
branch = os.environ.get('TRAVIS_BRANCH', 'master')
try:
pr_id = int(os.environ.get('TRAVIS_PULL_REQUEST', 'false'))
except ValueError:
print('Not a pull request')
@ -14,18 +10,7 @@ print('Pull request %s#%i' % (repo, pr_id))
if repo != 'dfhack/dfhack':
print('Not in dfhack/dfhack')
sys.exit(0)
res = {}
try:
res = json.loads(urlopen('https://api.github.com/repos/%s/pulls/%i' % (repo, pr_id)).read().decode('utf-8'))
except ValueError:
pass
except HTTPError as e:
print('Failed to retrieve PR information from API: %s' % e)
sys.exit(2)
if 'base' not in res or 'ref' not in res['base']:
print('Invalid JSON returned from API')
sys.exit(2)
if res['base']['ref'] != 'develop':
if branch != 'develop':
print('Not based on develop branch')
sys.exit(1)
else: