diff --git a/src-tauri/src/commands/commit_metrics.rs b/src-tauri/src/commands/commit_metrics.rs index cc16689..57e59c5 100644 --- a/src-tauri/src/commands/commit_metrics.rs +++ b/src-tauri/src/commands/commit_metrics.rs @@ -365,11 +365,21 @@ pub fn get_all_commit_health() -> Result, String> { let conn = crate::db::pool().get().map_err(|e| e.to_string())?; let round3 = |v: f64| (v * 1000.0).round() / 1000.0; - // 聚合各 project_id 的指标,并通过两条路径解析名称 + // 聚合各 project_id 的指标,四条路径解析名称: + // 1) projects 直接匹配(名称字符串 id) + // 2) blueprint_buffs + projects 路径关联 + // 3) project_profiles "prof-UUID" 格式(孤儿 UUID 的名称来源) + // 4) blueprint_buffs.project_path(后处理提取末段目录名) let mut stmt = conn.prepare( "SELECT cm.project_id, - COALESCE(p_direct.name, p_via_buff.name, bb.project_path, cm.project_id) AS name, + COALESCE( + p_direct.name, + p_via_buff.name, + pp_prof.name, + bb.project_path, + cm.project_id + ) AS name, COUNT(*) AS total, SUM(CASE WHEN cm.commit_type IS NOT NULL THEN 1 ELSE 0 END) AS conventional, SUM(CASE WHEN cm.is_rework=1 AND cm.is_ci_auto=0 THEN 1 ELSE 0 END) AS rework @@ -379,6 +389,7 @@ pub fn get_all_commit_health() -> Result, String> { LEFT JOIN projects p_via_buff ON p_via_buff.win_path = bb.project_path OR p_via_buff.wsl_path = bb.project_path + LEFT JOIN project_profiles pp_prof ON pp_prof.id = ('prof-' || cm.project_id) GROUP BY cm.project_id ORDER BY total DESC", ).map_err(|e| e.to_string())?; @@ -422,11 +433,20 @@ pub fn get_all_commit_health() -> Result, String> { .filter_map(|r| r.ok()) .collect(); + // 如果 name 解析为路径(含 / 或 \),取末段目录名 + let display_name = if name.contains('/') || name.contains('\\') { + name.split(['/', '\\']).filter(|s| !s.is_empty()).last() + .unwrap_or(&name) + .to_string() + } else { + name + }; + result.push(CommitHealthWithName { conventional_rate: round3(if total > 0 { conventional as f64 / total as f64 } else { 0.0 }), rework_rate: round3(if conventional > 0 { rework as f64 / conventional as f64 } else { 0.0 }), project_id: pid, - project_name: name, + project_name: display_name, total_commits: total, conventional_commits: conventional, rework_commits: rework,