cargo-governor 2.0.0

Machine-First, LLM-Ready, CI/CD-Native release automation tool for Rust crates
Documentation
//! Commit analysis for simulation service

use governor_core::domain::commit::{Commit, CommitType};
use serde_json::json;

/// Analyze commits and categorize by type
pub fn analyze_commits(
    commits: &[Commit],
) -> (
    Vec<serde_json::Value>,
    Vec<serde_json::Value>,
    Vec<serde_json::Value>,
    usize,
) {
    let mut breaking = Vec::new();
    let mut features = Vec::new();
    let mut fixes = Vec::new();
    let mut other = 0;

    for commit in commits {
        let short_hash = commit.hash.chars().take(7).collect::<String>();

        match commit.commit_type {
            Some(CommitType::Feat) => {
                if commit.breaking {
                    breaking.push(json!({
                        "commit_hash": commit.hash,
                        "short_hash": short_hash,
                        "message": commit.short_message(),
                        "description": "Breaking feature change",
                    }));
                } else {
                    features.push(json!({
                        "commit_hash": commit.hash,
                        "short_hash": short_hash,
                        "message": commit.short_message(),
                        "scope": commit.scope,
                    }));
                }
            }
            Some(CommitType::Fix) => {
                if commit.breaking {
                    breaking.push(json!({
                        "commit_hash": commit.hash,
                        "short_hash": short_hash,
                        "message": commit.short_message(),
                        "description": "Breaking fix",
                    }));
                } else {
                    fixes.push(json!({
                        "commit_hash": commit.hash,
                        "short_hash": short_hash,
                        "message": commit.short_message(),
                        "scope": commit.scope,
                    }));
                }
            }
            Some(CommitType::Perf | CommitType::Refactor) => {
                if commit.breaking {
                    breaking.push(json!({
                        "commit_hash": commit.hash,
                        "short_hash": short_hash,
                        "message": commit.short_message(),
                        "description": "Breaking refactor/perf change",
                    }));
                }
            }
            _ => {
                other += 1;
            }
        }
    }

    (breaking, features, fixes, other)
}