瀏覽代碼

Implement command diffing for other commands

kellda 4 年之前
父節點
當前提交
6c30d9e5a3
共有 6 個文件被更改,包括 84 次插入37 次删除
  1. 11 1
      src/handlers/glacier.rs
  2. 12 14
      src/handlers/major_change.rs
  3. 13 3
      src/handlers/nominate.rs
  4. 16 15
      src/handlers/ping.rs
  5. 19 1
      src/handlers/prioritize.rs
  6. 13 3
      src/handlers/relabel.rs

+ 11 - 1
src/handlers/glacier.rs

@@ -32,7 +32,17 @@ impl Handler for GlacierHandler {
         };
 
         let mut input = Input::new(&body, &ctx.username);
-        match input.parse_command() {
+        let command = input.parse_command();
+        
+        if let Some(previous) = event.comment_from() {
+            let mut prev_input = Input::new(&previous, &ctx.username);
+            let prev_command = prev_input.parse_command();
+            if command == prev_command {
+                return Ok(None);
+            }
+        }
+        
+        match command {
             Command::Glacier(Ok(command)) => Ok(Some(command)),
             Command::Glacier(Err(err)) => {
                 return Err(format!(

+ 12 - 14
src/handlers/major_change.rs

@@ -63,15 +63,21 @@ impl Handler for MajorChangeHandler {
                 // All other issue events are ignored
                 return Ok(None);
             }
-            Event::IssueComment(e) => {
-                if e.action != github::IssueCommentAction::Created {
-                    return Ok(None);
-                }
-            }
+            Event::IssueComment(e) => {}
         }
 
         let mut input = Input::new(&body, &ctx.username);
-        match input.parse_command() {
+        let command = input.parse_command();
+        
+        if let Some(previous) = event.comment_from() {
+            let mut prev_input = Input::new(&previous, &ctx.username);
+            let prev_command = prev_input.parse_command();
+            if command == prev_command {
+                return Ok(None);
+            }
+        }
+        
+        match command {
             Command::Second(Ok(SecondCommand)) => Ok(Some(Invocation::Second)),
             _ => Ok(None),
         }
@@ -107,14 +113,6 @@ async fn handle_input(
                 return Ok(());
             }
 
-            if !issue.labels().iter().any(|l| l.name == "major-change") {
-                let cmnt = ErrorComment::new(
-                    &issue,
-                    "This is not a major change (it lacks the `major-change` label).",
-                );
-                cmnt.post(&ctx.github).await?;
-                return Ok(());
-            }
             let is_team_member =
                 if let Err(_) | Ok(false) = event.user().is_team_member(&ctx.github).await {
                     false

+ 13 - 3
src/handlers/nominate.rs

@@ -30,15 +30,25 @@ impl Handler for NominateHandler {
         };
 
         if let Event::Issue(e) = event {
-            if e.action != github::IssuesAction::Opened {
-                // skip events other than opening the issue to avoid retriggering commands in the
+            if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
+                // skip events other than opening or editing the issue to avoid retriggering commands in the
                 // issue body
                 return Ok(None);
             }
         }
 
         let mut input = Input::new(&body, &ctx.username);
-        match input.parse_command() {
+        let command = input.parse_command();
+        
+        if let Some(previous) = event.comment_from() {
+            let mut prev_input = Input::new(&previous, &ctx.username);
+            let prev_command = prev_input.parse_command();
+            if command == prev_command {
+                return Ok(None);
+            }
+        }
+        
+        match command {
             Command::Nominate(Ok(command)) => Ok(Some(command)),
             Command::Nominate(Err(err)) => {
                 return Err(format!(

+ 16 - 15
src/handlers/ping.rs

@@ -33,25 +33,26 @@ impl Handler for PingHandler {
             return Ok(None);
         };
 
-        match event {
-            Event::Issue(e) => {
-                if e.action != github::IssuesAction::Opened {
-                    // skip events other than opening the issue to avoid retriggering commands in the
-                    // issue body
-                    return Ok(None);
-                }
-            }
-            Event::IssueComment(e) => {
-                // Especially on ping commands, which ping tons of folks, this
-                // is quite noisy.
-                if e.action != github::IssueCommentAction::Created {
-                    return Ok(None);
-                }
+        if let Event::Issue(e) = event {
+            if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
+                // skip events other than opening or editing the issue to avoid retriggering commands in the
+                // issue body
+                return Ok(None);
             }
         }
 
         let mut input = Input::new(&body, &ctx.username);
-        match input.parse_command() {
+        let command = input.parse_command();
+        
+        if let Some(previous) = event.comment_from() {
+            let mut prev_input = Input::new(&previous, &ctx.username);
+            let prev_command = prev_input.parse_command();
+            if command == prev_command {
+                return Ok(None);
+            }
+        }
+        
+        match command {
             Command::Ping(Ok(command)) => Ok(Some(command)),
             Command::Ping(Err(err)) => {
                 return Err(format!(

+ 19 - 1
src/handlers/prioritize.rs

@@ -25,9 +25,27 @@ impl Handler for PrioritizeHandler {
             // not interested in other events
             return Ok(None);
         };
+        
+        if let Event::Issue(e) = event {
+            if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
+                // skip events other than opening or editing the issue to avoid retriggering commands in the
+                // issue body
+                return Ok(None);
+            }
+        }
 
         let mut input = Input::new(&body, &ctx.username);
-        match input.parse_command() {
+        let command = input.parse_command();
+        
+        if let Some(previous) = event.comment_from() {
+            let mut prev_input = Input::new(&previous, &ctx.username);
+            let prev_command = prev_input.parse_command();
+            if command == prev_command {
+                return Ok(None);
+            }
+        }
+        
+        match command {
             Command::Prioritize(Ok(PrioritizeCommand)) => Ok(Some(PrioritizeCommand)),
             _ => Ok(None),
         }

+ 13 - 3
src/handlers/relabel.rs

@@ -38,15 +38,25 @@ impl Handler for RelabelHandler {
         };
 
         if let Event::Issue(e) = event {
-            if e.action != github::IssuesAction::Opened {
-                // skip events other than opening the issue to avoid retriggering commands in the
+            if !matches!(e.action, github::IssuesAction::Opened | github::IssuesAction::Edited) {
+                // skip events other than opening or editing the issue to avoid retriggering commands in the
                 // issue body
                 return Ok(None);
             }
         }
 
         let mut input = Input::new(&body, &ctx.username);
-        match input.parse_command() {
+        let command = input.parse_command();
+        
+        if let Some(previous) = event.comment_from() {
+            let mut prev_input = Input::new(&previous, &ctx.username);
+            let prev_command = prev_input.parse_command();
+            if command == prev_command {
+                return Ok(None);
+            }
+        }
+        
+        match command {
             Command::Relabel(Ok(command)) => Ok(Some(command)),
             Command::Relabel(Err(err)) => {
                 return Err(format!(