Skip to content

Commit

Permalink
fix(core): Fix default method not implement
Browse files Browse the repository at this point in the history
Signed-off-by: KunoiSayami <[email protected]>
  • Loading branch information
KunoiSayami committed Dec 12, 2021
1 parent 5297369 commit 3b9a1f6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "github-webhook-notification"
version = "2.0.0-beta"
version = "2.0.0-rc"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion data/config.toml.default
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[server]
bind = ""
bind = "127.0.0.1"
port = 25511
secrets = ""
#token = ""
Expand Down
33 changes: 14 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@ use tokio::sync::{mpsc, Mutex};

mod configure;
mod datastructures;
#[cfg(test)]
mod test;

const SERVER_VERSION: &str = env!("CARGO_PKG_VERSION");

#[derive(Debug)]
enum Command {
Terminate,
#[allow(unused)]
#[deprecated(
since = "1.2.0",
note = "You should use Data to direct process GitHub event, \
and it will remove in next release"
)]
Text(String),
Data(Box<dyn DisplayableEvent>),
}

Expand Down Expand Up @@ -81,16 +75,6 @@ async fn process_send_message(
let bot = bot.parse_mode(ParseMode::Html);
while let Some(cmd) = rx.recv().await {
match cmd {
#[allow(deprecated)]
Command::Text(text) => {
for send_to in receiver.clone() {
let mut payload = bot.send_message(send_to, text.clone());
payload.disable_web_page_preview = Option::from(true);
if let Err(e) = payload.send().await {
error!("Got error in send message {:?}", e);
}
}
}
Command::Data(event) => {
if let Some(repository) = specify_configures.get(event.get_full_name()) {
if repository.branch_ignore().contains(&event.branch_name()) {
Expand All @@ -108,6 +92,14 @@ async fn process_send_message(
error!("Got error in send message {:?}", e);
}
}
} else {
for send_to in receiver.clone() {
let mut payload = bot.send_message(send_to, event.to_string());
payload.disable_web_page_preview = Option::from(true);
if let Err(e) = payload.send().await {
error!("Got error in send message {:?}", e);
}
}
}
}
Command::Terminate => break,
Expand All @@ -117,6 +109,10 @@ async fn process_send_message(
Ok(())
}

fn check_0(s: &str) -> bool {
s.chars().into_iter().all(|x| x == '0')
}

async fn route_post(
request: HttpRequest,
mut payload: web::Payload,
Expand Down Expand Up @@ -165,8 +161,7 @@ async fn route_post(
}
"push" => {
let request_body = serde_json::from_slice::<GitHubPushEvent>(&body)?;
if request_body.after().starts_with("000000000000")
|| request_body.before().starts_with("000000000000")
if check_0(request_body.after()) || check_0(request_body.before())
{
return Ok(HttpResponse::NoContent().finish());
}
Expand Down

0 comments on commit 3b9a1f6

Please sign in to comment.