dave2wave commented on issue #279:
URL:
https://github.com/apache/tooling-trusted-releases/issues/279#issuecomment-3993538521
@sbp
```python
async def thread_messages(
thread_id: str,
) -> AsyncGenerator[tuple[str, dict[str, Any]]]:
"""Iterate over mailing list thread messages in chronological order."""
thread_url = f"https://lists.apache.org/api/thread.json?id={thread_id}"
try:
async with create_secure_session() as session:
async with session.get(thread_url) as resp:
resp.raise_for_status()
thread_data: Any = await resp.json(content_type=None)
except Exception as exc:
raise FetchError(f"Failed fetching thread metadata for {thread_id}:
{exc}", url=thread_url) from exc
message_ids: set[str] = set()
if isinstance(thread_data, dict):
for email_entry in thread_data.get("emails", []):
if isinstance(email_entry, dict) and (mid :=
email_entry.get("id")):
message_ids.add(str(mid))
_thread_messages_walk(thread_data.get("thread"), message_ids)
if not message_ids:
return
email_urls = [f"https://lists.apache.org/api/email.json?id={mid}" for
mid in message_ids]
messages: list[dict[str, Any]] = []
async for url, status, content in get_urls_as_completed(email_urls):
if (status != 200) or (not content):
log.warning(f"Failed to fetch email data from {url}: {status}")
continue
try:
msg_json = json.loads(content.decode())
messages.append(msg_json)
except Exception as exc:
log.warning(f"Failed to parse email JSON from {url}: {exc}")
messages.sort(key=lambda m: m.get("epoch", 0))
for msg_json in messages:
msg_id = str(msg_json.get("id", ""))
yield msg_id, msg_json
```
I think that error message json like `messages.append(error_json)` should
injected after each of the `log.warning` calls in `async for url...` loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]