pacsea/sources/comments.rs
1//! AUR package comments fetched through arch-toolkit.
2
3use crate::integrations::arch_toolkit::ToolkitContext;
4use crate::state::types::AurComment;
5
6/// Result type alias for AUR comments fetching operations.
7type Result<T> = super::Result<T>;
8
9/// What: Fetch AUR package comments through arch-toolkit.
10///
11/// Inputs:
12/// - `pkgname`: Package name to fetch comments for.
13///
14/// Output:
15/// - Parsed comments with stable IDs, timestamps, links, formatting, and pinned status.
16///
17/// # Errors
18///
19/// Returns an error when client construction, bounded retrieval, validation, or parsing fails.
20///
21/// Details:
22/// - Standalone callers construct a configured context; runtime workers share one context through
23/// [`fetch_aur_comments_with_context`]. arch-toolkit bounds the streamed response to 10 MiB.
24pub async fn fetch_aur_comments(pkgname: String) -> Result<Vec<AurComment>> {
25 let context = ToolkitContext::new()?;
26 fetch_aur_comments_with_context(&context, pkgname).await
27}
28
29/// What: Fetch AUR comments with a caller-owned shared toolkit context.
30///
31/// Inputs:
32/// - `context`: Runtime integration context.
33/// - `pkgname`: Package name to fetch.
34///
35/// Output:
36/// - Pacsea comments or an actionable error.
37///
38/// # Errors
39///
40/// Returns an error when bounded toolkit retrieval or comment parsing fails.
41///
42/// Details:
43/// - Toolkit values are converted inside the anti-corruption layer.
44pub async fn fetch_aur_comments_with_context(
45 context: &ToolkitContext,
46 pkgname: String,
47) -> Result<Vec<AurComment>> {
48 crate::integrations::arch_toolkit::aur::comments(context, &pkgname)
49 .await
50 .map_err(Into::into)
51}