I have a python script that fetches for updates from GitHub and displays patch-notes for the latest version when doing so.
I would like the script to display patch-notes for all releases ahead of the current version/release.
My github releases are versioned as so: v1.2.3
This is the code I am currently using that displays patch notes for the latest release only:
version = 2.1.5
import urllib.request, json
with urllib.request.urlopen("https://api.github.com/repos/:author/:repo/releases/latest") as url:
data = json.loads(url.read().decode())
latest = data['tag_name'][1:] # "v2.3.6" -> "2.3.6"
patchNotes = data['body']
if latest > version:
print('\nUpdate available!')
print(f'Latest Version: v{latest}')
print('\n'+str(patchNotes)+'\n') #display latest (v2.3.6) patch notes
input(str('Update now? [Y/n] ')).upper()
#code to download the latest version
This is an idea I have had to get what I need:
data[body]
from respective github-api json pageI don't know how to impliment the above idea, and if there are more efficient ways of achieving what I'm going for, I'm open for suggestions.
You can use something like this :
import requests
from packaging import version
maxVersion = version.parse("3.9.2")
repoWithOwner= "labstack/echo"
r = requests.get("https://api.github.com/repos/{}/releases?per_page=100".format(repoWithOwner))
releases = [
(t["tag_name"],t["body"])
for t in r.json()
if version.parse(t["tag_name"]) >= maxVersion
][::-1]
for r in releases:
print("{} : {}".format(r[0],r[1]))
It gets the 100 last releases & check wether it is >= {your specified version}, reverse the array and print the tag & body