started gitea api impl #2
+12
-3
@@ -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<Self> {
|
||||
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<String> {
|
||||
let response = reqwest::get(url).await?;
|
||||
let response = self.http_client.get(url).send().await?;
|
||||
let body = response.text().await?;
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
+1
-4
@@ -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()?,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user