diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index f18e705..c8573c5 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -69,7 +69,12 @@ impl PipelineOrchestrator { } #[tracing::instrument(skip_all, fields(repo_id = repo.name.as_str()))] - async fn run_pipeline(&self, repo: &RepoView, scan_run_id: &str) -> Result { + async fn run_pipeline( + &self, + repo: &RepoView, + scan_run_id: &str, + trigger: &ScanTrigger, + ) -> Result { let repo_id = repo.id.as_ref().map(|id| id.to_hex()).unwrap_or_default(); // Stage 0: Change detection @@ -83,8 +88,22 @@ impl PipelineOrchestrator { ); let repo_path = git_ops.clone_or_fetch(&repo.git_url, &repo.name)?; - if !GitOps::has_new_commits(&repo_path, repo.last_scanned_commit.as_deref())? { + // A scheduled or webhook scan of an unchanged repository has nothing + // new to find; one a person started always runs (after an update of + // Prüfwerk itself, or a changed setting, it can find something else). + if *trigger != ScanTrigger::Manual + && !GitOps::has_new_commits(&repo_path, repo.last_scanned_commit.as_deref())? + { tracing::info!("[{repo_id}] No new commits, skipping scan"); + self.skip_stage( + scan_run_id, + SkippedStage::new( + "change_detection", + SkipCode::NoNewCommits, + "no new commits since the last scan", + ), + ) + .await; return Ok(0); } @@ -584,7 +603,7 @@ impl PipelineOrchestrator { .await? .ok_or_else(|| AgentError::Other(format!("Onboarded target {target_id} not found")))?; - let scan_run = ScanRun::new(target_id.to_string(), trigger); + let scan_run = ScanRun::new(target_id.to_string(), trigger.clone()); let insert = self.db.scan_runs().insert_one(&scan_run).await?; let scan_run_id = insert .inserted_id @@ -592,7 +611,9 @@ impl PipelineOrchestrator { .map(|id| id.to_hex()) .unwrap_or_default(); - let result = self.run_target_pipeline(&target, &scan_run_id).await; + let result = self + .run_target_pipeline(&target, &scan_run_id, &trigger) + .await; match &result { Ok(count) => { self.db @@ -655,6 +676,7 @@ impl PipelineOrchestrator { &self, target: &OnboardedTarget, scan_run_id: &str, + trigger: &ScanTrigger, ) -> Result { let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default(); let plan = build_scan_plan(target); @@ -737,7 +759,7 @@ impl PipelineOrchestrator { match target.code_artifact() { Some(code) if code.kind == ArtifactKind::GitRepo => { let repo = RepoView::from_target(target, code, &self.secrets); - let n = self.run_pipeline(&repo, scan_run_id).await?; + let n = self.run_pipeline(&repo, scan_run_id, trigger).await?; self.finalize_target(target, &repo, n).await?; new_count += n; self.dast_after_code_scan(&target_id, &plan, scan_run_id) diff --git a/compliance-core/src/models/scan.rs b/compliance-core/src/models/scan.rs index 532885c..37065dd 100644 --- a/compliance-core/src/models/scan.rs +++ b/compliance-core/src/models/scan.rs @@ -181,6 +181,9 @@ pub enum SkipCode { /// Some components were not matched against known vulnerabilities; /// `subject` names the lookup, and the components where known. CveLookupIncomplete, + /// A scheduled or webhook scan found no new commits since the last scan, + /// so nothing was scanned again. + NoNewCommits, } /// Why a scan run failed, stable for the dashboard to word. diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 60e3d2d..2128e00 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -383,6 +383,10 @@ pub mod scans { /// this dashboard does not know yet; it is then shown as it is. pub fn stage(id: &str) -> Option { let text = match id { + "change_detection" => Text { + de: "Änderungserkennung", + en: "Change detection", + }, "ingest" => Text { de: "Einlesen der Dateien", en: "Reading the upload", @@ -550,6 +554,16 @@ pub mod scans { ), (SkipCode::CveLookupIncomplete, Lang::De) => format!("Nicht abgeglichen: {subject}"), (SkipCode::CveLookupIncomplete, Lang::En) => format!("Not matched: {subject}"), + (SkipCode::NoNewCommits, Lang::De) => { + "Keine neuen Commits seit der letzten Prüfung, daher nicht erneut geprüft. \ + „Prüfung starten“ prüft trotzdem vollständig." + .into() + } + (SkipCode::NoNewCommits, Lang::En) => { + "No new commits since the last scan, so it was not scanned again. \ + \"Run scan\" always scans in full." + .into() + } } }