Mohammed Naser | 7f6414c | 2025-02-17 16:02:00 -0500 | [diff] [blame] | 1 | use crate::RepositoryClient; |
| 2 | use async_trait::async_trait; |
| 3 | use gitea_sdk::Auth; |
| 4 | use gitea_sdk::Client as GiteaClient; |
| 5 | use std::error::Error; |
| 6 | |
| 7 | pub struct Client { |
| 8 | client: GiteaClient, |
| 9 | } |
| 10 | |
| 11 | impl Client { |
| 12 | pub fn new() -> Self { |
| 13 | Client { |
| 14 | client: GiteaClient::new("https://opendev.org", Auth::None::<String>), |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | #[async_trait] |
| 20 | impl RepositoryClient for Client { |
| 21 | async fn get_latest_commit( |
| 22 | &self, |
| 23 | repository: &crate::repository::Repository, |
| 24 | branch: &str, |
| 25 | ) -> Result<String, Box<dyn Error>> { |
| 26 | let branch_info = self |
| 27 | .client |
| 28 | .repos(repository.owner.clone(), repository.name.clone()) |
| 29 | .get_branch(branch) |
| 30 | .send(&self.client) |
| 31 | .await?; |
| 32 | |
| 33 | Ok(branch_info.commit.id) |
| 34 | } |
| 35 | } |