Watch
0
0
Fork
You've already forked hyperhive
0

hive-forge: subscription --ignore errors instead of subscribing; warn on --draft; always print agit PR URL

This commit is contained in:
atlas 2026-10-09 11:43:21 +02:00 • committed by mara
commit 6e32b432ec

View file

@ -50,7 +50,8 @@ pub struct Args {
/// Read body from a file. `-` means stdin.
#[arg(long = "body-file")]
body_file: Option<String>,
/// Open as draft. Ignored in `--agit` mode.
/// Not supported by this forge (no draft field): warns on stderr and
/// opens a normal PR.
#[arg(long)]
draft: bool,
/// Push the local `--head` branch to `--remote` before creating the PR.
@ -88,6 +89,9 @@ pub struct Args {
/// token missing/invalid), an unresolved `--label` name, and any I/O
/// error from writing the PR URL to stdout.
pub fn run(client: &Client, args: Args) -> Result<()> {
if args.draft {
eprintln!("{DRAFT_WARNING}");
}
let body = body::resolve(args.body.as_deref(), args.body_file.as_deref())?.unwrap_or_default();
if args.agit {
return agit_create(client, &args, &body);
@ -109,10 +113,9 @@ pub fn run(client: &Client, args: Args) -> Result<()> {
let all = labels::repo_labels(client)?;
Some(labels::resolve_ids(&all, &args.labels)?)
};
// Note: Forgejo's CreatePullRequestOption has no `draft` /
// 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.
// swagger).
let payload = CreatePullRequestOption {
assignee: None,
assignees: None,
@ -201,6 +204,9 @@ fn agit_create(client: &Client, args: &Args, body: &str) -> Result<()> {
);
return Ok(());
};
// The PR exists once the push succeeds; print the URL before any
// follow-up so a failing step cannot hide it and prompt a duplicate.
println!("{url}");
if deferred_body {
if let Some(number) = pr_number_from_url(&url) {
let (owner, name) = client.owner_repo()?;
@ -231,7 +237,6 @@ fn agit_create(client: &Client, args: &Args, body: &str) -> Result<()> {
if !args.labels.is_empty() {
apply_agit_labels(client, &args.labels, &url)?;
}
println!("{url}");
Ok(())
}
@ -380,6 +385,8 @@ fn remote_content(line: &str) -> Option<&str> {
.map(str::trim_start)
}
const DRAFT_WARNING: &str = "warning: --draft is not supported by this forge; opening a normal PR";
fn is_remote_line(line: &str) -> bool {
remote_content(line).is_some()
}
@ -395,6 +402,18 @@ fn is_pr_hint_opener(line: &str) -> bool {
mod tests {
use super::*;
#[test]
fn draft_flag_parses() {
#[derive(clap::Parser)]
struct Cli {
#[command(flatten)]
args: Args,
}
use clap::Parser;
let cli = Cli::parse_from(["x", "--title", "t", "--head", "h", "--draft"]);
assert!(cli.args.draft);
}
#[test]
fn agit_parse_pr_url_picks_pulls_link() {
let stderr = "\