Browse Source

rustfmt all code

In-editor rustfmt was broken due to lack of --edition=2018 which is not
autodetected
Mark Rousskov 5 years ago
parent
commit
8fca96a11f
5 changed files with 101 additions and 83 deletions
  1. 2 1
      src/config.rs
  2. 1 5
      src/handlers.rs
  3. 79 68
      src/handlers/assign.rs
  4. 9 3
      src/handlers/relabel.rs
  5. 10 6
      src/lib.rs

+ 2 - 1
src/config.rs

@@ -54,7 +54,8 @@ fn get_cached_config(repo: &str) -> Option<Arc<Config>> {
 
 async fn get_fresh_config(gh: &GithubClient, repo: &str) -> Result<Arc<Config>, Error> {
     let contents = gh
-        .raw_file(repo, "master", CONFIG_FILE_NAME).await?
+        .raw_file(repo, "master", CONFIG_FILE_NAME)
+        .await?
         .ok_or_else(|| {
             failure::err_msg(
                 "This repository is not enabled to use triagebot.\n\

+ 1 - 5
src/handlers.rs

@@ -40,11 +40,7 @@ pub trait Handler: Sync + Send {
     type Input;
     type Config;
 
-    fn parse_input(
-        &self,
-        ctx: &Context,
-        event: &Event,
-    ) -> Result<Option<Self::Input>, Error>;
+    fn parse_input(&self, ctx: &Context, event: &Event) -> Result<Option<Self::Input>, Error>;
 
     fn handle_input<'a>(
         &self,

+ 79 - 68
src/handlers/assign.rs

@@ -18,9 +18,9 @@ use crate::{
     interactions::EditIssueBody,
 };
 use failure::{Error, ResultExt};
+use futures::future::{BoxFuture, FutureExt};
 use parser::command::assign::AssignCommand;
 use parser::command::{Command, Input};
-use futures::future::{FutureExt, BoxFuture};
 
 pub(super) struct AssignmentHandler;
 
@@ -76,79 +76,90 @@ impl Handler for AssignmentHandler {
 }
 
 async fn handle_input(ctx: &Context, event: &Event, cmd: AssignCommand) -> Result<(), Error> {
-        let is_team_member = if let Err(_) | Ok(false) = event.user().is_team_member(&ctx.github).await {
-            false
-        } else {
-            true
-        };
+    let is_team_member = if let Err(_) | Ok(false) = event.user().is_team_member(&ctx.github).await
+    {
+        false
+    } else {
+        true
+    };
 
-        let e = EditIssueBody::new(&event.issue().unwrap(), "ASSIGN");
+    let e = EditIssueBody::new(&event.issue().unwrap(), "ASSIGN");
 
-        let to_assign = match cmd {
-            AssignCommand::Own => event.user().login.clone(),
-            AssignCommand::User { username } => {
-                if !is_team_member && username != event.user().login {
-                    failure::bail!("Only Rust team members can assign other users");
-                }
-                username.clone()
+    let to_assign = match cmd {
+        AssignCommand::Own => event.user().login.clone(),
+        AssignCommand::User { username } => {
+            if !is_team_member && username != event.user().login {
+                failure::bail!("Only Rust team members can assign other users");
             }
-            AssignCommand::Release => {
-                if let Some(AssignData {
-                    user: Some(current),
-                }) = e.current_data()
-                {
-                    if current == event.user().login || is_team_member {
-                        event
-                            .issue()
-                            .unwrap()
-                            .remove_assignees(&ctx.github, Selection::All).await?;
-                        e.apply(&ctx.github, String::new(), AssignData { user: None }).await?;
-                        return Ok(());
-                    } else {
-                        failure::bail!("Cannot release another user's assignment");
-                    }
+            username.clone()
+        }
+        AssignCommand::Release => {
+            if let Some(AssignData {
+                user: Some(current),
+            }) = e.current_data()
+            {
+                if current == event.user().login || is_team_member {
+                    event
+                        .issue()
+                        .unwrap()
+                        .remove_assignees(&ctx.github, Selection::All)
+                        .await?;
+                    e.apply(&ctx.github, String::new(), AssignData { user: None })
+                        .await?;
+                    return Ok(());
                 } else {
-                    let current = &event.user();
-                    if event.issue().unwrap().contain_assignee(current) {
-                        event
-                            .issue()
-                            .unwrap()
-                            .remove_assignees(&ctx.github, Selection::One(&current)).await?;
-                        e.apply(&ctx.github, String::new(), AssignData { user: None }).await?;
-                        return Ok(());
-                    } else {
-                        failure::bail!("Cannot release unassigned issue");
-                    }
-                };
-            }
-        };
-        let data = AssignData {
-            user: Some(to_assign.clone()),
-        };
+                    failure::bail!("Cannot release another user's assignment");
+                }
+            } else {
+                let current = &event.user();
+                if event.issue().unwrap().contain_assignee(current) {
+                    event
+                        .issue()
+                        .unwrap()
+                        .remove_assignees(&ctx.github, Selection::One(&current))
+                        .await?;
+                    e.apply(&ctx.github, String::new(), AssignData { user: None })
+                        .await?;
+                    return Ok(());
+                } else {
+                    failure::bail!("Cannot release unassigned issue");
+                }
+            };
+        }
+    };
+    let data = AssignData {
+        user: Some(to_assign.clone()),
+    };
 
-        e.apply(&ctx.github, String::new(), &data).await?;
+    e.apply(&ctx.github, String::new(), &data).await?;
 
-        match event.issue().unwrap().set_assignee(&ctx.github, &to_assign).await {
-            Ok(()) => return Ok(()), // we are done
-            Err(github::AssignmentError::InvalidAssignee) => {
-                event
-                    .issue()
-                    .unwrap()
-                    .set_assignee(&ctx.github, &ctx.username).await
-                    .context("self-assignment failed")?;
-                e.apply(
-                    &ctx.github,
-                    format!(
-                        "This issue has been assigned to @{} via [this comment]({}).",
-                        to_assign,
-                        event.html_url().unwrap()
-                    ),
-                    &data,
-                ).await?;
-            }
-            Err(e) => return Err(e.into()),
+    match event
+        .issue()
+        .unwrap()
+        .set_assignee(&ctx.github, &to_assign)
+        .await
+    {
+        Ok(()) => return Ok(()), // we are done
+        Err(github::AssignmentError::InvalidAssignee) => {
+            event
+                .issue()
+                .unwrap()
+                .set_assignee(&ctx.github, &ctx.username)
+                .await
+                .context("self-assignment failed")?;
+            e.apply(
+                &ctx.github,
+                format!(
+                    "This issue has been assigned to @{} via [this comment]({}).",
+                    to_assign,
+                    event.html_url().unwrap()
+                ),
+                &data,
+            )
+            .await?;
         }
+        Err(e) => return Err(e.into()),
+    }
 
-        Ok(())
-
+    Ok(())
 }

+ 9 - 3
src/handlers/relabel.rs

@@ -15,9 +15,9 @@ use crate::{
     interactions::ErrorComment,
 };
 use failure::Error;
+use futures::future::{BoxFuture, FutureExt};
 use parser::command::relabel::{LabelDelta, RelabelCommand};
 use parser::command::{Command, Input};
-use futures::future::{FutureExt, BoxFuture};
 
 pub(super) struct RelabelHandler;
 
@@ -66,7 +66,12 @@ impl Handler for RelabelHandler {
     }
 }
 
-async fn handle_input(ctx: &Context, config: &RelabelConfig, event: &Event, input: RelabelCommand) -> Result<(), Error> {
+async fn handle_input(
+    ctx: &Context,
+    config: &RelabelConfig,
+    event: &Event,
+    input: RelabelCommand,
+) -> Result<(), Error> {
     let mut issue_labels = event.issue().unwrap().labels().to_owned();
     let mut changed = false;
     for delta in &input.0 {
@@ -98,7 +103,8 @@ async fn handle_input(ctx: &Context, config: &RelabelConfig, event: &Event, inpu
         event
             .issue()
             .unwrap()
-            .set_labels(&ctx.github, issue_labels).await?;
+            .set_labels(&ctx.github, issue_labels)
+            .await?;
     }
 
     Ok(())

+ 10 - 6
src/lib.rs

@@ -2,8 +2,8 @@
 #![allow(clippy::new_without_default)]
 
 use failure::{Error, ResultExt};
-use std::fmt;
 use interactions::ErrorComment;
+use std::fmt;
 
 pub mod config;
 pub mod github;
@@ -31,11 +31,15 @@ impl std::str::FromStr for EventName {
 
 impl fmt::Display for EventName {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "{}", match self {
-            EventName::IssueComment => "issue_comment",
-            EventName::Issue => "issues",
-            EventName::Other => "other",
-        })
+        write!(
+            f,
+            "{}",
+            match self {
+                EventName::IssueComment => "issue_comment",
+                EventName::Issue => "issues",
+                EventName::Other => "other",
+            }
+        )
     }
 }