Handle empty GitHub repositories and do not 500 if the repository cannot be read
This commit is contained in:
parent
abfc38f10a
commit
6fd2440294
2 changed files with 17 additions and 5 deletions
|
@ -13,7 +13,8 @@ from endpoints.api.build import (build_status_view, trigger_view, RepositoryBuil
|
||||||
get_trigger_config)
|
get_trigger_config)
|
||||||
from endpoints.common import start_build
|
from endpoints.common import start_build
|
||||||
from endpoints.trigger import (BuildTrigger as BuildTriggerBase, TriggerDeactivationException,
|
from endpoints.trigger import (BuildTrigger as BuildTriggerBase, TriggerDeactivationException,
|
||||||
TriggerActivationException, EmptyRepositoryException)
|
TriggerActivationException, EmptyRepositoryException,
|
||||||
|
RepositoryReadException)
|
||||||
from data import model
|
from data import model
|
||||||
from auth.permissions import UserAdminPermission
|
from auth.permissions import UserAdminPermission
|
||||||
|
|
||||||
|
@ -116,9 +117,14 @@ class BuildTriggerSubdirs(RepositoryParamResource):
|
||||||
'status': 'success'
|
'status': 'success'
|
||||||
}
|
}
|
||||||
except EmptyRepositoryException as exc:
|
except EmptyRepositoryException as exc:
|
||||||
|
return {
|
||||||
|
'status': 'success',
|
||||||
|
'subdir': []
|
||||||
|
}
|
||||||
|
except RepositoryReadException as exc:
|
||||||
return {
|
return {
|
||||||
'status': 'error',
|
'status': 'error',
|
||||||
'message': exc.msg
|
'message': exc.message
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
raise Unauthorized()
|
raise Unauthorized()
|
||||||
|
|
|
@ -38,6 +38,9 @@ class ValidationRequestException(Exception):
|
||||||
class EmptyRepositoryException(Exception):
|
class EmptyRepositoryException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class RepositoryReadException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BuildTrigger(object):
|
class BuildTrigger(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -209,9 +212,12 @@ class GithubBuildTrigger(BuildTrigger):
|
||||||
return [os.path.dirname(elem.path) for elem in commit_tree.tree
|
return [os.path.dirname(elem.path) for elem in commit_tree.tree
|
||||||
if (elem.type == u'blob' and
|
if (elem.type == u'blob' and
|
||||||
os.path.basename(elem.path) == u'Dockerfile')]
|
os.path.basename(elem.path) == u'Dockerfile')]
|
||||||
except GithubException:
|
except GithubException as ge:
|
||||||
msg = 'Unable to list contents of repository: %s' % source
|
message = ge.data.get('message', 'Unable to list contents of repository: %s' % source)
|
||||||
raise EmptyRepositoryException(msg)
|
if message == 'Branch not found':
|
||||||
|
raise EmptyRepositoryException()
|
||||||
|
|
||||||
|
raise RepositoryReadException(message)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _prepare_build(config, repo, commit_sha, build_name, ref):
|
def _prepare_build(config, repo, commit_sha, build_name, ref):
|
||||||
|
|
Reference in a new issue