tasks/eval: use regex to match labels on word boundary
This prevents a PR named "libsdl: xyz" being tagged as "6.topic: bsd". This is slightly more robust than simply checking if the strings "bsd" or "darwin" or "macos" are present in the title.
This commit is contained in:
parent
accd873d62
commit
008c9c5728
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -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",
|
||||
]
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<String> {
|
||||
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::<String>::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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue