Manually load GHE org repos if none returned by default

Fixes #276
This commit is contained in:
Joseph Schorr 2015-07-27 16:01:52 -04:00
parent 66b3d45fbc
commit 80e2739b41

View file

@ -729,12 +729,14 @@ class GithubBuildTrigger(BuildTriggerHandler):
raise RepositoryReadException('Unable to list user repositories')
namespaces = {}
has_non_personal = False
for repository in repos:
namespace = repository.owner.login
if not namespace in namespaces:
is_personal_repo = namespace == usr.login
namespaces[namespace] = {
'personal': namespace == usr.login,
'personal': is_personal_repo,
'repos': [],
'info': {
'name': namespace,
@ -742,8 +744,27 @@ class GithubBuildTrigger(BuildTriggerHandler):
}
}
if not is_personal_repo:
has_non_personal = True
namespaces[namespace]['repos'].append(repository.full_name)
# In older versions of GitHub Enterprise, the get_repos call above does not
# return any non-personal repositories. In that case, we need to lookup the
# repositories manually.
# TODO: Remove this once we no longer support GHE versions <= 2.1
if not has_non_personal:
for org in usr.get_orgs():
repo_list = [repo.full_name for repo in org.get_repos(type='member')]
namespaces[org.name] = {
'personal': False,
'repos': repo_list,
'info': {
'name': org.name or org.login,
'avatar_url': org.avatar_url
}
}
entries = list(namespaces.values())
entries.sort(key=lambda e: e['info']['name'])
return entries