mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
Implement support for getting repo by id
This allows the Github class to retrieve repos by either their full name or id. If the user passes in an id for a repo which doesn't exist or in which they don't have sufficient permissions, an UnknownObjectException will be raised. This addresses issue #245.
This commit is contained in:
+5
-4
@@ -188,15 +188,16 @@ class Github(object):
|
||||
)
|
||||
return github.Organization.Organization(self.__requester, headers, data, completed=True)
|
||||
|
||||
def get_repo(self, full_name):
|
||||
def get_repo(self, full_name_or_id):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_
|
||||
:calls: `GET /repos/:owner/:repo <http://developer.github.com/v3/repos>`_ or `GET /repositories/:id <http://developer.github.com/v3/repos>`_
|
||||
:rtype: :class:`github.Repository.Repository`
|
||||
"""
|
||||
assert isinstance(full_name, (str, unicode)), full_name
|
||||
assert isinstance(full_name_or_id, (str, unicode, int)), full_name_or_id
|
||||
url_base = "/repositories/" if isinstance(full_name_or_id, int) else "/repos/"
|
||||
headers, data = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"/repos/" + full_name
|
||||
"%s%s" % (url_base, full_name_or_id)
|
||||
)
|
||||
return Repository.Repository(self.__requester, headers, data, completed=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user