Use reqwest 0.12 with rustls-tls and add timeouts

Also improve review prompt with line calculation instructions, switch
feedback to French, and enable reasoning for OpenRouter.
This commit is contained in:
2026-06-03 20:51:21 +00:00
parent de81232201
commit cd5c5b9478
7 changed files with 46 additions and 446 deletions
+3 -2
View File
@@ -69,10 +69,11 @@ pub struct Bot {
impl Bot {
pub fn new(config: EnvConfig) -> anyhow::Result<Self> {
Ok(Self {
gitea_api: GiteaAPI::new(&config.gitea_url, &config.gitea_token),
gitea_api: GiteaAPI::new(&config.gitea_url, &config.gitea_token, config.gitea_timeout),
open_router_client: OpenRouterClient::new(
&config.open_router_api_key,
&config.open_router_model,
config.open_router_timeout,
)?,
config,
})
@@ -116,7 +117,7 @@ impl Bot {
.download_git_diff(&review_payload.pull_request.diff_url)
.await?;
let bot_request = &&REVIEW_PROMPT
let bot_request = REVIEW_PROMPT
.replace("{subject}", &review_payload.pull_request.title)
.replace("{comment}", &review_payload.comment.body)
.replace("{diff}", &git_diff);
+11 -1
View File
@@ -20,7 +20,17 @@ pub const REVIEW_PROMPT: &str = "
\"{diff}\"
Please review the code changes and provide feedback.
Return your feedback with only this json format, reviews must contain each review (filename field must contain the full path with extension) and comment msut contain a final summary:
IMPORTANT — How to compute the line number:
The diff is in unified format. Each hunk starts with a header like:
`@@ -old_start,old_count +new_start,new_count @@`
The `line` field must be the line number in the **new** version of the file.
To find it, start at `new_start`, then count every context line (no prefix)
and every added line (prefixed with `+`) — skip removed lines (prefixed with `-`).
The line number increments by 1 for each context or added line.
Return your feedback, in french, with only this json format, reviews must contain each review
(filename field must contain the full path with extension) and comment must contain a final summary:
{
\"reviews\": [
+6
View File
@@ -7,9 +7,11 @@ pub struct EnvConfig {
pub webhook_secret: String,
pub open_router_api_key: String,
pub open_router_model: String,
pub open_router_timeout: u64,
pub bot_name: String,
pub gitea_url: String,
pub gitea_token: String,
pub gitea_timeout: u64,
}
pub fn load_config() -> anyhow::Result<EnvConfig> {
@@ -20,8 +22,10 @@ pub fn load_config() -> anyhow::Result<EnvConfig> {
let webhook_secret = try_get_env("WEBHOOK_SIG_HEADER_SECRET")?;
let open_router_api_key = try_get_env("OPEN_ROUTER_API_KEY")?;
let open_router_model = try_get_env("OPEN_ROUTER_MODEL")?;
let open_router_timeout = try_get_env("OPEN_ROUTER_TIMEOUT")?.parse()?;
let gitea_url = try_get_env("GITEA_URL")?;
let gitea_token = try_get_env("GITEA_TOKEN")?;
let gitea_timeout = try_get_env("GITEA_TIMEOUT")?.parse()?;
Ok(EnvConfig {
http_port,
@@ -29,8 +33,10 @@ pub fn load_config() -> anyhow::Result<EnvConfig> {
bot_name,
open_router_api_key,
open_router_model,
open_router_timeout,
gitea_url,
gitea_token,
gitea_timeout,
})
}
+14 -8
View File
@@ -1,3 +1,5 @@
use std::time::Duration;
use serde::Deserialize;
use serde_json::{Value, json};
@@ -5,13 +7,18 @@ use crate::errors::AppError;
pub struct GiteaAPI {
base_url: String,
client: reqwest::Client,
token: String,
}
impl GiteaAPI {
pub fn new(base_url: &str, token: &str) -> Self {
pub fn new(base_url: &str, token: &str, timeout: u64) -> Self {
Self {
base_url: String::from(base_url),
client: reqwest::Client::builder()
.timeout(Duration::from_secs(timeout))
.build()
.unwrap(),
token: String::from(token),
}
}
@@ -27,8 +34,8 @@ impl GiteaAPI {
self.base_url, full_name, index, self.token
);
let client = reqwest::Client::new();
let res = client
let res = self
.client
.post(url)
.json(&json!({
"body": body
@@ -50,16 +57,15 @@ impl GiteaAPI {
self.base_url, full_name, comment_id, self.token
);
let client = reqwest::Client::new();
let res = client
self.client
.patch(url)
.json(&json!({
"body": body
}))
.send()
.await?;
Ok(())
.await
.map(|_| ())
.map_err(anyhow::Error::from)
}
}
+9 -1
View File
@@ -1,3 +1,5 @@
use std::time::Duration;
use openrouter_rs::{Message, api::chat::ChatCompletionRequest};
pub struct OpenRouterClient {
@@ -6,10 +8,15 @@ pub struct OpenRouterClient {
}
impl OpenRouterClient {
pub fn new(token: &str, model: &str) -> anyhow::Result<Self> {
pub fn new(token: &str, model: &str, timeout: u64) -> anyhow::Result<Self> {
Ok(Self {
client: openrouter_rs::OpenRouterClient::builder()
.api_key(token)
.http_client(
reqwest::Client::builder()
.timeout(Duration::from_secs(timeout))
.build()?,
)
.build()?,
model: String::from(model),
})
@@ -18,6 +25,7 @@ impl OpenRouterClient {
pub async fn chat(&self, msg: &str) -> anyhow::Result<String> {
let request = ChatCompletionRequest::builder()
.model(&self.model)
.enable_reasoning()
.messages(vec![Message::new(
openrouter_rs::types::Role::Developer,
msg,