1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
Files
netbox-community-netbox/netbox/utilities/versions.py

28 lines
892 B
Python
Raw Normal View History

2020-01-24 00:15:32 +01:00
import requests
from cacheops import cached
from django.conf import settings
from packaging import version
if settings.GITHUB_VERSION_TIMEOUT and settings.GITHUB_REPOSITORY:
@cached(timeout=settings.GITHUB_VERSION_TIMEOUT)
def get_latest_version():
url = 'https://api.github.com/repos/{}/releases'.format(settings.GITHUB_REPOSITORY)
headers = {
'Accept': 'application/vnd.github.v3+json',
}
try:
response = requests.get(url, headers=headers)
versions = [(version.parse(release['tag_name']), release.get('html_url'))
for release in response.json()
if 'tag_name' in release]
if versions:
return max(versions)
2020-01-24 10:11:32 +01:00
except Exception:
2020-01-24 00:15:32 +01:00
pass
return 'unknown', None
else:
def get_latest_version():
return None