use serde_json::Value;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
pub fn workspace_root() -> PathBuf {
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
manifest_dir
.parent()
.unwrap()
.parent()
.unwrap()
.to_path_buf()
}
pub fn get_rivets_binary() -> PathBuf {
let workspace = workspace_root();
let status = Command::new("cargo")
.args(["build", "--package", "rivets", "--quiet"])
.current_dir(&workspace)
.status()
.expect("Failed to build rivets");
assert!(status.success(), "Failed to build rivets binary");
workspace.join("target/debug/rivets")
}
pub fn run_rivets_in_dir(dir: &Path, args: &[&str]) -> Output {
let binary = get_rivets_binary();
Command::new(&binary)
.args(args)
.current_dir(dir)
.output()
.expect("Failed to execute rivets binary")
}
#[allow(dead_code)] pub fn create_issue(dir: &Path, title: &str, extra_args: &[&str]) -> String {
let mut args = vec!["--json", "create", "--title", title];
args.extend(extra_args);
let output = run_rivets_in_dir(dir, &args);
assert!(
output.status.success(),
"Failed to create issue: {}",
String::from_utf8_lossy(&output.stderr)
);
let stdout = String::from_utf8_lossy(&output.stdout);
let json: Value = serde_json::from_str(&stdout).expect("Failed to parse JSON output");
json["id"]
.as_str()
.expect("Issue ID not found in output")
.to_string()
}