Handle empty GitHub repositories and do not 500 if the repository cannot be read

This commit is contained in:
Joseph Schorr 2014-03-28 15:32:56 -04:00
parent abfc38f10a
commit 6fd2440294
2 changed files with 17 additions and 5 deletions

View file

@ -38,6 +38,9 @@ class ValidationRequestException(Exception):
class EmptyRepositoryException(Exception):
pass
class RepositoryReadException(Exception):
pass
class BuildTrigger(object):
def __init__(self):
@ -209,9 +212,12 @@ class GithubBuildTrigger(BuildTrigger):
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)
except GithubException as ge:
message = ge.data.get('message', 'Unable to list contents of repository: %s' % source)
if message == 'Branch not found':
raise EmptyRepositoryException()
raise RepositoryReadException(message)
@staticmethod
def _prepare_build(config, repo, commit_sha, build_name, ref):