From 4b0f4c0a7b58ac3ef6d972a425d1e3df1f2b11c5 Mon Sep 17 00:00:00 2001 From: jakedt Date: Mon, 24 Feb 2014 14:12:54 -0500 Subject: [PATCH] Handle the case of empty repositories in the trigger. --- endpoints/trigger.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/endpoints/trigger.py b/endpoints/trigger.py index 7634c74a3..990fb5278 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -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()