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

@ -4,10 +4,11 @@
use anyhow::Result;
use clap::{Args as ClapArgs, ValueEnum};
use serde_json::{Map, Value, json};
use forgejo_api::structs::EditIssueOption;
use serde_json::json;
use crate::body;
use crate::client::Client;
use crate::client::{Client, index};
use crate::verbs::print_json;
#[derive(Copy, Clone, ValueEnum)]
@ -55,7 +56,9 @@ pub struct Args {
pub fn run(client: &Client, args: Args) -> Result<()> {
// Body is partial: only update the body field if a source was
// actually given. Piped stdin without --body/--body-file leaves
// body alone (the partial-update contract).
// body alone (the partial-update contract). Absent fields ride as
// JSON `null`, which Forgejo's partial-update binding treats as
// "leave unchanged".
let body_explicit = args.body.is_some() || args.body_file.is_some();
let body = if body_explicit {
body::resolve(args.body.as_deref(), args.body_file.as_deref())?
@ -63,29 +66,28 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
None
};
let mut payload = Map::new();
if let Some(t) = args.title {
payload.insert("title".into(), Value::String(t));
}
if let Some(b) = body {
payload.insert("body".into(), Value::String(b));
}
if let Some(s) = args.state {
payload.insert("state".into(), Value::String(s.as_str().to_owned()));
}
if let Some(m) = args.milestone {
payload.insert("milestone".into(), Value::Number(m.into()));
}
let payload = EditIssueOption {
assignee: None,
assignees: None,
body,
due_date: None,
milestone: args.milestone.map(index).transpose()?,
r#ref: None,
state: args.state.map(|s| s.as_str().to_owned()),
title: args.title,
unset_due_date: None,
updated_at: None,
};
let repo = client.repo();
let resp = client.patch_json(
&format!("/repos/{repo}/issues/{}", args.number),
&Value::Object(payload),
)?;
let (owner, name) = client.owner_repo()?;
let resp = client
.api()
.issue_edit_issue(owner, name, index(args.number)?, payload)
.send()?;
print_json(&json!({
"number": resp.get("number"),
"title": resp.get("title"),
"state": resp.get("state"),
"milestone": resp.get("milestone").and_then(|m| m.get("title")),
"number": resp.number,
"title": resp.title,
"state": resp.state,
"milestone": resp.milestone.as_ref().and_then(|m| m.title.as_deref()),
}))
}