Skip to content

Commit 310007f

Browse files
committed
Move around some structs
1 parent d13d61f commit 310007f

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/handlers.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,6 @@ use std::fmt;
1010
use std::sync::Arc;
1111
use tracing as log;
1212

13-
#[derive(Debug)]
14-
pub enum HandlerError {
15-
Message(String),
16-
Other(anyhow::Error),
17-
}
18-
19-
impl std::error::Error for HandlerError {}
20-
21-
impl fmt::Display for HandlerError {
22-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23-
match self {
24-
HandlerError::Message(msg) => write!(f, "{}", msg),
25-
HandlerError::Other(_) => write!(f, "An internal error occurred."),
26-
}
27-
}
28-
}
29-
30-
#[derive(Debug)]
31-
pub struct UserError(String);
32-
33-
impl std::error::Error for UserError {}
34-
35-
impl fmt::Display for UserError {
36-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37-
f.write_str(&self.0)
38-
}
39-
}
40-
4113
macro_rules! inform {
4214
(msg:literal $(,)?) => {
4315
anyhow::bail!(crate::handlers::UserError($msg.into()))
@@ -81,6 +53,19 @@ mod shortcut;
8153
mod transfer;
8254
pub mod types_planning_updates;
8355

56+
pub struct Context {
57+
pub github: GithubClient,
58+
pub zulip: ZulipClient,
59+
pub team: TeamClient,
60+
pub db: crate::db::ClientPool,
61+
pub username: String,
62+
pub octocrab: Octocrab,
63+
/// Represents the workqueue (assigned open PRs) of individual reviewers.
64+
/// tokio's RwLock is used to avoid deadlocks, since we run on a single-threaded tokio runtime.
65+
pub workqueue: Arc<tokio::sync::RwLock<ReviewerWorkqueue>>,
66+
pub gha_logs: Arc<tokio::sync::RwLock<GitHubActionLogsCache>>,
67+
}
68+
8469
pub async fn handle(ctx: &Context, host: &str, event: &Event) -> Vec<HandlerError> {
8570
let config = config::get(&ctx.github, event.repo()).await;
8671
if let Err(e) = &config {
@@ -440,15 +425,30 @@ command_handlers! {
440425
transfer: Transfer,
441426
}
442427

443-
pub struct Context {
444-
pub github: GithubClient,
445-
pub zulip: ZulipClient,
446-
pub team: TeamClient,
447-
pub db: crate::db::ClientPool,
448-
pub username: String,
449-
pub octocrab: Octocrab,
450-
/// Represents the workqueue (assigned open PRs) of individual reviewers.
451-
/// tokio's RwLock is used to avoid deadlocks, since we run on a single-threaded tokio runtime.
452-
pub workqueue: Arc<tokio::sync::RwLock<ReviewerWorkqueue>>,
453-
pub gha_logs: Arc<tokio::sync::RwLock<GitHubActionLogsCache>>,
428+
#[derive(Debug)]
429+
pub enum HandlerError {
430+
Message(String),
431+
Other(anyhow::Error),
432+
}
433+
434+
impl std::error::Error for HandlerError {}
435+
436+
impl fmt::Display for HandlerError {
437+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
438+
match self {
439+
HandlerError::Message(msg) => write!(f, "{}", msg),
440+
HandlerError::Other(_) => write!(f, "An internal error occurred."),
441+
}
442+
}
443+
}
444+
445+
#[derive(Debug)]
446+
pub struct UserError(String);
447+
448+
impl std::error::Error for UserError {}
449+
450+
impl fmt::Display for UserError {
451+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
452+
f.write_str(&self.0)
453+
}
454454
}

0 commit comments

Comments
 (0)