Fix AI review
Webhook action check before user check
This commit is contained in:
Generated
+1
-1
@@ -786,7 +786,7 @@ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "herald"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "herald"
|
||||
version = "1.0.0"
|
||||
version = "1.0.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
+3
-3
@@ -41,13 +41,13 @@ pub fn load_config() -> anyhow::Result<EnvConfig> {
|
||||
}
|
||||
|
||||
pub fn try_get_env(key: &str) -> anyhow::Result<String> {
|
||||
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)]
|
||||
|
||||
+8
-8
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user