github.py 文件源码

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

项目:invenio-github 作者: inveniosoftware 项目源码 文件源码
def index():
    """Display list of the user's repositories."""
    github = GitHubAPI(user_id=current_user.id)
    token = github.session_token
    ctx = dict(connected=False)

    if token:
        # The user is authenticated and the token we have is still valid.
        if github.account.extra_data.get('login') is None:
            github.init_account()
            db.session.commit()

        # Sync if needed
        if request.method == 'POST' or github.check_sync():
            # When we're in an XHR request, we want to synchronously sync hooks
            github.sync(async_hooks=(not request.is_xhr))
            db.session.commit()

        # Generate the repositories view object
        extra_data = github.account.extra_data
        repos = extra_data['repos']
        if repos:
            # 'Enhance' our repos dict, from our database model
            db_repos = Repository.query.filter(
                Repository.github_id.in_([int(k) for k in repos.keys()]),
            ).all()
            for repo in db_repos:
                repos[str(repo.github_id)]['instance'] = repo
                repos[str(repo.github_id)]['latest'] = GitHubRelease(
                    repo.latest_release())

        last_sync = humanize.naturaltime(
            (utcnow() - parse_timestamp(extra_data['last_sync'])))

        ctx.update({
            'connected': True,
            'repos': sorted(repos.items(), key=lambda x: x[1]['full_name']),
            'last_sync': last_sync,
        })

    return render_template(current_app.config['GITHUB_TEMPLATE_INDEX'], **ctx)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号