mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 03:41:08 +00:00
Add support to create Repository objects lazily in MainClass.
This lets users do the following without issuing an unnecessary request:
issues_of_my_repository = g.get_repo('PyGithub/PyGithub').get_issues()
Since the GithubObject layer handles laziness transparently, lazy
loading is enabled by default, and can be disabled via the `lazy`
kwarg. This does not affect any test except tests that pertain to
caching or laziness itself.
This commit is contained in:
+4
-1
@@ -188,13 +188,16 @@ class Github(object):
|
||||
)
|
||||
return github.Organization.Organization(self.__requester, headers, data, completed=True)
|
||||
|
||||
def get_repo(self, full_name_or_id):
|
||||
def get_repo(self, full_name_or_id, lazy=True):
|
||||
"""
|
||||
: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_or_id, (str, unicode, int)), full_name_or_id
|
||||
url_base = "/repositories/" if isinstance(full_name_or_id, int) else "/repos/"
|
||||
url = "%s%s" % (url_base, full_name_or_id)
|
||||
if lazy:
|
||||
return Repository.Repository(self.__requester, {}, {"url": url}, completed=False)
|
||||
headers, data = self.__requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
"%s%s" % (url_base, full_name_or_id)
|
||||
|
||||
Reference in New Issue
Block a user