def repo(request):
prefix = request.match_info['prefix']
try:
repo_name = getattr(scopes, prefix).repo
except AttributeError:
return web.HTTPNotFound()
def info(name, pr=False):
ref = '%s/%s' % ('pull' if pr else 'heads', name)
if pr:
lxc = '%spr-%s' % (prefix, name)
gh_url = 'https://github.com/%s/pull/%s' % (repo_name, name)
else:
name_cleaned = re.sub('[^a-z0-9]', '', name.lower())
lxc = '%s-%s' % (prefix, name_cleaned)
gh_url = 'https://github.com/%s/commits/%s' % (repo_name, ref)
return {
'protected_db': lxc in conf['protected_dbs'],
'name': name,
'lxc': lxc,
'gh_url': gh_url,
'url': 'http://%s.%s' % (lxc, conf['domain']),
'restart_url': get_restart_url(prefix, ref),
'logs_url': '%slatest/%s/' % (conf['log_url'], lxc),
}
resp, body = await gh_api('repos/%s/pulls?per_page=100' % repo_name)
pulls = [info(i['number'], True) for i in body]
resp, body = await gh_api('repos/%s/branches?per_page=100' % repo_name)
branches = [info(i['name']) for i in body]
refs = [
{'title': 'Pull requests', 'items': pulls},
{'title': 'Branches', 'items': branches}
]
return render_tpl(repo_tpl, {'refs': refs})
评论列表
文章目录