Archived
feat: add unread updates to My Work (#133)
This commit is contained in:
1 parent
d75a55f3f7
commit
f34fc8b5f5
7 files changed
+336
-13
No files matched your search
@@ -2,6 +2,7 @@ import asyncio
|
||||
import os
|
||||
import shlex
|
||||
from typing import Any
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -117,6 +118,69 @@ async def issues() -> list[dict]:
|
||||
)
|
||||
|
||||
|
||||
def _safe_web_url(value: Any) -> str:
|
||||
if not isinstance(value, str):
|
||||
return ""
|
||||
parsed = urlsplit(value)
|
||||
return value if parsed.scheme in {"http", "https"} and parsed.netloc else ""
|
||||
|
||||
|
||||
async def notifications() -> list[dict]:
|
||||
threads = await fetch("notifications?status-types=unread&limit=50")
|
||||
if not isinstance(threads, list):
|
||||
raise ValueError("Gitea notification response was not a list")
|
||||
normalized = []
|
||||
for thread in threads:
|
||||
if not isinstance(thread, dict):
|
||||
continue
|
||||
repository = thread.get("repository")
|
||||
subject = thread.get("subject")
|
||||
repository = repository if isinstance(repository, dict) else {}
|
||||
subject = subject if isinstance(subject, dict) else {}
|
||||
subject_url = _safe_web_url(subject.get("html_url"))
|
||||
latest_url = _safe_web_url(subject.get("latest_comment_html_url"))
|
||||
number_text = (
|
||||
urlsplit(subject_url).path.rstrip("/").rsplit("/", 1)[-1]
|
||||
if subject_url
|
||||
else ""
|
||||
)
|
||||
normalized.append(
|
||||
{
|
||||
"id": thread.get("id"),
|
||||
"unread": thread.get("unread") is True,
|
||||
"updated_at": (
|
||||
thread.get("updated_at")
|
||||
if isinstance(thread.get("updated_at"), str)
|
||||
else ""
|
||||
),
|
||||
"repository": (
|
||||
repository.get("full_name")
|
||||
if isinstance(repository.get("full_name"), str)
|
||||
else ""
|
||||
),
|
||||
"number": int(number_text) if number_text.isdigit() else None,
|
||||
"title": (
|
||||
subject.get("title")
|
||||
if isinstance(subject.get("title"), str) and subject.get("title")
|
||||
else "Untitled update"
|
||||
),
|
||||
"subject_type": (
|
||||
subject.get("type")
|
||||
if isinstance(subject.get("type"), str) and subject.get("type")
|
||||
else "Update"
|
||||
),
|
||||
"state": (
|
||||
subject.get("state")
|
||||
if isinstance(subject.get("state"), str)
|
||||
else ""
|
||||
),
|
||||
"url": latest_url or subject_url,
|
||||
"subject_url": subject_url,
|
||||
}
|
||||
)
|
||||
return normalized
|
||||
|
||||
|
||||
async def pull_requests() -> list[dict]:
|
||||
assigned, review_requested = await asyncio.gather(
|
||||
fetch("repos/issues/search?state=open&assigned=true&type=pulls&limit=50"),
|
||||
|
||||
Reference in new issue
Block a user