Is there possibility to get releases with pyGithub
Asked Answered
D

3

9

I havent used PyGithub yet but I am just curious if there is any possibility to get a list of releases from a repository (e.g. https://github.com/{username}/{repo-name}/releases). I can not see any information about that in documentation here.

Din answered 7/11, 2016 at 10:14 Comment(1)
If you have no specific requirements for PyGithub I can strongly recommend github3.py, which does support this API.Ferrer
K
9

The question is a bit old but nobody seems to have answered it in the way the OP asked.

PyGithub does have a way to return releases of a repo, here is a working example:

from github import Github

G = Github('')  # Put your GitHub token here
repo = G.get_repo('justintime50/github-archive')
releases = repo.get_releases()

for release in releases:
    print(release.title)

The above will return the following:

v4.3.0
v4.2.2
v4.2.1
v4.2.0
v4.1.1
...

I hope this is helpful!

Kushner answered 1/2, 2020 at 19:19 Comment(0)
H
2

You can get a list of releases from a GitHub repo by making a GET request to

https://api.github.com/repos/{user}/{repo}/releases

Eg

import requests

url = 'https://api.github.com/repos/facebook/react/releases'
response = requests.get(url)

# Raise an exception if the API call fails.
response.raise_for_status()

data = response.json()

Also its worth noting you should be making authenticated requests otherwise you'll hit GitHubs API rate limiting pretty quickly and just get back 403s.

Hangchow answered 7/11, 2016 at 10:36 Comment(8)
thanks for answering but i was thinking about using just PyGithub to maintain my requirements to github but i see that i will need to create separate function for this.Din
What exactly are you trying to do?Hangchow
I want to make some notification about new releases of most interesting repositories for me which will be loaded from yaml or similar.Din
Are these repos you own? If so you could set up a webhook and listen for a release event developer.github.com/v3/activity/events/types/#releaseeventHangchow
No, they are not mine.Din
I'm still a little unsure as to what you need to do. Do you want to know when packages are being released so you can update your projects third party requirements?Hangchow
So you could then just define this in your requirements.txt file. For example ``` Django djangorestframework ``` and then run pip install -r requirements.txt This would install the latest version of each package. You can also define versions in your requirements file like so Django==1.10.3Hangchow
i see that I misunderstood your previous comment. I don't mean python requirements but just other requirements like for infrastructure components like docker, kubernetes, prometheus and so onDin
F
2

The documentation for PyGithub doesn't mention it, but I believe that pygithub-1.29 (the latest published on PyPi as of today) does in fact contain this API: Repository.py for the v1.29 tag contains a get_releases() function.

There is also an open, unmerged pull request that appears to fill out this API to include assets, too.

Ferrer answered 16/11, 2016 at 10:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.