Browse Source

Only update labels if a label command was noted

Mark Rousskov 6 năm trước cách đây
mục cha
commit
e56cafe42e
1 tập tin đã thay đổi với 7 bổ sung1 xóa
  1. 7 1
      src/handlers/label.rs

+ 7 - 1
src/handlers/label.rs

@@ -36,11 +36,13 @@ impl Handler for LabelHandler {
 
 
         let mut issue_labels = event.issue.labels().to_owned();
         let mut issue_labels = event.issue.labels().to_owned();
 
 
+        let mut changed = false;
         for label_block in LABEL_RE.find_iter(&event.comment.body) {
         for label_block in LABEL_RE.find_iter(&event.comment.body) {
             let label_block = &label_block.as_str()["label: ".len()..]; // guaranteed to start with this
             let label_block = &label_block.as_str()["label: ".len()..]; // guaranteed to start with this
             for label in label_block.split_whitespace() {
             for label in label_block.split_whitespace() {
                 if label.starts_with('-') {
                 if label.starts_with('-') {
                     if let Some(label) = issue_labels.iter().position(|el| el.name == &label[1..]) {
                     if let Some(label) = issue_labels.iter().position(|el| el.name == &label[1..]) {
+                        changed = true;
                         issue_labels.remove(label);
                         issue_labels.remove(label);
                     } else {
                     } else {
                         // do nothing, if the user attempts to remove a label that's not currently
                         // do nothing, if the user attempts to remove a label that's not currently
@@ -48,11 +50,13 @@ impl Handler for LabelHandler {
                     }
                     }
                 } else if label.starts_with('+') {
                 } else if label.starts_with('+') {
                     // add this label, but without the +
                     // add this label, but without the +
+                    changed = true;
                     issue_labels.push(Label {
                     issue_labels.push(Label {
                         name: label[1..].to_string(),
                         name: label[1..].to_string(),
                     });
                     });
                 } else {
                 } else {
                     // add this label (literally)
                     // add this label (literally)
+                    changed = true;
                     issue_labels.push(Label {
                     issue_labels.push(Label {
                         name: label.to_string(),
                         name: label.to_string(),
                     });
                     });
@@ -60,7 +64,9 @@ impl Handler for LabelHandler {
             }
             }
         }
         }
 
 
-        event.issue.set_labels(&self.client, issue_labels)?;
+        if changed {
+            event.issue.set_labels(&self.client, issue_labels)?;
+        }
 
 
         Ok(())
         Ok(())
     }
     }