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))
评论列表
文章目录