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).
52 lines
1.6 KiB
Rust
52 lines
1.6 KiB
Rust
//! `subscription [--watch|--ignore|--unwatch] [repo]` — get or set
|
|
//! the current user's watch subscription for a repo.
|
|
|
|
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 {
|
|
/// Subscribe (watch the repo).
|
|
#[arg(long, group = "action")]
|
|
watch: bool,
|
|
/// Mute (mark ignored).
|
|
#[arg(long, group = "action")]
|
|
ignore: bool,
|
|
/// Unsubscribe (clear watch + ignore).
|
|
#[arg(long, group = "action")]
|
|
unwatch: bool,
|
|
}
|
|
|
|
/// # 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();
|
|
if args.unwatch {
|
|
client.delete(&format!("/repos/{repo}/subscription"), None)?;
|
|
println!("unsubscribed");
|
|
return Ok(());
|
|
}
|
|
if args.watch || args.ignore {
|
|
let (subscribed, ignored) = if args.ignore { (false, true) } else { (true, false) };
|
|
let resp = client.post_json(
|
|
&format!("/repos/{repo}/subscription"),
|
|
&json!({ "subscribed": subscribed, "ignored": ignored }),
|
|
)?;
|
|
return print_json(&json!({
|
|
"subscribed": resp.get("subscribed"),
|
|
"ignored": resp.get("ignored"),
|
|
}));
|
|
}
|
|
let resp: Value = client.get_json(&format!("/repos/{repo}/subscription"))?;
|
|
print_json(&json!({
|
|
"subscribed": resp.get("subscribed"),
|
|
"ignored": resp.get("ignored"),
|
|
}))
|
|
}
|