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

@ -25,10 +25,10 @@ use std::process::{Command, Stdio};
use anyhow::{Context, Result};
use clap::Args as ClapArgs;
use serde_json::{Value, json};
use forgejo_api::structs::{CreatePullRequestOption, EditIssueOption};
use crate::body;
use crate::client::Client;
use crate::client::{Client, index};
#[derive(ClapArgs)]
pub struct Args {
@ -97,17 +97,27 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
if args.push {
push_branch(remote, head)?;
}
let repo = client.repo();
let payload = json!({
"title": args.title,
"head": head,
"base": args.base,
"body": body,
"draft": args.draft,
"allow_maintainer_edit": true,
});
let resp = client.post_json(&format!("/repos/{repo}/pulls"), &payload)?;
if let Some(url) = resp.get("html_url").and_then(Value::as_str) {
let (owner, name) = client.owner_repo()?;
// Note: Forgejo's CreatePullRequestOption has no `draft` /
// `allow_maintainer_edit` fields (verified against the instance's
// swagger) — the raw client used to send both and the server
// silently dropped them, so omitting them here changes nothing.
let payload = CreatePullRequestOption {
assignee: None,
assignees: None,
base: Some(args.base.clone()),
body: Some(body),
due_date: None,
head: Some(head.to_owned()),
labels: None,
milestone: None,
title: Some(args.title.clone()),
};
let resp = client
.api()
.repo_create_pull_request(owner, name, payload)
.send()?;
if let Some(url) = resp.html_url {
println!("{url}");
}
Ok(())
@ -182,12 +192,23 @@ fn agit_create(client: &Client, args: &Args, body: &str) -> Result<()> {
};
if deferred_body {
if let Some(number) = pr_number_from_url(&url) {
let repo = client.repo();
let (owner, name) = client.owner_repo()?;
let payload = EditIssueOption {
assignee: None,
assignees: None,
body: Some(body.to_owned()),
due_date: None,
milestone: None,
r#ref: None,
state: None,
title: None,
unset_due_date: None,
updated_at: None,
};
client
.patch_json(
&format!("/repos/{repo}/issues/{number}"),
&json!({ "body": body }),
)
.api()
.issue_edit_issue(owner, name, index(number)?, payload)
.send()
.with_context(|| format!("set body on AGit PR #{number}"))?;
} else {
eprintln!(