use std::io;
use std::path::{Path, PathBuf};
use crate::adopt::plan::{AdoptionPlan, DetectedGate, HookStage, TriggerKind};
pub fn detect_all(repo_root: &Path) -> io::Result<AdoptionPlan> {
let mut findings: Vec<DetectedGate> = Vec::new();
findings.extend(super::detect_pre_commit::detect(repo_root)?);
findings.extend(super::detect_husky::detect(repo_root)?);
findings.extend(super::detect_lefthook::detect(repo_root)?);
findings.extend(super::detect_plain_hooks::detect(repo_root)?);
findings.extend(super::detect_lint_staged::detect(repo_root)?);
Ok(AdoptionPlan { findings })
}
pub(super) fn first_existing_file(root: &Path, candidates: &[&str]) -> Option<PathBuf> {
candidates
.iter()
.map(|name| root.join(name))
.find(|p| p.is_file())
}
pub(super) fn hook_to_trigger(hook: HookStage) -> TriggerKind {
match hook {
HookStage::PreCommit => TriggerKind::Commit,
HookStage::PrePush => TriggerKind::Push,
}
}