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:
Tyler Treat
2014-04-22 21:12:22 -05:00
parent 5e7d45a2f8
commit 0ddfaaca01
3 changed files with 19 additions and 4 deletions
+5 -4
View File
@@ -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)