Fix API exception in trigger setup due to invalid Dockerfile path

This commit is contained in:
Joseph Schorr 2017-03-07 18:58:28 -05:00 committed by Evan Cordell
parent 04c9b6568c
commit a15abd3b5c
5 changed files with 10 additions and 4 deletions

View file

@ -290,7 +290,10 @@ class BuildTriggerHandler(object):
def get_dockerfile_path(self): def get_dockerfile_path(self):
""" Returns the normalized path to the Dockerfile found in the subdirectory """ Returns the normalized path to the Dockerfile found in the subdirectory
in the config. """ in the config. """
return self.config.get('subdir', '') dockerfile_path = self.config.get('subdir') or 'Dockerfile'
if dockerfile_path[0] == '/':
dockerfile_path = dockerfile_path[1:]
return dockerfile_path
def prepare_build(self, metadata, is_manual=False): def prepare_build(self, metadata, is_manual=False):
# Ensure that the metadata meets the scheme. # Ensure that the metadata meets the scheme.

View file

@ -371,6 +371,9 @@ class GithubBuildTrigger(BuildTriggerHandler):
raise RepositoryReadException(message) raise RepositoryReadException(message)
path = self.get_dockerfile_path() path = self.get_dockerfile_path()
if not path:
return None
try: try:
file_info = repo.get_file_contents(path) file_info = repo.get_file_contents(path)
except GithubException as ghe: except GithubException as ghe:

View file

@ -23,7 +23,7 @@ def get_repo_path_contents(path, revision):
return (True, data, None) return (True, data, None)
def get_raw_path_contents(path, revision): def get_raw_path_contents(path, revision):
if path == '/Dockerfile': if path == 'Dockerfile':
return (True, 'hello world', None) return (True, 'hello world', None)
if path == 'somesubdir/Dockerfile': if path == 'somesubdir/Dockerfile':

View file

@ -119,7 +119,7 @@ def get_mock_github():
return [master, otherbranch] return [master, otherbranch]
def get_file_contents_mock(filepath): def get_file_contents_mock(filepath):
if filepath == '/Dockerfile': if filepath == 'Dockerfile':
m = Mock() m = Mock()
m.content = 'hello world' m.content = 'hello world'
return m return m

View file

@ -151,7 +151,7 @@ def gettag_mock(repo_id, tag):
} }
def getrawfile_mock(repo_id, branch_name, path): def getrawfile_mock(repo_id, branch_name, path):
if path == '/Dockerfile': if path == 'Dockerfile':
return 'hello world' return 'hello world'
if path == 'somesubdir/Dockerfile': if path == 'somesubdir/Dockerfile':