hyperhive/hive-forge/src/verbs/view.rs
damocles d59bfb899f hive-forge: drop boilerplate # Errors from pure-GET verbs (mara on #827, option A)
mara: 'those comments seem very redundant'. true — the 16 pure-GET
verbs all got the same 'transport error + stdout I/O' boilerplate,
which just restates the Result<()> contract that's trivially
derivable from the type.

dropped # Errors from: assign, branches, close, comment_show,
comments, diff, issue, labels, lint, list, milestone, pr,
pr_reviews, subscription, timeline, tree_sha, view (17 files).

kept on the 7 verbs that have a non-Forgejo failure surface worth
documenting:
- comment, comment_edit, issue_create, issue_edit — body input I/O
  via --body-file / stdin
- pr_create — body input + --push shellout to git
- attach::run_issue, attach::run_comment — explicit bail! on
  missing file

net: 23 verbs touched in the original PR → 17 trimmed back to
no-doc, 6 kept (with the 7th call being attach::run_comment in the
same file). 38 tests still pass.
2026-05-31 16:22:05 +02:00

60 lines
1.7 KiB
Rust

//! `view <number> [repo]` — dump title + body + all comments as
//! markdown.
use anyhow::Result;
use clap::Args as ClapArgs;
use serde_json::Value;
use crate::client::Client;
#[derive(ClapArgs)]
pub struct Args {
/// Issue or PR number.
number: u64,
}
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo();
let issue = client.get_json(&format!("/repos/{repo}/issues/{}", args.number))?;
let title = issue.get("title").and_then(Value::as_str).unwrap_or("");
let body = issue.get("body").and_then(Value::as_str).unwrap_or("");
let state = issue.get("state").and_then(Value::as_str).unwrap_or("?");
let user = issue
.get("user")
.and_then(|u| u.get("login"))
.and_then(Value::as_str)
.unwrap_or("?");
let kind = if issue.get("pull_request").is_some_and(|p| !p.is_null()) {
"PR"
} else {
"issue"
};
println!("# {kind} #{} [{state}] by {user}", args.number);
println!("{title}");
if !body.is_empty() {
println!();
println!("{body}");
}
let comments = client.get_json(&format!(
"/repos/{repo}/issues/{}/comments?limit=50",
args.number
))?;
let arr = comments.as_array().cloned().unwrap_or_default();
if !arr.is_empty() {
println!();
println!("---");
println!("## Comments ({})", arr.len());
println!();
for c in &arr {
let cu = c
.get("user")
.and_then(|u| u.get("login"))
.and_then(Value::as_str)
.unwrap_or("?");
let cb = c.get("body").and_then(Value::as_str).unwrap_or("");
println!("**{cu}**: {cb}");
println!();
}
}
Ok(())
}