web.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fireq 作者: superdesk 项目源码 文件源码
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})
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号