Update admin status to work with gitlab

This commit is contained in:
Basraah 2018-10-09 19:43:44 +10:00
parent 4947e0c483
commit d37a543c39
2 changed files with 15 additions and 18 deletions

View File

@ -13,14 +13,14 @@
{% else %} {% else %}
<span class="label label-danger">{% trans "Closed" %}</span> <span class="label label-danger">{% trans "Closed" %}</span>
{% endif %} {% endif %}
<a href="{{ notif.html_url }}" target="_blank">#{{ notif.number }} {{ notif.title }}</a> <a href="{{ notif.web_url }}" target="_blank">#{{ notif.number }} {{ notif.title }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<div class="text-right" style="position:absolute;bottom:5px;right:5px;"> <div class="text-right" style="position:absolute;bottom:5px;right:5px;">
<a href="https://github.com/allianceauth/allianceauth/issues"><span class="label label-default"> <a href="https://gitlab.com/allianceauth/allianceauth/issues"><span class="label" style="background-color:#e65328;">
<i class="fa fa-github" aria-hidden="true"></i> Powered by Github</span> <i class="fa fa-gitlab" aria-hidden="true"></i> Powered by GitLab</span>
</a> </a>
</div> </div>
</div> </div>
@ -39,7 +39,7 @@
<li class="list-group-item list-group-item-{% if latest_major %}success{% else %}warning{% endif %}"> <li class="list-group-item list-group-item-{% if latest_major %}success{% else %}warning{% endif %}">
<h4 class="list-group-item-heading">{% trans "Latest Major" %}</h4> <h4 class="list-group-item-heading">{% trans "Latest Major" %}</h4>
<p class="list-group-item-text"> <p class="list-group-item-text">
<a href="{{ latest_major_url }}" style="color:#000"><i class="fa fa-github" aria-hidden="true"></i> <a href="https://gitlab.com/allianceauth/allianceauth/tags" style="color:#000"><i class="fa fa-gitlab" aria-hidden="true"></i>
{{ latest_major_version }} {{ latest_major_version }}
</a> </a>
{% if not latest_major %}<br>{% trans "Update available" %}{% endif %} {% if not latest_major %}<br>{% trans "Update available" %}{% endif %}
@ -48,7 +48,7 @@
<li class="list-group-item list-group-item-{% if latest_minor %}success{% else %}warning{% endif %}"> <li class="list-group-item list-group-item-{% if latest_minor %}success{% else %}warning{% endif %}">
<h4 class="list-group-item-heading">{% trans "Latest Minor" %}</h4> <h4 class="list-group-item-heading">{% trans "Latest Minor" %}</h4>
<p class="list-group-item-text"> <p class="list-group-item-text">
<a href="{{ latest_minor_url }}" style="color:#000"><i class="fa fa-github" aria-hidden="true"></i> <a href="https://gitlab.com/allianceauth/allianceauth/tags" style="color:#000"><i class="fa fa-gitlab" aria-hidden="true"></i>
{{ latest_minor_version }} {{ latest_minor_version }}
</a> </a>
{% if not latest_minor %}<br>{% trans "Update available" %}{% endif %} {% if not latest_minor %}<br>{% trans "Update available" %}{% endif %}
@ -57,7 +57,7 @@
<li class="list-group-item list-group-item-{% if latest_patch %}success{% else %}danger{% endif %}"> <li class="list-group-item list-group-item-{% if latest_patch %}success{% else %}danger{% endif %}">
<h4 class="list-group-item-heading">{% trans "Latest Patch" %}</h4> <h4 class="list-group-item-heading">{% trans "Latest Patch" %}</h4>
<p class="list-group-item-text"> <p class="list-group-item-text">
<a href="{{ latest_patch_url }}" style="color:#000"><i class="fa fa-github" aria-hidden="true"></i> <a href="https://gitlab.com/allianceauth/allianceauth/tags" style="color:#000"><i class="fa fa-gitlab" aria-hidden="true"></i>
{{ latest_patch_version }} {{ latest_patch_version }}
</a> </a>
{% if not latest_patch %}<br>{% trans "Update available" %}{% endif %} {% if not latest_patch %}<br>{% trans "Update available" %}{% endif %}

View File

@ -17,16 +17,16 @@ NOTIFICATION_CACHE_TIME = 300 # 5 minutes
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def get_github_tags(): def get_git_tags():
request = requests.get('https://api.github.com/repos/allianceauth/allianceauth/releases') request = requests.get('https://gitlab.com/api/v4/projects/allianceauth%2Fallianceauth/repository/tags')
request.raise_for_status() request.raise_for_status()
return request.json() return request.json()
def get_github_notification_issues(): def get_notification_issues():
# notification # notification
request = requests.get( request = requests.get(
'https://api.github.com/repos/allianceauth/allianceauth/issues?labels=announcement&state=all') 'https://gitlab.com/api/v4/projects/allianceauth%2Fallianceauth/issues?labels=announcement')
request.raise_for_status() request.raise_for_status()
return request.json() return request.json()
@ -68,10 +68,10 @@ def get_notifications():
'notifications': list(), 'notifications': list(),
} }
try: try:
notifications = cache.get_or_set('github_notification_issues', get_github_notification_issues, notifications = cache.get_or_set('gitlab_notification_issues', get_notification_issues,
NOTIFICATION_CACHE_TIME) NOTIFICATION_CACHE_TIME)
# Limit notifications to those posted by repo owners and members # Limit notifications to those posted by repo owners and members
response['notifications'] += [n for n in notifications if n['author_association'] in ['OWNER', 'MEMBER']][:5] response['notifications'] += notifications[:5]
except requests.RequestException: except requests.RequestException:
logger.exception('Error while getting github notifications') logger.exception('Error while getting github notifications')
return response return response
@ -85,7 +85,7 @@ def get_version_info():
'current_version': __version__, 'current_version': __version__,
} }
try: try:
tags = cache.get_or_set('github_release_tags', get_github_tags, TAG_CACHE_TIME) tags = cache.get_or_set('git_release_tags', get_git_tags, TAG_CACHE_TIME)
current_ver = semver.Version.coerce(__version__) current_ver = semver.Version.coerce(__version__)
# Set them all to the current version to start # Set them all to the current version to start
@ -102,7 +102,7 @@ def get_version_info():
}) })
for tag in tags: for tag in tags:
tag_name = tag.get('tag_name') tag_name = tag.get('name')
if tag_name[0] == 'v': if tag_name[0] == 'v':
# Strip 'v' off front of verison if it exists # Strip 'v' off front of verison if it exists
tag_name = tag_name[1:] tag_name = tag_name[1:]
@ -114,24 +114,21 @@ def get_version_info():
if latest_major is None or tag_ver > latest_major: if latest_major is None or tag_ver > latest_major:
latest_major = tag_ver latest_major = tag_ver
response['latest_major_version'] = tag_name response['latest_major_version'] = tag_name
response['latest_major_url'] = tag['html_url']
if tag_ver.major > current_ver.major: if tag_ver.major > current_ver.major:
response['latest_major'] = False response['latest_major'] = False
elif tag_ver.major == current_ver.major: elif tag_ver.major == current_ver.major:
if latest_minor is None or tag_ver > latest_minor: if latest_minor is None or tag_ver > latest_minor:
latest_minor = tag_ver latest_minor = tag_ver
response['latest_minor_version'] = tag_name response['latest_minor_version'] = tag_name
response['latest_minor_url'] = tag['html_url']
if tag_ver.minor > current_ver.minor: if tag_ver.minor > current_ver.minor:
response['latest_minor'] = False response['latest_minor'] = False
elif tag_ver.minor == current_ver.minor: elif tag_ver.minor == current_ver.minor:
if latest_patch is None or tag_ver > latest_patch: if latest_patch is None or tag_ver > latest_patch:
latest_patch = tag_ver latest_patch = tag_ver
response['latest_patch_version'] = tag_name response['latest_patch_version'] = tag_name
response['latest_patch_url'] = tag['html_url']
if tag_ver.patch > current_ver.patch: if tag_ver.patch > current_ver.patch:
response['latest_patch'] = False response['latest_patch'] = False
except requests.RequestException: except requests.RequestException:
logger.exception('Error while getting github release tags') logger.exception('Error while getting gitlab release tags')
return response return response