systemic gap argus flagged on PR #798 (timeline verb). every `pub fn run` in hive-forge/src/verbs/*.rs lacked a `# Errors` block — violates Rust API guidelines + obscures the failure surface for operators reading the source. uniform doc per verb category: - pure GET + print verbs: "transport error from the Forgejo REST call + I/O error from stdout" - body-from-file verbs (comment/comment_edit/issue_create/issue_edit/ pr_create): adds 'I/O error from --body-file/stdin input' - file-upload verbs (attach-issue, attach-comment): adds 'file read/exist check' - pr_create: also mentions the --push shellout 23 `pub fn run` signatures touched. no behaviour change; pure documentation sweep. cargo test green (38 tests).
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
//! `pr-reviews <number> [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<Value> = 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))
|
|
}
|