mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-17 08:20:16 +02:00
Upgrades
- Error handling per hook - Fix github redirect - Better code for github pagination
This commit is contained in:
parent
1c1e219037
commit
cd9d985732
@ -63,7 +63,7 @@
|
|||||||
<span class="badge bg-danger me-2">{% translate "Closed" %}</span>
|
<span class="badge bg-danger me-2">{% translate "Closed" %}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="badge bg-info me-2">{{ notif.app_name }}</span>
|
<span class="badge bg-info me-2">{{ notif.app_name }}</span>
|
||||||
<a href="{{ notif.web_url }}{{ notif.url }}" target="_blank">#{{ notif.iid }}{{ notif.number }} {{ notif.title }}</a>
|
<a href="{{ notif.web_url }}{{ notif.html_url }}" target="_blank">#{{ notif.iid }}{{ notif.number }} {{ notif.title }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -88,7 +88,7 @@ class AppAnnouncementHook:
|
|||||||
|
|
||||||
@hooks.register("app_announcement_hook")
|
@hooks.register("app_announcement_hook")
|
||||||
def test_hook():
|
def test_hook():
|
||||||
return AppAnnouncementHook("test GitHub app", "r0kym/allianceauth-example-plugin", RepositoryKind.GITLAB)
|
return AppAnnouncementHook("test GitLab app", "r0kym/allianceauth-example-plugin", RepositoryKind.GITLAB)
|
||||||
|
|
||||||
@hooks.register("app_announcement_hook")
|
@hooks.register("app_announcement_hook")
|
||||||
def test_hook_2():
|
def test_hook_2():
|
||||||
@ -141,10 +141,20 @@ def _current_notifications() -> dict:
|
|||||||
_fetch_notification_issues_from_gitlab,
|
_fetch_notification_issues_from_gitlab,
|
||||||
NOTIFICATION_CACHE_TIME
|
NOTIFICATION_CACHE_TIME
|
||||||
)
|
)
|
||||||
app_notifications = []
|
except requests.HTTPError:
|
||||||
hooks = get_hooks("app_announcement_hook")
|
logger.warning('Error while getting gitlab notifications', exc_info=True)
|
||||||
items = [fn() for fn in hooks]
|
top_notifications = []
|
||||||
for hook in items:
|
else:
|
||||||
|
if notifications:
|
||||||
|
top_notifications = notifications[:5]
|
||||||
|
else:
|
||||||
|
top_notifications = []
|
||||||
|
|
||||||
|
app_notifications = []
|
||||||
|
hooks = [fn() for fn in get_hooks("app_announcement_hook")]
|
||||||
|
for hook in hooks:
|
||||||
|
logger.info(hook)
|
||||||
|
try:
|
||||||
app_notifications.extend(hook.get_announcement_list())
|
app_notifications.extend(hook.get_announcement_list())
|
||||||
"""
|
"""
|
||||||
app_notifications.extend(cache.get_or_set(
|
app_notifications.extend(cache.get_or_set(
|
||||||
@ -153,20 +163,13 @@ def _current_notifications() -> dict:
|
|||||||
NOTIFICATION_CACHE_TIME,
|
NOTIFICATION_CACHE_TIME,
|
||||||
))
|
))
|
||||||
"""
|
"""
|
||||||
except requests.HTTPError:
|
except requests.HTTPError:
|
||||||
logger.warning('Error while getting gitlab notifications', exc_info=True)
|
logger.warning("Error when getting %s notifications", hook, exc_info=True)
|
||||||
top_notifications = []
|
|
||||||
application_notifications = []
|
|
||||||
else:
|
|
||||||
if notifications:
|
|
||||||
top_notifications = notifications[:5]
|
|
||||||
else:
|
|
||||||
top_notifications = []
|
|
||||||
|
|
||||||
if app_notifications:
|
if app_notifications:
|
||||||
application_notifications = app_notifications[:10]
|
application_notifications = app_notifications[:10]
|
||||||
else:
|
else:
|
||||||
application_notifications = []
|
application_notifications = []
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'notifications': top_notifications,
|
'notifications': top_notifications,
|
||||||
@ -282,7 +285,6 @@ def _fetch_list_from_gitlab(url: str, max_pages: int = MAX_PAGES) -> list:
|
|||||||
|
|
||||||
def _fetch_list_from_github(url: str, max_pages: int = MAX_PAGES) -> list:
|
def _fetch_list_from_github(url: str, max_pages: int = MAX_PAGES) -> list:
|
||||||
"""returns a list from the GitHub API. Supports paging"""
|
"""returns a list from the GitHub API. Supports paging"""
|
||||||
# TODO actual paging
|
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for page in range(1, max_pages+1):
|
for page in range(1, max_pages+1):
|
||||||
@ -308,9 +310,9 @@ def _fetch_list_from_github(url: str, max_pages: int = MAX_PAGES) -> list:
|
|||||||
|
|
||||||
result += request.json()
|
result += request.json()
|
||||||
|
|
||||||
if 'link' in request.headers and 'rel=\"next\"' in request.headers['link']:
|
# https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api?apiVersion=2022-11-28
|
||||||
continue
|
# See Example creating a pagination metho
|
||||||
|
if not ('link' in request.headers and 'rel=\"next\"' in request.headers['link']):
|
||||||
break
|
break
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
x
Reference in New Issue
Block a user