Browse Source

Use prioritize_on field to start prioritization process

Santiago Pastorino 5 years ago
parent
commit
939f8b04a4
2 changed files with 18 additions and 0 deletions
  1. 4 0
      src/config.rs
  2. 14 0
      src/handlers/prioritize.rs

+ 4 - 0
src/config.rs

@@ -78,6 +78,10 @@ pub(crate) struct RelabelConfig {
 #[derive(PartialEq, Eq, Debug, serde::Deserialize)]
 pub(crate) struct PrioritizeConfig {
     pub(crate) label: String,
+    #[serde(default)]
+    pub(crate) prioritize_on: Vec<String>,
+    #[serde(default)]
+    pub(crate) priority_labels: String,
     pub(crate) zulip_stream: u64,
 }
 

+ 14 - 0
src/handlers/prioritize.rs

@@ -38,6 +38,20 @@ impl Handler for PrioritizeHandler {
                     if e.label.as_ref().expect("label").name == config.label {
                         // We need to take the exact same action in this case.
                         return Ok(Some(Prioritize::Start));
+                    } else {
+                        match glob::Pattern::new(&config.priority_labels) {
+                            Ok(glob) => {
+                                let issue_labels = event.issue().unwrap().labels();
+                                let label_name = &e.label.as_ref().expect("label").name;
+
+                                if issue_labels.iter().all(|l| !glob.matches(&l.name))
+                                    && config.prioritize_on.iter().any(|l| l == label_name)
+                                {
+                                    return Ok(Some(Prioritize::Label));
+                                }
+                            }
+                            Err(error) => log::error!("Invalid glob pattern: {}", error),
+                        }
                     }
                 }
             }