Browse Source

post errors in the issues whenever possible

Pietro Albini 6 years ago
parent
commit
60dcfba99d
3 changed files with 16 additions and 13 deletions
  1. 6 0
      src/github.rs
  2. 2 11
      src/handlers/label.rs
  3. 8 2
      src/main.rs

+ 6 - 0
src/github.rs

@@ -182,6 +182,12 @@ impl Event {
             Event::IssueComment(event) => &event.repository.full_name,
         }
     }
+
+    pub fn issue(&self) -> Option<&Issue> {
+        match self {
+            Event::IssueComment(event) => Some(&event.issue),
+        }
+    }
 }
 
 trait RequestSend: Sized {

+ 2 - 11
src/handlers/label.rs

@@ -37,18 +37,9 @@ impl Handler for LabelHandler {
         match input.parse_command() {
             Command::Label(Ok(command)) => Ok(Some(command)),
             Command::Label(Err(err)) => {
-                ErrorComment::new(
-                    &event.issue,
-                    format!(
-                        "Parsing label command in [comment]({}) failed: {}",
-                        event.comment.html_url, err
-                    ),
-                )
-                .post(&ctx.github)?;
                 failure::bail!(
-                    "label parsing failed for issue #{}, error: {:?}",
-                    event.issue.number,
-                    err
+                    "Parsing label command in [comment]({}) failed: {}",
+                    event.comment.html_url, err
                 );
             }
             _ => Ok(None),

+ 8 - 2
src/main.rs

@@ -11,13 +11,14 @@ use rocket::State;
 use rocket::{http::Status, Outcome, Request};
 use std::env;
 
-mod handlers;
 mod config;
 mod github;
+mod handlers;
 mod interactions;
 mod payload;
 mod team;
 
+use interactions::ErrorComment;
 use payload::SignedPayload;
 
 enum EventName {
@@ -75,7 +76,12 @@ fn webhook(
                 .map_err(Error::from)?;
 
             let event = github::Event::IssueComment(payload);
-            handlers::handle(&ctx, &event)?;
+            if let Err(err) = handlers::handle(&ctx, &event) {
+                if let Some(issue) = event.issue() {
+                    ErrorComment::new(issue, err.to_string()).post(&ctx.github)?;
+                }
+                return Err(err.into());
+            }
         }
         // Other events need not be handled
         EventName::Other => {}