hive-forge: rewrite bash CLI helper as a rust binary (closes #280)

This commit is contained in:
damocles 2026-05-25 01:30:44 +02:00 committed by Mara
commit 595e3c040c
28 changed files with 1434 additions and 612 deletions

View file

@ -0,0 +1,51 @@
//! `pr-create --title <t> --head <branch> [--base <b>] [body sources]
//! [--draft] [repo]` — create a PR. Prints the PR URL.
use anyhow::Result;
use clap::Args as ClapArgs;
use serde_json::{Value, json};
use crate::body;
use crate::client::Client;
#[derive(ClapArgs)]
pub struct Args {
/// PR title.
#[arg(long)]
title: String,
/// Head branch.
#[arg(long)]
head: String,
/// Base branch (default: main).
#[arg(long, default_value = "main")]
base: String,
/// Inline body text.
#[arg(long, conflicts_with = "body_file")]
body: Option<String>,
/// Read body from a file. `-` means stdin.
#[arg(long = "body-file")]
body_file: Option<String>,
/// Open as draft.
#[arg(long)]
draft: bool,
/// Repo override.
repo: Option<String>,
}
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(args.repo.as_deref());
let payload = json!({
"title": args.title,
"head": args.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) {
println!("{url}");
}
Ok(())
}