2929import subprocess
3030import sys
3131
32+ from script_utils import LOCAL_BRANCH_ENV
33+ from script_utils import LOCAL_REMOTE_ENV
34+ from script_utils import in_travis
35+ from script_utils import in_travis_pr
36+ from script_utils import travis_branch
37+
3238
3339IGNORED_DIRECTORIES = [
3440 os .path .join ('bigtable' , 'google' , 'cloud' , 'bigtable' , '_generated' ),
@@ -143,14 +149,14 @@ def get_files_for_linting(allow_limited=True):
143149 against for changed files. (This requires ``allow_limited=True``.)
144150
145151 To speed up linting on Travis pull requests against master, we manually
146- set the diff base to origin/master . We don't do this on non-pull requests
147- since origin/ master will be equivalent to the currently checked out code.
148- One could potentially use ${TRAVIS_COMMIT_RANGE} to find a diff base but
149- this value is not dependable.
152+ set the diff base to the branch the pull request is against . We don't do
153+ this on "push" builds since " master" will be the currently checked out
154+ code. One could potentially use ${TRAVIS_COMMIT_RANGE} to find a diff base
155+ but this value is not dependable.
150156
151- To allow faster local ``tox`` runs, the environment variables
152- ``GOOGLE_CLOUD_REMOTE_FOR_LINT`` and ``GOOGLE_CLOUD_BRANCH_FOR_LINT`` can
153- be set to specify a remote branch to diff against.
157+ To allow faster local ``tox`` runs, the local remote and local branch
158+ environment variables can be set to specify a remote branch to diff
159+ against.
154160
155161 :type allow_limited: bool
156162 :param allow_limited: Boolean indicating if a reduced set of files can
@@ -161,15 +167,15 @@ def get_files_for_linting(allow_limited=True):
161167 linted.
162168 """
163169 diff_base = None
164- if ( os . getenv ( 'TRAVIS_BRANCH' ) == 'master' and
165- os . getenv ( 'TRAVIS_PULL_REQUEST' ) != 'false' ):
166- # In the case of a pull request into master, we want to
167- # diff against HEAD in master.
168- diff_base = 'origin/master'
169- elif os . getenv ( 'TRAVIS' ) is None :
170+ if in_travis ():
171+ # In the case of a pull request into a branch, we want to
172+ # diff against HEAD in that branch.
173+ if in_travis_pr ():
174+ diff_base = travis_branch ()
175+ else :
170176 # Only allow specified remote and branch in local dev.
171- remote = os .getenv ('GOOGLE_CLOUD_REMOTE_FOR_LINT' )
172- branch = os .getenv ('GOOGLE_CLOUD_BRANCH_FOR_LINT' )
177+ remote = os .getenv (LOCAL_REMOTE_ENV )
178+ branch = os .getenv (LOCAL_BRANCH_ENV )
173179 if remote is not None and branch is not None :
174180 diff_base = '%s/%s' % (remote , branch )
175181
0 commit comments