blob: b8ac5f3a86ee8853c6549d7d1bbbc25b630a7f6b [file] [log] [blame]
Mohammed Naser7f6414c2025-02-17 16:02:00 -05001use crate::RepositoryClient;
2use async_trait::async_trait;
3use octocrab::Octocrab;
4use std::error::Error;
5use std::sync::Arc;
6
7pub struct Client {
8 client: Arc<Octocrab>,
9}
10
11impl Client {
12 pub fn new() -> Self {
13 Client {
14 client: octocrab::instance(),
15 }
16 }
17}
18
19#[async_trait]
20impl 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}