Skip to main content

batuta/pipeline/stages/
analysis.rs

1//! Analysis stage - detects languages and dependencies.
2
3use anyhow::Result;
4
5#[cfg(feature = "native")]
6use tracing::info;
7
8// Stub macros for WASM build
9#[cfg(not(feature = "native"))]
10macro_rules! info {
11    ($($arg:tt)*) => {{}};
12}
13
14use crate::pipeline::types::{PipelineContext, PipelineStage, ValidationResult};
15
16/// Analysis stage - detects languages and dependencies
17pub struct AnalysisStage;
18
19#[async_trait::async_trait]
20impl PipelineStage for AnalysisStage {
21    fn name(&self) -> &'static str {
22        "Analysis"
23    }
24
25    async fn execute(&self, mut ctx: PipelineContext) -> Result<PipelineContext> {
26        info!("Analyzing project at {:?}", ctx.input_path);
27
28        let analysis = crate::analyzer::analyze_project(
29            &ctx.input_path,
30            false, // TDG - skip for pipeline
31            true,  // languages
32            true,  // dependencies
33        )?;
34
35        ctx.primary_language = analysis.primary_language;
36        ctx.metadata.insert("total_files".to_string(), serde_json::json!(analysis.total_files));
37        ctx.metadata.insert("total_lines".to_string(), serde_json::json!(analysis.total_lines));
38
39        Ok(ctx)
40    }
41
42    fn validate(&self, ctx: &PipelineContext) -> Result<ValidationResult> {
43        let passed = ctx.primary_language.is_some();
44        Ok(ValidationResult {
45            stage: self.name().to_string(),
46            passed,
47            message: if passed {
48                format!("Language detected: {:?}", ctx.primary_language)
49            } else {
50                "Could not detect primary language".to_string()
51            },
52            details: None,
53        })
54    }
55}