use crate::{domain::CommitHash, error::CommitHashError, model::Branch, polling::git::GitFetcher};
pub(super) struct BranchInfo {
pub branch: Branch,
pub latest_hash: CommitHash,
}
impl BranchInfo {
pub async fn new<F: GitFetcher + ?Sized>(
branch: Branch,
fetcher: &F,
) -> Result<BranchInfo, CommitHashError> {
let latest_hash = fetcher
.get_latest_hash(branch.repo_url.as_str(), branch.name.as_str())
.await?;
Ok(BranchInfo {
branch,
latest_hash,
})
}
pub fn has_updated(&self) -> bool {
self.branch.last_commit_hash.as_deref() != Some(&self.latest_hash)
}
}