started gitea api impl #2
+12
-3
@@ -1,3 +1,5 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -65,18 +67,25 @@ pub struct Bot {
|
|||||||
config: EnvConfig,
|
config: EnvConfig,
|
||||||
gitea_api: GiteaAPI,
|
gitea_api: GiteaAPI,
|
||||||
open_router_client: OpenRouterClient,
|
open_router_client: OpenRouterClient,
|
||||||
|
http_client: reqwest::Client,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
pub fn new(config: EnvConfig) -> anyhow::Result<Self> {
|
pub fn new(config: EnvConfig) -> anyhow::Result<Self> {
|
||||||
|
let gitea_timeout = config.gitea_timeout;
|
||||||
|
let open_router_timeout = config.open_router_timeout;
|
||||||
|
|
||||||
Ok(Self {
|
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(
|
open_router_client: OpenRouterClient::new(
|
||||||
&config.open_router_api_key,
|
&config.open_router_api_key,
|
||||||
&config.open_router_model,
|
&config.open_router_model,
|
||||||
config.open_router_timeout,
|
open_router_timeout,
|
||||||
)?,
|
)?,
|
||||||
config,
|
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> {
|
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?;
|
let body = response.text().await?;
|
||||||
Ok(body)
|
Ok(body)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -8,7 +8,6 @@ use crate::errors::AppError;
|
|||||||
pub struct GiteaAPI {
|
pub struct GiteaAPI {
|
||||||
base_url: String,
|
base_url: String,
|
||||||
client: reqwest::Client,
|
client: reqwest::Client,
|
||||||
token: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GiteaAPI {
|
impl GiteaAPI {
|
||||||
@@ -24,9 +23,7 @@ impl GiteaAPI {
|
|||||||
client: reqwest::Client::builder()
|
client: reqwest::Client::builder()
|
||||||
.timeout(Duration::from_secs(timeout))
|
.timeout(Duration::from_secs(timeout))
|
||||||
.default_headers(default_headers)
|
.default_headers(default_headers)
|
||||||
.build()
|
.build()?,
|
||||||
.unwrap(),
|
|
||||||
token: String::from(token),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user