PyGithub does not appear to support the GitHub API call to acquire the latest release. I'm wondering if I can add a method to PyGithub at run time that would do this for me.
For example, the existing code has the following method:
# Repository.py
def get_releases(self):
"""
:calls: `GET /repos/:owner/:repo/releases <http://developer.github.com/v3/repos>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Tag.Tag`
"""
return github.PaginatedList.PaginatedList(
github.GitRelease.GitRelease,
self._requester,
self.url + "/releases",
None
)
I'd like to add this one to the Repository.py class:
def get_latest_release(self):
return github.PaginatedList.PaginatedList(
github.GitRelease.GitRelease,
self._requester,
self.url + "/releases/latest",
None
)
I tried this but I received an error:
# main.py
from types import MethodType
from github import Github
from github.Repository import Repository, github
def get_latest_release(self): ...
def main():
Repository.method = MethodType(get_latest_release, None, Repository)
g = Github(<my name>, <my password>)
org = g.get_organization(<name of org>)
repo = org.get_repo(<name of repository>)
release = repo.get_latest_release()
# AttributeError: 'Repository' object has no attribute 'get_latest_release'
Is it possible to add this method at runtime?
Repository.method? Whymethod?Repository.get_latest_release = get_latest_releasebe sufficient. You would only needMethodTypeif you were trying to assign to an instance, e.g.repo.get_lastest_release = MethodType(get_latest_release, repo)