use std::path::Path;
use gitcortex_core::schema::{NodeKind, Visibility};
pub(crate) fn sig_line(n: &gitcortex_core::graph::Node) -> String {
const MAX: usize = 120;
let first = n
.metadata
.definition
.signature
.lines()
.next()
.unwrap_or("")
.trim();
if first.chars().count() > MAX {
let truncated: String = first.chars().take(MAX).collect();
format!("{truncated}…")
} else {
first.to_owned()
}
}
pub(crate) fn parse_node_kind(s: &str) -> Option<NodeKind> {
s.parse().ok()
}
pub(crate) fn parse_visibility(s: &str) -> Option<Visibility> {
s.parse().ok()
}
pub(crate) fn detect_current_branch(repo_root: &Path) -> Option<String> {
let out = std::process::Command::new("git")
.args(["symbolic-ref", "--short", "HEAD"])
.current_dir(repo_root)
.output()
.ok()?;
if out.status.success() {
let s = String::from_utf8(out.stdout).ok()?;
let b = s.trim().to_owned();
if b.is_empty() {
None
} else {
Some(b)
}
} else {
None
}
}