diff --git a/Cargo.lock b/Cargo.lock index 2647c1c..f998bb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -786,7 +786,7 @@ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] name = "herald" -version = "1.0.0" +version = "1.0.1" dependencies = [ "anyhow", "axum", diff --git a/Cargo.toml b/Cargo.toml index 29abeab..520aaf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "herald" -version = "1.0.0" +version = "1.0.1" edition = "2024" [dependencies] diff --git a/src/env.rs b/src/env.rs index f391aff..855b58b 100644 --- a/src/env.rs +++ b/src/env.rs @@ -41,13 +41,13 @@ pub fn load_config() -> anyhow::Result { } pub fn try_get_env(key: &str) -> anyhow::Result { - let env = std::env::var(key).map_err(|e| anyhow::anyhow!(format!("{}: {}", key, e)))?; + let env_value = std::env::var(key).map_err(|e| anyhow::anyhow!("{}: {}", key, e))?; - if env.trim().is_empty() { + if env_value.trim().is_empty() { return Err(anyhow!(format!("env var {} is empty", key))); } - Ok(env) + Ok(env_value) } #[cfg(test)] diff --git a/src/gitea.rs b/src/gitea.rs index 34fb852..5bae543 100644 --- a/src/gitea.rs +++ b/src/gitea.rs @@ -206,14 +206,6 @@ impl WebhookType { _ => Err(AppError::UnknownEventErr), }?; - let pr_body = match &wb { - WebhookType::Review(review_payload) => &review_payload.comment.body, - }; - - if !pr_body.starts_with(&format!("@{}", bot_name)) { - return Err(AppError::UnauthorizedUserErr); - } - let action = match &wb { WebhookType::Review(review_payload) => &review_payload.action, }; @@ -222,6 +214,14 @@ impl WebhookType { return Err(AppError::InvalidActionErr); } + let pr_body = match &wb { + WebhookType::Review(review_payload) => &review_payload.comment.body, + }; + + if !pr_body.starts_with(&format!("@{}", bot_name)) { + return Err(AppError::UnauthorizedUserErr); + } + Ok(wb) } }