Skip to content

Commit 060adb3

Browse files
author
Andrew McKnight
committed
push branches before trying to create prs
1 parent f496b29 commit 060adb3

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/main.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,11 @@ impl GitChain {
22702270
let stdout = String::from_utf8_lossy(&output.stdout);
22712271
let pr_objects: Vec<serde_json::Value> = serde_json::from_str(&stdout).unwrap_or_default();
22722272
if !pr_objects.is_empty() {
2273-
println!("🔗 Open PR already exists for branch {}", branch.branch_name.bold());
2273+
if let Some(pr_url) = pr_objects.get(0).and_then(|pr| pr.get("url")).and_then(|url| url.as_str()) {
2274+
println!("🔗 Open PR already exists for branch {}: {}", branch.branch_name.bold(), pr_url);
2275+
} else {
2276+
println!("🔗 Open PR already exists for branch {}", branch.branch_name.bold());
2277+
}
22742278
continue;
22752279
}
22762280
}
@@ -2280,8 +2284,28 @@ impl GitChain {
22802284
}
22812285
}
22822286

2287+
// Ensure the branch is pushed before creating a PR, because gh pr create --web drops into an interactive shell that this script doesn't handle correctly
2288+
let push_output = Command::new("git")
2289+
.arg("push")
2290+
.arg("origin")
2291+
.arg(&branch.branch_name)
2292+
.output();
2293+
2294+
if let Err(e) = push_output {
2295+
eprintln!("Failed to push branch {}: {}", branch.branch_name.bold(), e);
2296+
continue;
2297+
} else {
2298+
let unwrapped_push_output = push_output.unwrap();
2299+
if !unwrapped_push_output.status.success() {
2300+
eprintln!("Failed to push branch {}: {}", branch.branch_name.bold(), String::from_utf8_lossy(&unwrapped_push_output.stderr));
2301+
continue;
2302+
}
2303+
}
2304+
2305+
println!("Pushed branch {}, creating PR...", branch.branch_name.bold());
2306+
22832307
let mut gh_command = Command::new("gh");
2284-
gh_command.arg("pr").arg("create").arg("--base").arg(base_branch).arg("--head").arg(&branch.branch_name);
2308+
gh_command.arg("pr").arg("create").arg("--base").arg(base_branch).arg("--head").arg(&branch.branch_name).arg("--web");
22852309

22862310
if draft {
22872311
gh_command.arg("--draft");

0 commit comments

Comments
 (0)