diff --git a/.travis.yml b/.travis.yml index b149c1140..5e8077f9e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: cpp script: - python travis/lint.py +- python travis/pr-check-base.py diff --git a/travis/pr-check-base.py b/travis/pr-check-base.py new file mode 100644 index 000000000..e4e9ae910 --- /dev/null +++ b/travis/pr-check-base.py @@ -0,0 +1,29 @@ +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: + pr_id = int(os.environ.get('TRAVIS_PULL_REQUEST', 'false')) +except ValueError: + print('Not a pull request') + sys.exit(0) +print('Pull request %i' % pr_id) +res = {} +try: + res = json.loads(urlopen('https://api.github.com/repos/dfhack/dfhack/pulls/%i' % pr_id).read().decode('utf-8')) +except ValueError: + pass +except HTTPError: + print('Failed to retrieve PR information from API') + 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': + print('Not based on develop branch') + sys.exit(1) +else: + print('Ok') + sys.exit(0)