//! `pr-reviews [repo]` — list PR reviews with id/state/user/body. use anyhow::Result; use clap::Args as ClapArgs; use serde_json::{Value, json}; use crate::client::Client; use crate::verbs::print_json; #[derive(ClapArgs)] pub struct Args { /// PR number. number: u64, } /// # Errors /// /// Propagates any transport error from the Forgejo REST call /// (network unreachable, 4xx/5xx response, token missing/invalid) /// and any I/O error from writing the response to stdout. pub fn run(client: &Client, args: Args) -> Result<()> { let repo = client.repo(); let v = client.get_json(&format!("/repos/{repo}/pulls/{}/reviews", args.number))?; let trimmed: Vec = v .as_array() .map(|a| { a.iter() .map(|r| { json!({ "id": r.get("id"), "state": r.get("state"), "user": r.get("user").and_then(|u| u.get("login")), "body": r.get("body"), "comments_count": r.get("comments_count"), }) }) .collect() }) .unwrap_or_default(); print_json(&Value::Array(trimmed)) }