use crate::hotspot::{format_age, HeatMap, BULK_COMMIT_FILES, TOP_N};
use crate::render::pipeline::IrFile;
pub fn commits_label(commits: u32) -> String {
if commits == 1 {
"1 commit".to_string()
} else {
format!("{} commits", commits)
}
}
pub fn render_hot_spots(ranked: &[&IrFile], heat: &HeatMap, now: i64) -> String {
let mut out = format!("**Hot spots** (commits in the last {}", heat.span.label);
if heat.skipped_bulk > 0 {
out.push_str(&format!(
"; skipped {} bulk commit{} of over {} files",
heat.skipped_bulk,
if heat.skipped_bulk == 1 { "" } else { "s" },
BULK_COMMIT_FILES
));
}
out.push_str("):");
if ranked.is_empty() {
out.push_str(" none\n");
return out;
}
out.push('\n');
for (i, file) in ranked.iter().take(TOP_N).enumerate() {
let h = file.heat.unwrap_or_default();
out.push_str(&format!(
"{}. {}: {}, +{}/-{}, {}\n",
i + 1,
file.display_path.display(),
commits_label(h.commits),
h.added,
h.deleted,
format_age(h.last_commit, now)
));
}
out
}