(&self, chain_name: &str, draft: bool)
| 372 | Ok(()) |
| 373 | } |
| 374 | pub fn pr(&self, chain_name: &str, draft: bool) -> Result<(), Error> { |
| 375 | check_gh_cli_installed()?; |
| 376 | if Chain::chain_exists(self, chain_name)? { |
| 377 | let chain = Chain::get_chain(self, chain_name)?; |
| 378 | |
| 379 | for (i, branch) in chain.branches.iter().enumerate() { |
| 380 | let base_branch = if i == 0 { |
| 381 | &chain.root_branch |
| 382 | } else { |
| 383 | &chain.branches[i - 1].branch_name |
| 384 | }; |
| 385 | |
| 386 | // Check for existing open PRs for the branch |
| 387 | let output = Command::new("gh") |
| 388 | .arg("pr") |
| 389 | .arg("list") |
| 390 | .arg("--head") |
| 391 | .arg(&branch.branch_name) |
| 392 | .arg("--json") |
| 393 | .arg("url") |
| 394 | .output(); |
| 395 | |
| 396 | match output { |
| 397 | Ok(output) if output.status.success() => { |
| 398 | let stdout = String::from_utf8_lossy(&output.stdout); |
| 399 | let pr_objects: Vec<serde_json::Value> = |
| 400 | serde_json::from_str(&stdout).unwrap_or_default(); |
| 401 | if !pr_objects.is_empty() { |
| 402 | if let Some(pr_url) = pr_objects |
| 403 | .first() |
| 404 | .and_then(|pr| pr.get("url")) |
| 405 | .and_then(|url| url.as_str()) |
| 406 | { |
| 407 | println!( |
| 408 | "🔗 Open PR already exists for branch {}: {}", |
| 409 | branch.branch_name.bold(), |
| 410 | pr_url |
| 411 | ); |
| 412 | } else { |
| 413 | println!( |
| 414 | "🔗 Open PR already exists for branch {}", |
| 415 | branch.branch_name.bold() |
| 416 | ); |
| 417 | } |
| 418 | continue; |
| 419 | } |
| 420 | } |
| 421 | _ => { |
| 422 | eprintln!( |
| 423 | " Failed to check existing PRs for branch {}.", |
| 424 | branch.branch_name.bold() |
| 425 | ); |
| 426 | continue; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | // 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 |
| 431 | let push_output = Command::new("git") |
no test coverage detected