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>
|
||||
{% endif %}
|
||||
<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>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
@ -88,7 +88,7 @@ class AppAnnouncementHook:
|
||||
|
||||
@hooks.register("app_announcement_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")
|
||||
def test_hook_2():
|
||||
@ -141,10 +141,20 @@ def _current_notifications() -> dict:
|
||||
_fetch_notification_issues_from_gitlab,
|
||||
NOTIFICATION_CACHE_TIME
|
||||
)
|
||||
except requests.HTTPError:
|
||||
logger.warning('Error while getting gitlab notifications', exc_info=True)
|
||||
top_notifications = []
|
||||
else:
|
||||
if notifications:
|
||||
top_notifications = notifications[:5]
|
||||
else:
|
||||
top_notifications = []
|
||||
|
||||
app_notifications = []
|
||||
hooks = get_hooks("app_announcement_hook")
|
||||
items = [fn() for fn in hooks]
|
||||
for hook in items:
|
||||
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(cache.get_or_set(
|
||||
@ -154,14 +164,7 @@ def _current_notifications() -> dict:
|
||||
))
|
||||
"""
|
||||
except requests.HTTPError:
|
||||
logger.warning('Error while getting gitlab notifications', exc_info=True)
|
||||
top_notifications = []
|
||||
application_notifications = []
|
||||
else:
|
||||
if notifications:
|
||||
top_notifications = notifications[:5]
|
||||
else:
|
||||
top_notifications = []
|
||||
logger.warning("Error when getting %s notifications", hook, exc_info=True)
|
||||
|
||||
if app_notifications:
|
||||
application_notifications = app_notifications[:10]
|
||||
@ -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:
|
||||
"""returns a list from the GitHub API. Supports paging"""
|
||||
# TODO actual paging
|
||||
|
||||
result = []
|
||||
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()
|
||||
|
||||
if 'link' in request.headers and 'rel=\"next\"' in request.headers['link']:
|
||||
continue
|
||||
|
||||
# https://docs.github.com/en/rest/using-the-rest-api/using-pagination-in-the-rest-api?apiVersion=2022-11-28
|
||||
# See Example creating a pagination metho
|
||||
if not ('link' in request.headers and 'rel=\"next\"' in request.headers['link']):
|
||||
break
|
||||
|
||||
return result
|
||||
|
Loading…
x
Reference in New Issue
Block a user