Mohammed Naser | 7f6414c | 2025-02-17 16:02:00 -0500 | [diff] [blame] | 1 | use crate::RepositoryClient; |
| 2 | use async_trait::async_trait; |
| 3 | use octocrab::Octocrab; |
| 4 | use std::error::Error; |
| 5 | use std::sync::Arc; |
| 6 | |
| 7 | pub struct Client { |
| 8 | client: Arc<Octocrab>, |
| 9 | } |
| 10 | |
| 11 | impl Client { |
| 12 | pub fn new() -> Self { |
| 13 | Client { |
| 14 | client: octocrab::instance(), |
| 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 commits = self |
| 27 | .client |
| 28 | .repos(repository.owner.clone(), repository.name.clone()) |
| 29 | .list_commits() |
| 30 | .branch(branch) |
| 31 | .send() |
| 32 | .await?; |
| 33 | |
| 34 | Ok(commits.items[0].sha.clone()) |
| 35 | } |
| 36 | } |