#![cfg_attr(coverage_nightly, coverage(off))]
use serde::{Deserialize, Serialize};
use std::path::Path;
use std::process::Command;
use std::time::Duration;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GateResult {
pub name: String,
pub passed: bool,
#[serde(with = "serde_millis")]
pub duration: Duration,
pub message: String,
}
mod serde_millis {
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::time::Duration;
pub(super) fn serialize<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
duration.as_millis().serialize(serializer)
}
pub(super) fn deserialize<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where
D: Deserializer<'de>,
{
let millis = u64::deserialize(deserializer)?;
Ok(Duration::from_millis(millis))
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct QualityReport {
pub gates: Vec<GateResult>,
pub passed: bool,
#[serde(with = "serde_millis")]
pub total_duration: Duration,
pub timestamp: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct GateConfig {
pub run_clippy: bool,
pub clippy_strict: bool,
pub run_tests: bool,
pub test_timeout: u64,
pub check_coverage: bool,
pub min_coverage: f64,
pub check_complexity: bool,
pub max_complexity: u32,
}
impl Default for GateConfig {
fn default() -> Self {
Self {
run_clippy: true,
clippy_strict: true,
run_tests: true,
test_timeout: 300,
check_coverage: true,
min_coverage: 80.0,
check_complexity: true,
max_complexity: 10,
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum GateError {
#[error("Command execution failed: {0}")]
CommandFailed(String),
#[error("Timeout exceeded: {0}s")]
Timeout(u64),
#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),
}
pub type Result<T> = std::result::Result<T, GateError>;
include!("gates_checks.rs");
include!("gates_runner.rs");
include!("gates_tests.rs");