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
Sander Steffann 405d93c6f2 Update versions.py
2020-02-27 18:26:15 +01:00

28 lines
892 B
Python

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)
except Exception:
pass
return 'unknown', None
else:
def get_latest_version():
return None