env.py 830 B

123456789101112131415161718192021
  1. import os
  2. import subprocess
  3. if 'TRAVIS' not in os.environ:
  4. print 'TRAVIS is not defined; this should run in TRAVIS. Sorry.'
  5. exit(127)
  6. if os.environ['TRAVIS_PULL_REQUEST'] != 'false':
  7. commit_range = [os.environ['TRAVIS_BRANCH'], 'FETCH_HEAD']
  8. else:
  9. try:
  10. subprocess.check_call([
  11. 'git', 'log', '-1', '--format=format:',
  12. os.environ['TRAVIS_COMMIT_RANGE'], '--',
  13. ])
  14. commit_range = os.environ['TRAVIS_COMMIT_RANGE'].split('...')
  15. if len(commit_range) == 1: # if it didn't split, it must have been separated by '..' instead
  16. commit_range = commit_range[0].split('..')
  17. except subprocess.CalledProcessError:
  18. print 'TRAVIS_COMMIT_RANGE is invalid. This seems to be a force push. We will just assume it must be against upstream master and compare all commits in between.'
  19. commit_range = ['upstream/master', 'HEAD']