Watch
0
0
Fork
You've already forked hyperhive
0

hive-forge: pr create --draft: extract draft_warning so the warning decision is tested

This commit is contained in:
atlas 2026-10-09 12:05:35 +02:00 • committed by mara
commit 4e6c3b4a2f

View file

@ -89,8 +89,8 @@ pub struct Args {
/// token missing/invalid), an unresolved `--label` name, and any I/O /// token missing/invalid), an unresolved `--label` name, and any I/O
/// error from writing the PR URL to stdout. /// error from writing the PR URL to stdout.
pub fn run(client: &Client, args: Args) -> Result<()> { pub fn run(client: &Client, args: Args) -> Result<()> {
if args.draft { if let Some(w) = draft_warning(&args) {
eprintln!("{DRAFT_WARNING}"); eprintln!("{w}");
} }
let body = body::resolve(args.body.as_deref(), args.body_file.as_deref())?.unwrap_or_default(); let body = body::resolve(args.body.as_deref(), args.body_file.as_deref())?.unwrap_or_default();
if args.agit { if args.agit {
@ -387,6 +387,10 @@ fn remote_content(line: &str) -> Option<&str> {
const DRAFT_WARNING: &str = "warning: --draft is not supported by this forge; opening a normal PR"; const DRAFT_WARNING: &str = "warning: --draft is not supported by this forge; opening a normal PR";
fn draft_warning(args: &Args) -> Option<&'static str> {
args.draft.then_some(DRAFT_WARNING)
}
fn is_remote_line(line: &str) -> bool { fn is_remote_line(line: &str) -> bool {
remote_content(line).is_some() remote_content(line).is_some()
} }
@ -401,17 +405,24 @@ fn is_pr_hint_opener(line: &str) -> bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use clap::Parser;
#[test]
fn draft_flag_parses() {
#[derive(clap::Parser)] #[derive(clap::Parser)]
struct Cli { struct Cli {
#[command(flatten)] #[command(flatten)]
args: Args, args: Args,
} }
use clap::Parser;
#[test]
fn draft_flag_yields_warning() {
let cli = Cli::parse_from(["x", "--title", "t", "--head", "h", "--draft"]); let cli = Cli::parse_from(["x", "--title", "t", "--head", "h", "--draft"]);
assert!(cli.args.draft); assert_eq!(draft_warning(&cli.args), Some(DRAFT_WARNING));
}
#[test]
fn no_draft_flag_yields_no_warning() {
let cli = Cli::parse_from(["x", "--title", "t", "--head", "h"]);
assert_eq!(draft_warning(&cli.args), None);
} }
#[test] #[test]