diff --git a/compliance-agent/src/pipeline/issue_creation.rs b/compliance-agent/src/pipeline/issue_creation.rs index 070a903..5bbcf1d 100644 --- a/compliance-agent/src/pipeline/issue_creation.rs +++ b/compliance-agent/src/pipeline/issue_creation.rs @@ -139,7 +139,7 @@ impl PipelineOrchestrator { // Check if an issue already exists by fingerprint first, then by title let mut found_existing = false; - for search_term in [&finding.fingerprint, &title] { + for search_term in issue_search_terms(finding, &title) { match tracker .find_existing_issue(owner, tracker_repo_name, search_term) .await @@ -320,6 +320,18 @@ pub(crate) fn build_tracker( } } +/// What to search the tracker for to find a finding's issue: its +/// fingerprint, then its title. A group (#464) only by fingerprint: it has +/// the title of its rule's single findings, whose issues are being closed as +/// grouped, and must get one of its own. +fn issue_search_terms<'a>(finding: &'a Finding, title: &'a str) -> Vec<&'a str> { + if finding.occurrences.is_empty() { + vec![finding.fingerprint.as_str(), title] + } else { + vec![finding.fingerprint.as_str()] + } +} + /// Format a finding into a markdown issue body for the tracker. pub(super) fn format_issue_body(finding: &Finding) -> String { let mut body = String::new(); @@ -475,6 +487,25 @@ mod tests { assert!(body.contains("- app/Main.java:80\n")); assert!(body.contains("8 places, listed above; the first is `app/Main.java:10`.")); assert!(body.contains(&format!("`{}`", findings[0].fingerprint))); + // Found by its fingerprint only: an issue of one of its places has + // the same title and is not the group's. + assert_eq!( + issue_search_terms(&findings[0], "[low] mobsfscan: Logging"), + [findings[0].fingerprint.as_str()] + ); + let single = Finding::new( + "r".into(), + "fp-single".into(), + "mobsfscan".into(), + ScanType::Sast, + "Logging".into(), + "The app logs.".into(), + Severity::Low, + ); + assert_eq!( + issue_search_terms(&single, "[low] mobsfscan: Logging"), + ["fp-single", "[low] mobsfscan: Logging"] + ); } #[test]