Handle the case of empty repositories in the trigger.

This commit is contained in:
jakedt 2014-02-24 14:12:54 -05:00
parent d861f9b646
commit 4b0f4c0a7b

View file

@ -31,6 +31,9 @@ class TriggerActivationException(Exception):
class ValidationRequestException(Exception):
pass
class EmptyRepositoryException(Exception):
pass
class BuildTrigger(object):
def __init__(self):
@ -158,13 +161,17 @@ class GithubBuildTrigger(BuildTrigger):
gh_client = self._get_client(auth_token)
source = config['build_source']
repo = gh_client.get_repo(source)
default_commit = repo.get_branch(repo.default_branch).commit
commit_tree = repo.get_git_tree(default_commit.sha, recursive=True)
try:
repo = gh_client.get_repo(source)
default_commit = repo.get_branch(repo.default_branch).commit
commit_tree = repo.get_git_tree(default_commit.sha, recursive=True)
return [os.path.dirname(elem.path) for elem in commit_tree.tree
if (elem.type == u'blob' and
os.path.basename(elem.path) == u'Dockerfile')]
return [os.path.dirname(elem.path) for elem in commit_tree.tree
if (elem.type == u'blob' and
os.path.basename(elem.path) == u'Dockerfile')]
except GithubException:
msg = 'Unable to list contents of repository: %s' % source
raise EmptyRepositoryException(msg)
def handle_trigger_request(self, request, auth_token, config):
payload = request.get_json()