Refactor title-based labelling

This will make it easier to add new topic labels.
This commit is contained in:
Alyssa Ross 2021-08-02 09:25:48 +00:00 committed by Cole Helbling
parent c158642647
commit 01a69183ef

View file

@ -26,6 +26,11 @@ use uuid::Uuid;
static MAINTAINER_REVIEW_MAX_CHANGED_PATHS: usize = 64; static MAINTAINER_REVIEW_MAX_CHANGED_PATHS: usize = 64;
const TITLE_LABELS: [(&str, &str); 2] = [
("darwin", "6.topic: darwin"),
("macos", "6.topic: darwin"),
];
pub struct NixpkgsStrategy<'a> { pub struct NixpkgsStrategy<'a> {
job: &'a EvaluationJob, job: &'a EvaluationJob,
pull: &'a hubcaps::pulls::PullRequest<'a>, pull: &'a hubcaps::pulls::PullRequest<'a>,
@ -67,18 +72,22 @@ impl<'a> NixpkgsStrategy<'a> {
} }
fn tag_from_title(&self) { fn tag_from_title(&self) {
let darwin = self let title = match self.issue_ref.get() {
.issue_ref Ok(issue) => issue.title.to_lowercase(),
.get() Err(_) => return,
.map(|iss| { };
iss.title.to_lowercase().contains("darwin")
|| iss.title.to_lowercase().contains("macos")
})
.unwrap_or(false);
if darwin { let labels: Vec<_> = TITLE_LABELS
update_labels(&self.issue_ref, &[String::from("6.topic: darwin")], &[]); .iter()
.filter(|(word, _label)| title.contains(word))
.map(|(_word, label)| (*label).into())
.collect();
if labels.is_empty() {
return;
} }
update_labels(&self.issue_ref, &labels, &[]);
} }
fn check_stdenvs_before(&mut self, dir: &Path) { fn check_stdenvs_before(&mut self, dir: &Path) {