hyperhive/hive-forge/src/verbs/tree_sha.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

38 lines
1.2 KiB
Rust

//! `tree-sha <ref> [repo]` — print the tree SHA of the commit at a
//! branch name or commit SHA.
use anyhow::Result;
use clap::Args as ClapArgs;
use serde_json::Value;
use crate::client::Client;
#[derive(ClapArgs)]
pub struct Args {
/// Branch name or commit SHA.
reference: String,
}
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo();
// Try branch first; the bash helper silently treats failure as
// "not a branch, use the reference as a commit sha directly".
let commit_sha = match client.get_json(&format!("/repos/{repo}/branches/{}", args.reference)) {
Ok(v) => v
.get("commit")
.and_then(|c| c.get("id"))
.and_then(Value::as_str)
.unwrap_or(&args.reference)
.to_owned(),
Err(_) => args.reference.clone(),
};
let commit = client.get_json(&format!("/repos/{repo}/git/commits/{commit_sha}"))?;
let sha = commit
.get("tree")
.and_then(|t| t.get("sha"))
.and_then(Value::as_str)
.or_else(|| commit.get("sha").and_then(Value::as_str))
.unwrap_or("");
println!("{sha}");
Ok(())
}