Skip to content

Commit 893c9d9

Browse files
committed
fix --web and --draft interop issue for github cli
1 parent fcaad2f commit 893c9d9

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

src/main.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2318,10 +2318,14 @@ impl GitChain {
23182318
println!("Pushed branch {}, creating PR...", branch.branch_name.bold());
23192319

23202320
let mut gh_command = Command::new("gh");
2321-
gh_command.arg("pr").arg("create").arg("--base").arg(base_branch).arg("--head").arg(&branch.branch_name).arg("--web");
2321+
gh_command.arg("pr").arg("create").arg("--base").arg(base_branch).arg("--head").arg(&branch.branch_name);
23222322

2323+
// For draft PRs, we can't use --web flag due to GitHub CLI limitation
2324+
// Instead, we'll create the draft PR and then open it separately
23232325
if draft {
23242326
gh_command.arg("--draft");
2327+
} else {
2328+
gh_command.arg("--web");
23252329
}
23262330

23272331
let output = gh_command.output().unwrap_or_else(|_| {
@@ -2333,6 +2337,26 @@ impl GitChain {
23332337

23342338
if output.status.success() {
23352339
println!("✅ Created PR for {} -> {}", branch.branch_name.bold(), base_branch.bold());
2340+
2341+
// If draft mode, open the PR in browser separately
2342+
if draft {
2343+
let pr_url = String::from_utf8_lossy(&output.stdout).trim().to_string();
2344+
if let Some(pr_number) = pr_url.split('/').last() {
2345+
let browse_output = Command::new("gh")
2346+
.arg("browse")
2347+
.arg(pr_number)
2348+
.output();
2349+
2350+
match browse_output {
2351+
Ok(browse_result) if browse_result.status.success() => {
2352+
println!("🌐 Opened draft PR in browser");
2353+
}
2354+
_ => {
2355+
println!("ℹ️ Draft PR created: {}", pr_url);
2356+
}
2357+
}
2358+
}
2359+
}
23362360
} else {
23372361
io::stdout().write_all(&output.stdout).unwrap();
23382362
io::stderr().write_all(&output.stderr).unwrap();

tests/pr.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,20 @@ if [ "$1" = "pr" ] && [ "$2" = "create" ]; then
8484
if [ "$3" = "--base" ] && [ "$5" = "--head" ] && [ "$7" = "--draft" ]; then
8585
base="$4"
8686
head="$6"
87-
echo "Creating draft pull request for $head into $base in test/repo"
88-
echo ""
87+
# Draft PR creation outputs the URL to stdout
8988
echo "https://github.com/test/repo/pull/999"
9089
exit 0
9190
fi
9291
fi
9392
93+
if [ "$1" = "browse" ]; then
94+
# gh browse <PR_NUMBER> - simulate opening PR in browser
95+
if [ -n "$2" ]; then
96+
echo "Opening https://github.com/test/repo/pull/$2 in your browser."
97+
exit 0
98+
fi
99+
fi
100+
94101
# Default error response
95102
echo "Error: unknown gh command" >&2
96103
exit 1
@@ -306,14 +313,13 @@ fn test_pr_command_with_draft_flag() {
306313
println!("EXIT STATUS: {}", output.status);
307314
println!("======");
308315

309-
// git-chain continues running even when individual PR creations fail
310-
// but it should show the error from gh CLI and report failed PR creation
316+
// With the fix, draft PRs should now work successfully
311317
assert!(output.status.success(),
312-
"git-chain should complete successfully even when individual PRs fail");
313-
assert!(stderr.contains("the `--draft` flag is not supported with `--web`"),
314-
"Should show GitHub CLI error about incompatible flags, got: {}", stderr);
315-
assert!(stdout.contains("🛑 Failed to create PR for"),
316-
"Should show failed PR creation messages, got: {}", stdout);
318+
"Command should succeed with draft flag");
319+
assert!(stdout.contains("✅ Created PR for"),
320+
"Should show successful PR creation, got: {}", stdout);
321+
assert!(stdout.contains("🌐 Opened draft PR in browser") || stdout.contains("ℹ️ Draft PR created:"),
322+
"Should show browser opening or PR URL, got: {}", stdout);
317323

318324
teardown_git_repo(test_name);
319325
}
@@ -364,7 +370,7 @@ fn test_gh_cli_not_installed() {
364370
println!("EXIT STATUS: {}", output.status);
365371
println!("======");
366372

367-
// Assertions
373+
// Assertions - the command should fail when gh is not installed
368374
assert!(!output.status.success(), "Command should fail when gh is not installed");
369375
assert!(stderr.contains("GitHub CLI (gh) is not installed") ||
370376
stderr.contains("not found in the PATH"),

0 commit comments

Comments
 (0)