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,13 @@
//! `comment-edit <id> [body sources] [repo]` — edit an existing
//! comment by id.
use anyhow::Result;
use anyhow::{Result, bail};
use clap::Args as ClapArgs;
use forgejo_api::structs::EditIssueCommentOption;
use serde_json::json;
use crate::body;
use crate::client::Client;
use crate::client::{Client, index};
use crate::verbs::print_json;
#[derive(ClapArgs)]
@ -33,14 +34,26 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
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 }),
)?;
let (owner, name) = client.owner_repo()?;
let Some(resp) = client
.api()
.issue_edit_comment(
owner,
name,
index(args.id)?,
EditIssueCommentOption {
body,
updated_at: None,
},
)
.send()?
else {
// Forgejo answers 204 (no content) when the edit was a no-op.
bail!("hive-forge comment-edit: comment {} not updated", args.id);
};
print_json(&json!({
"id": resp.get("id"),
"user": resp.get("user").and_then(|u| u.get("login")),
"url": resp.get("html_url"),
"id": resp.id,
"user": resp.user.as_ref().and_then(|u| u.login.as_deref()),
"url": resp.html_url,
}))
}