github_api.py 文件源码

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

项目:ob2 作者: octobear2 项目源码 文件源码
def _assign_repo(repo_name, members=[]):
    """
    (PRIVATE method, use the repomanager instead) Creates the repository and adds the members as
    contributors, idempotently.

    """
    if config.github_read_only_mode:
        raise RuntimeError("Cannot assign repo because of GitHub read-only mode")
    github = _get_github_admin()
    fq_repo_name = "%s/%s" % (config.github_organization, repo_name)
    organization = github.organization(config.github_organization)
    try:
        repo = organization.create_repo(repo_name, private=config.github_private_repos)
    except github3.GitHubError as e:
        if e.args and hasattr(e.args[0], "status_code") and e.args[0].status_code == 422:
            repo = github.repository(config.github_organization, repo_name)
            assert repo, "Unable to get repository object for GitHub (check API key permissions?)"
        else:
            raise

    collaborators = {user.login for user in repo.iter_collaborators()}

    for member in members:
        if member not in collaborators:
            successfully_added = repo.add_collaborator(member)
            assert successfully_added, "Unable to add member %s to %s" % (repr(member),
                                                                          repr(fq_repo_name))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号