refactor(hive-forge): port CLI verbs to forgejo-api

This commit is contained in:
müde 2026-07-07 09:24:53 +02:00
commit 4636987469
36 changed files with 1463 additions and 1153 deletions

View file

@ -1,12 +1,12 @@
//! `comment-show <id>` — print the body (or full JSON envelope
//! when `--json` is set globally) of a single comment by id.
use anyhow::Result;
use anyhow::{Result, bail};
use clap::Args as ClapArgs;
use serde_json::{Value, json};
use serde_json::json;
use crate::client::Client;
use crate::verbs::print_json;
use crate::client::{Client, index};
use crate::verbs::{print_json, rfc3339};
#[derive(ClapArgs)]
pub struct Args {
@ -15,20 +15,26 @@ pub struct Args {
}
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo();
let v = client.get_json(&format!("/repos/{repo}/issues/comments/{}", args.id))?;
let (owner, name) = client.owner_repo()?;
let Some(c) = client
.api()
.issue_get_comment(owner, name, index(args.id)?)
.send()?
else {
bail!("hive-forge comment-show: comment {} not found", args.id);
};
if client.json_mode() {
let trimmed = json!({
"id": v.get("id"),
"user": v.get("user").and_then(|u| u.get("login")),
"created_at": v.get("created_at"),
"updated_at": v.get("updated_at"),
"body": v.get("body"),
"url": v.get("html_url"),
"id": c.id,
"user": c.user.as_ref().and_then(|u| u.login.as_deref()),
"created_at": rfc3339(c.created_at),
"updated_at": rfc3339(c.updated_at),
"body": c.body,
"url": c.html_url,
});
print_json(&trimmed)
} else {
let body = v.get("body").and_then(Value::as_str).unwrap_or("");
let body = c.body.as_deref().unwrap_or("");
println!("{body}");
Ok(())
}