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

@ -3,7 +3,7 @@
use anyhow::Result;
use clap::Args as ClapArgs;
use serde_json::{Value, json};
use forgejo_api::structs::CreateIssueOption;
use crate::body;
use crate::client::Client;
@ -32,13 +32,23 @@ pub struct Args {
/// I/O error from writing the issue URL to stdout.
pub fn run(client: &Client, args: Args) -> Result<()> {
let body = body::resolve(args.body.as_deref(), args.body_file.as_deref())?.unwrap_or_default();
let repo = client.repo();
let mut payload = json!({ "title": args.title, "body": body });
if let Some(a) = args.assignee {
payload["assignees"] = json!([a]);
}
let resp = client.post_json(&format!("/repos/{repo}/issues"), &payload)?;
if let Some(url) = resp.get("html_url").and_then(Value::as_str) {
let (owner, name) = client.owner_repo()?;
let payload = CreateIssueOption {
assignee: None,
assignees: args.assignee.map(|a| vec![a]),
body: Some(body),
closed: None,
due_date: None,
labels: None,
milestone: None,
r#ref: None,
title: args.title,
};
let issue = client
.api()
.issue_create_issue(owner, name, payload)
.send()?;
if let Some(url) = issue.html_url {
println!("{url}");
}
Ok(())