diff --git a/src/bot.rs b/src/bot.rs index 413de1e..72b80ab 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use serde::Deserialize; use crate::{ @@ -65,18 +67,25 @@ pub struct Bot { config: EnvConfig, gitea_api: GiteaAPI, open_router_client: OpenRouterClient, + http_client: reqwest::Client, } impl Bot { pub fn new(config: EnvConfig) -> anyhow::Result { + let gitea_timeout = config.gitea_timeout; + let open_router_timeout = config.open_router_timeout; + Ok(Self { - gitea_api: GiteaAPI::new(&config.gitea_url, &config.gitea_token, config.gitea_timeout)?, + gitea_api: GiteaAPI::new(&config.gitea_url, &config.gitea_token, gitea_timeout)?, open_router_client: OpenRouterClient::new( &config.open_router_api_key, &config.open_router_model, - config.open_router_timeout, + open_router_timeout, )?, config, + http_client: reqwest::Client::builder() + .timeout(Duration::from_secs(gitea_timeout)) + .build()?, }) } @@ -187,7 +196,7 @@ impl Bot { } async fn download_git_diff(&self, url: &str) -> anyhow::Result { - let response = reqwest::get(url).await?; + let response = self.http_client.get(url).send().await?; let body = response.text().await?; Ok(body) } diff --git a/src/gitea.rs b/src/gitea.rs index 4f81913..4da05b4 100644 --- a/src/gitea.rs +++ b/src/gitea.rs @@ -8,7 +8,6 @@ use crate::errors::AppError; pub struct GiteaAPI { base_url: String, client: reqwest::Client, - token: String, } impl GiteaAPI { @@ -24,9 +23,7 @@ impl GiteaAPI { client: reqwest::Client::builder() .timeout(Duration::from_secs(timeout)) .default_headers(default_headers) - .build() - .unwrap(), - token: String::from(token), + .build()?, }) }