def get(cls, user_id, github_id=None, name=None, check_owner=True):
"""Return a repository.
:param integer user_id: User identifier.
:param integer github_id: GitHub repository identifier.
:param str name: GitHub repository full name.
:returns: The repository object.
:raises: :py:exc:`~sqlalchemy.orm.exc.NoResultFound`: if the repository
doesn't exist.
:raises: :py:exc:`~sqlalchemy.orm.exc.MultipleResultsFound`: if
multiple repositories with the specified GitHub id and/or name
exist.
:raises: :py:exc:`RepositoryAccessError`: if the user is not the owner
of the repository.
"""
repo = cls.query.filter((Repository.github_id == github_id) |
(Repository.name == name)).one()
if (check_owner and repo and repo.user_id and
repo.user_id != int(user_id)):
raise RepositoryAccessError(
u'User {user} cannot access repository {repo}({repo_id}).'
.format(user=user_id, repo=name, repo_id=github_id)
)
return repo
评论列表
文章目录