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).
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
//! `comment-edit <id> [body sources] [repo]` — edit an existing
|
|
//! comment by id.
|
|
|
|
use anyhow::Result;
|
|
use clap::Args as ClapArgs;
|
|
use serde_json::json;
|
|
|
|
use crate::body;
|
|
use crate::client::Client;
|
|
use crate::verbs::print_json;
|
|
|
|
#[derive(ClapArgs)]
|
|
pub struct Args {
|
|
/// Comment id.
|
|
id: u64,
|
|
/// Inline body text.
|
|
#[arg(long, conflicts_with = "body_file")]
|
|
body: Option<String>,
|
|
/// Read body from a file. `-` means stdin.
|
|
#[arg(long = "body-file")]
|
|
body_file: Option<String>,
|
|
}
|
|
|
|
/// # Errors
|
|
///
|
|
/// Propagates any I/O error from the body input (`--body-file`,
|
|
/// stdin), 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 body = body::resolve_required(
|
|
args.body.as_deref(),
|
|
args.body_file.as_deref(),
|
|
"comment-edit",
|
|
)?;
|
|
let repo = client.repo();
|
|
let resp = client.patch_json(
|
|
&format!("/repos/{repo}/issues/comments/{}", args.id),
|
|
&json!({ "body": body }),
|
|
)?;
|
|
print_json(&json!({
|
|
"id": resp.get("id"),
|
|
"user": resp.get("user").and_then(|u| u.get("login")),
|
|
"url": resp.get("html_url"),
|
|
}))
|
|
}
|