pmat 3.11.0

PMAT - Zero-config AI context generation and code quality toolkit (CLI, MCP, HTTP)
/// Generate pre-commit hook script for project type
///
/// # Complexity
/// - Time: O(1)
/// - Cyclomatic: 3
pub fn generate_pre_commit_hook(config: &HookConfig) -> Result<String> {
    let script = match &config.project_type {
        TemplateType::Agent { .. } => generate_pforge_hook(config),
        TemplateType::Wasm { .. } => generate_wasm_hook(config),
        _ => return Err(ScaffoldError::UnsupportedProjectType),
    };

    Ok(script)
}

/// Generate pforge-specific pre-commit hook
///
/// # Quality Gates
/// - cargo clippy -- -D warnings
/// - cargo test
/// - Complexity check (if enabled)
///
/// # Complexity
/// - Time: O(1)
/// - Cyclomatic: 1
fn generate_pforge_hook(_config: &HookConfig) -> String {
    r#"#!/bin/bash
# Pre-commit hook for pforge project
# Generated by PMAT ScaffoldEngine

set -e

echo "Running pre-commit quality gates..."

# Clippy (strict mode)
echo "→ Running clippy..."
cargo clippy --all-targets --all-features -- -D warnings

# Tests
echo "→ Running tests..."
cargo test

echo "✓ All quality gates passed!"
exit 0
"#
    .to_string()
}

/// Generate WASM-specific pre-commit hook
///
/// # Quality Gates
/// - cargo clippy -- -D warnings
/// - cargo test
/// - WASM build verification
/// - Complexity check (if enabled)
///
/// # Complexity
/// - Time: O(1)
/// - Cyclomatic: 1
fn generate_wasm_hook(_config: &HookConfig) -> String {
    r#"#!/bin/bash
# Pre-commit hook for WASM project
# Generated by PMAT ScaffoldEngine

set -e

echo "Running pre-commit quality gates..."

# Clippy (strict mode)
echo "→ Running clippy..."
cargo clippy --all-targets --all-features -- -D warnings

# Tests
echo "→ Running tests..."
cargo test

# WASM build verification
echo "→ Verifying WASM build..."
cargo build --target wasm32-unknown-unknown --release

echo "✓ All quality gates passed!"
exit 0
"#
    .to_string()
}

/// Generate post-commit hook script
///
/// # TICKET-PMAT-5013
///
/// # Complexity
/// - Time: O(1)
/// - Cyclomatic: 1
pub fn generate_post_commit_hook() -> String {
    r#"#!/bin/bash
# Post-commit hook for roadmap updates
# Generated by PMAT Maintenance Engine

# Only run if this is a ticket commit
if ! git log -1 --pretty=%B | grep -q "TICKET-PMAT-"; then
    exit 0
fi

# Run roadmap updater
if command -v pmat &> /dev/null; then
    pmat maintain update-roadmap --from-commit HEAD 2>/dev/null || true
fi

exit 0
"#
    .to_string()
}