use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use super::repository::ScanTrigger; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "lowercase")] pub enum ScanType { Sast, Sbom, Cve, Gdpr, OAuth, Graph, Dast, SecretDetection, Lint, CodeReview, } impl std::fmt::Display for ScanType { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Sast => write!(f, "sast"), Self::Sbom => write!(f, "sbom"), Self::Cve => write!(f, "cve"), Self::Gdpr => write!(f, "gdpr"), Self::OAuth => write!(f, "oauth"), Self::Graph => write!(f, "graph"), Self::Dast => write!(f, "dast"), Self::SecretDetection => write!(f, "secret_detection"), Self::Lint => write!(f, "lint"), Self::CodeReview => write!(f, "code_review"), } } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum ScanRunStatus { Running, Completed, Failed, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum ScanPhase { ChangeDetection, Sast, SbomGeneration, CveScanning, PatternScanning, SecretDetection, LintScanning, CodeReview, GraphBuilding, LlmTriage, IssueCreation, DastScanning, Completed, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ScanRun { #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] pub id: Option, pub repo_id: String, pub trigger: ScanTrigger, pub commit_sha: Option, pub status: ScanRunStatus, pub current_phase: ScanPhase, pub phases_completed: Vec, pub new_findings_count: u32, pub error_message: Option, #[serde(with = "super::serde_helpers::bson_datetime")] pub started_at: DateTime, #[serde(default, with = "super::serde_helpers::opt_bson_datetime")] pub completed_at: Option>, } impl ScanRun { pub fn new(repo_id: String, trigger: ScanTrigger) -> Self { Self { id: None, repo_id, trigger, commit_sha: None, status: ScanRunStatus::Running, current_phase: ScanPhase::ChangeDetection, phases_completed: Vec::new(), new_findings_count: 0, error_message: None, started_at: Utc::now(), completed_at: None, } } }