mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-13 06:20:16 +02:00
Only show open announcements
This commit is contained in:
parent
74eb8621d9
commit
40824156bf
@ -27,7 +27,7 @@ GITLAB_AUTH_REPOSITORY_TAGS_URL = (
|
||||
)
|
||||
GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL = (
|
||||
'https://gitlab.com/api/v4/projects/allianceauth%2Fallianceauth/issues'
|
||||
'?labels=announcement'
|
||||
'?labels=announcement&state=opened'
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -36,7 +36,7 @@ logger = logging.getLogger(__name__)
|
||||
@register.inclusion_tag('allianceauth/admin-status/overview.html')
|
||||
def status_overview() -> dict:
|
||||
response = {
|
||||
'notifications': list(),
|
||||
'notifications': list(),
|
||||
'current_version': __version__,
|
||||
'task_queue_length': -1,
|
||||
}
|
||||
@ -51,7 +51,7 @@ def _fetch_celery_queue_length() -> int:
|
||||
app = app_or_default(None)
|
||||
with app.connection_or_acquire() as conn:
|
||||
return conn.default_channel.queue_declare(
|
||||
queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'),
|
||||
queue=getattr(settings, 'CELERY_DEFAULT_QUEUE', 'celery'),
|
||||
passive=True
|
||||
).message_count
|
||||
except amqp.exceptions.ChannelError:
|
||||
@ -63,13 +63,13 @@ def _fetch_celery_queue_length() -> int:
|
||||
|
||||
|
||||
def _current_notifications() -> dict:
|
||||
"""returns the newest 5 announcement issues"""
|
||||
"""returns the newest 5 announcement issues"""
|
||||
try:
|
||||
notifications = cache.get_or_set(
|
||||
'gitlab_notification_issues',
|
||||
'gitlab_notification_issues',
|
||||
_fetch_notification_issues_from_gitlab,
|
||||
NOTIFICATION_CACHE_TIME
|
||||
)
|
||||
)
|
||||
except requests.RequestException:
|
||||
logger.exception('Error while getting gitlab notifications')
|
||||
top_notifications = []
|
||||
@ -78,19 +78,19 @@ def _current_notifications() -> dict:
|
||||
top_notifications = notifications[:5]
|
||||
else:
|
||||
top_notifications = []
|
||||
|
||||
|
||||
response = {
|
||||
'notifications': top_notifications,
|
||||
}
|
||||
return response
|
||||
|
||||
|
||||
def _fetch_notification_issues_from_gitlab() -> list:
|
||||
def _fetch_notification_issues_from_gitlab() -> list:
|
||||
return _fetch_list_from_gitlab(GITLAB_AUTH_ANNOUNCEMENT_ISSUES_URL, max_pages=10)
|
||||
|
||||
|
||||
def _current_version_summary() -> dict:
|
||||
"""returns the current version info"""
|
||||
"""returns the current version info"""
|
||||
try:
|
||||
tags = cache.get_or_set(
|
||||
'git_release_tags', _fetch_tags_from_gitlab, TAG_CACHE_TIME
|
||||
@ -98,16 +98,16 @@ def _current_version_summary() -> dict:
|
||||
except requests.RequestException:
|
||||
logger.exception('Error while getting gitlab release tags')
|
||||
return {}
|
||||
|
||||
|
||||
if not tags:
|
||||
return {}
|
||||
|
||||
|
||||
(
|
||||
latest_major_version,
|
||||
latest_minor_version,
|
||||
latest_patch_version,
|
||||
latest_major_version,
|
||||
latest_minor_version,
|
||||
latest_patch_version,
|
||||
latest_beta_version
|
||||
) = _latests_versions(tags)
|
||||
) = _latests_versions(tags)
|
||||
current_version = Pep440Version(__version__)
|
||||
|
||||
has_latest_major = \
|
||||
@ -121,7 +121,7 @@ def _current_version_summary() -> dict:
|
||||
and latest_major_version.base_version <= latest_beta_version.base_version \
|
||||
if latest_beta_version else False
|
||||
|
||||
response = {
|
||||
response = {
|
||||
'latest_major': has_latest_major,
|
||||
'latest_minor': has_latest_minor,
|
||||
'latest_patch': has_latest_patch,
|
||||
@ -131,7 +131,7 @@ def _current_version_summary() -> dict:
|
||||
'latest_minor_version': str(latest_minor_version),
|
||||
'latest_patch_version': str(latest_patch_version),
|
||||
'latest_beta_version': str(latest_beta_version)
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
|
||||
@ -141,14 +141,14 @@ def _fetch_tags_from_gitlab():
|
||||
|
||||
def _latests_versions(tags: list) -> tuple:
|
||||
"""returns latests version from given tags list
|
||||
|
||||
|
||||
Non-compliant tags will be ignored
|
||||
"""
|
||||
versions = list()
|
||||
betas = list()
|
||||
for tag in tags:
|
||||
try:
|
||||
version = Pep440Version(tag.get('name'))
|
||||
version = Pep440Version(tag.get('name'))
|
||||
except InvalidVersion:
|
||||
pass
|
||||
else:
|
||||
@ -162,21 +162,21 @@ def _latests_versions(tags: list) -> tuple:
|
||||
v for v in versions if v.major == latest_version.major
|
||||
])
|
||||
latest_minor_version = min([
|
||||
v for v in versions
|
||||
v for v in versions
|
||||
if v.major == latest_version.major and v.minor == latest_version.minor
|
||||
])
|
||||
latest_beta_version = max(betas)
|
||||
return (
|
||||
latest_major_version,
|
||||
latest_minor_version,
|
||||
latest_patch_version,
|
||||
latest_major_version,
|
||||
latest_minor_version,
|
||||
latest_patch_version,
|
||||
latest_beta_version
|
||||
)
|
||||
|
||||
|
||||
def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list:
|
||||
"""returns a list from the GitLab API. Supports pageing"""
|
||||
result = list()
|
||||
result = list()
|
||||
for page in range(1, max_pages + 1):
|
||||
request = requests.get(
|
||||
url, params={'page': page}, timeout=REQUESTS_TIMEOUT
|
||||
@ -190,8 +190,8 @@ def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list:
|
||||
total_pages = None
|
||||
else:
|
||||
total_pages = None
|
||||
|
||||
|
||||
if not total_pages or page >= total_pages:
|
||||
break
|
||||
|
||||
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user