started gitea api impl
This commit is contained in:
+36
-3
@@ -1,13 +1,46 @@
|
||||
use crate::{env::EnvConfig, gitea::WebhookType};
|
||||
use crate::{
|
||||
env::EnvConfig,
|
||||
errors::AppError,
|
||||
gitea::{GiteaAPI, ReviewPayload, WebhookType},
|
||||
};
|
||||
|
||||
pub struct Bot {
|
||||
config: EnvConfig,
|
||||
gitea_api: GiteaAPI,
|
||||
}
|
||||
|
||||
impl Bot {
|
||||
pub fn new(config: EnvConfig) -> Self {
|
||||
Self { config }
|
||||
Self {
|
||||
gitea_api: GiteaAPI::new(&config.gitea_url),
|
||||
config,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn exec(&self, webhook: WebhookType) {}
|
||||
pub async fn start(
|
||||
&self,
|
||||
mut rx: tokio::sync::mpsc::Receiver<WebhookType>,
|
||||
) -> anyhow::Result<()> {
|
||||
while let Some(wb) = rx.recv().await {
|
||||
self.exec(wb).await;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn exec(&self, webhook: WebhookType) {
|
||||
let exec_result = match webhook {
|
||||
WebhookType::Review(review_payload) => self.exec_review(review_payload),
|
||||
}
|
||||
.await;
|
||||
|
||||
match exec_result {
|
||||
Ok(_) => println!("Task completed"),
|
||||
Err(_) => println!("Task errored"),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn exec_review(&self, review_payload: ReviewPayload) -> Result<(), AppError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user