use crate::contracts::CiGateConfig;
use anyhow::{Result, bail};
use std::path::Path;
use std::process::Output;
use super::shell::{SafeCommand, execute_safe_command};
pub fn ci_gate_to_safe_command(ci_gate: &CiGateConfig) -> Result<SafeCommand> {
if let Some(argv) = &ci_gate.argv {
if argv.is_empty() {
bail!("CI gate argv must contain at least one element");
}
if argv.iter().any(|arg| arg.trim().is_empty()) {
bail!("CI gate argv entries must be non-empty");
}
return Ok(SafeCommand::Argv { argv: argv.clone() });
}
bail!("CI gate is enabled but no argv is configured");
}
pub fn execute_ci_gate(ci_gate: &CiGateConfig, cwd: &Path) -> Result<Output> {
let command = ci_gate_to_safe_command(ci_gate)?;
execute_safe_command(&command, cwd)
}