diff --git a/Cargo.lock b/Cargo.lock index 2670f9c..557ece1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "amq-protocol" version = "6.0.3" @@ -927,6 +936,7 @@ dependencies = [ "lru-cache", "md5", "nom 4.2.3", + "regex", "separator", "serde", "serde_derive", @@ -1218,6 +1228,8 @@ version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] diff --git a/ofborg/Cargo.toml b/ofborg/Cargo.toml index cc0fdcb..64e402e 100644 --- a/ofborg/Cargo.toml +++ b/ofborg/Cargo.toml @@ -19,6 +19,7 @@ lapin = "1.0.0" lru-cache = "0.1.1" md5 = "0.3.5" nom = "4.0.0-beta3" +regex = "1.5.4" separator = "0.4.1" serde = "1.0" serde_derive = "1.0" diff --git a/ofborg/src/tasks/eval/nixpkgs.rs b/ofborg/src/tasks/eval/nixpkgs.rs index 8a7567d..3ef61e8 100644 --- a/ofborg/src/tasks/eval/nixpkgs.rs +++ b/ofborg/src/tasks/eval/nixpkgs.rs @@ -21,6 +21,7 @@ use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; use hubcaps::gists::Gists; use hubcaps::issues::{Issue, IssueRef}; use hubcaps::repositories::Repository; +use regex::Regex; use tracing::{info, warn}; use uuid::Uuid; @@ -32,6 +33,19 @@ const TITLE_LABELS: [(&str, &str); 3] = [ ("macos", "6.topic: darwin"), ]; +fn label_from_title(title: &str) -> Vec { + let labels: Vec<_> = TITLE_LABELS + .iter() + .filter(|(word, _label)| { + let re = Regex::new(&format!("\\b{}\\b", word)).unwrap(); + re.is_match(&title) + }) + .map(|(_word, label)| (*label).into()) + .collect(); + + labels +} + pub struct NixpkgsStrategy<'a> { job: &'a EvaluationJob, pull: &'a hubcaps::pulls::PullRequest<'a>, @@ -78,11 +92,7 @@ impl<'a> NixpkgsStrategy<'a> { Err(_) => return, }; - let labels: Vec<_> = TITLE_LABELS - .iter() - .filter(|(word, _label)| title.contains(word)) - .map(|(_word, label)| (*label).into()) - .collect(); + let labels = label_from_title(&title); if labels.is_empty() { return; @@ -662,4 +672,32 @@ mod tests { expect ); } + + #[test] + fn test_label_platform_from_title() { + assert_eq!( + label_from_title("libsdl: 1.0.0 -> 1.1.0"), + Vec::::new() + ); + assert_eq!( + label_from_title("fix build on bsd"), + vec![String::from("6.topic: bsd")] + ); + assert_eq!( + label_from_title("fix build on darwin"), + vec![String::from("6.topic: darwin")] + ); + assert_eq!( + label_from_title("fix build on macos"), + vec![String::from("6.topic: darwin")] + ); + assert_eq!( + label_from_title("fix build on bsd and darwin").sort(), + vec![ + String::from("6.topic: darwin"), + String::from("6.topic: bsd") + ] + .sort() + ); + } }