Merge pull request #2418 from charltonaustin/fix_error_with_dockerfile_content

fix(buildtrigger): fixed error from github api
This commit is contained in:
Charlton Austin 2017-03-10 13:34:47 -05:00 committed by GitHub
commit c09d07e81c
5 changed files with 6 additions and 6 deletions

View file

@ -259,7 +259,7 @@ class BuildTriggerHandler(object):
pass
@classmethod
def path_is_dockerfile(cls, file_name):
def filename_is_dockerfile(cls, file_name):
""" Returns whether the file is named Dockerfile or follows the convention <name>.Dockerfile"""
return file_name.endswith(".Dockerfile") or u"Dockerfile" == file_name

View file

@ -453,7 +453,7 @@ class BitbucketBuildTrigger(BuildTriggerHandler):
raise RepositoryReadException(err_msg)
files = set([f['path'] for f in data['files']])
return ["/" + file_path for file_path in files if self.path_is_dockerfile(os.path.basename(file_path))]
return ["/" + file_path for file_path in files if self.filename_is_dockerfile(os.path.basename(file_path))]
def load_dockerfile_contents(self):
repository = self._get_repository_client()

View file

@ -350,7 +350,7 @@ class GithubBuildTrigger(BuildTriggerHandler):
commit_tree = repo.get_git_tree(default_commit.sha, recursive=True)
return [elem.path for elem in commit_tree.tree
if (elem.type == u'blob' and self.path_is_dockerfile(os.path.basename(elem.path)))]
if (elem.type == u'blob' and self.filename_is_dockerfile(os.path.basename(elem.path)))]
except GithubException as ghe:
message = ghe.data.get('message', 'Unable to list contents of repository: %s' % source)
if message == 'Branch not found':
@ -371,7 +371,7 @@ class GithubBuildTrigger(BuildTriggerHandler):
raise RepositoryReadException(message)
path = self.get_dockerfile_path()
if not path:
if not path or not self.filename_is_dockerfile(os.path.basename(path)):
return None
try:

View file

@ -342,7 +342,7 @@ class GitLabBuildTrigger(BuildTriggerHandler):
msg = 'Unable to find GitLab repository tree for source: %s' % new_build_source
raise RepositoryReadException(msg)
return ["/"+node['name'] for node in repo_tree if self.path_is_dockerfile(node['name'])]
return ["/" + node['name'] for node in repo_tree if self.filename_is_dockerfile(node['name'])]
@_catch_timeouts
def load_dockerfile_contents(self):

View file

@ -12,4 +12,4 @@ from buildtrigger.basehandler import BuildTriggerHandler
(u"bad file name", False),
])
def test_path_is_dockerfile(input, output):
assert BuildTriggerHandler.path_is_dockerfile(input) == output
assert BuildTriggerHandler.filename_is_dockerfile(input) == output