api.py 文件源码

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

项目:invenio-github 作者: inveniosoftware 项目源码 文件源码
def sync(self, hooks=True, async_hooks=True):
        """Synchronize user repositories.

        :param bool hooks: True for syncing hooks.
        :param bool async_hooks: True for sending of an asynchronous task to
                                 sync hooks.

        .. note::

            Syncing happens from GitHub's direction only. This means that we
            consider the information on GitHub as valid, and we overwrite our
            own state based on this information.
        """
        active_repos = {}
        github_repos = {repo.id: repo for repo in self.api.repositories()
                        if repo.permissions['admin']}
        for gh_repo_id, gh_repo in github_repos.items():
            active_repos[gh_repo_id] = {
                'id': gh_repo_id,
                'full_name': gh_repo.full_name,
                'description': gh_repo.description,
            }

        if hooks:
            self._sync_hooks(list(active_repos.keys()),
                             asynchronous=async_hooks)

        # Remove ownership from repositories that the user has no longer
        # 'admin' permissions, or have been deleted.
        Repository.query.filter(
            Repository.user_id == self.user_id,
            ~Repository.github_id.in_(github_repos.keys())
        ).update(dict(user_id=None, hook=None), synchronize_session=False)

        # Update repos and last sync
        self.account.extra_data.update(dict(
            repos=active_repos,
            last_sync=iso_utcnow(),
        ))
        self.account.extra_data.changed()
        db.session.add(self.account)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号