use std::ops::Deref;
use std::ops::DerefMut;
use std::path::Path;
use super::git;
use super::git::RepoInfo;
use super::info::GitHubInfo;
use super::info::ProjectCiData;
use super::info::ProjectPrData;
use super::root_item::RootItem;
#[derive(Clone, Default)]
pub(crate) struct GitRepo {
pub repo_info: Option<RepoInfo>,
pub github_info: Option<GitHubInfo>,
pub ci_data: ProjectCiData,
pub pr_data: ProjectPrData,
}
#[derive(Clone)]
pub(crate) struct ProjectEntry {
pub item: RootItem,
pub git_repo: Option<GitRepo>,
}
impl ProjectEntry {
pub(crate) fn new(item: RootItem) -> Self {
let git_repo = git_repo_for(&item);
Self { item, git_repo }
}
pub(crate) const fn with_repo(item: RootItem, git_repo: Option<GitRepo>) -> Self {
Self { item, git_repo }
}
#[cfg(test)]
#[expect(dead_code, reason = "Reserved for later-stage test helpers")]
pub(crate) fn for_tests(item: RootItem) -> Self { Self::new(item) }
}
impl Deref for ProjectEntry {
type Target = RootItem;
fn deref(&self) -> &RootItem { &self.item }
}
impl DerefMut for ProjectEntry {
fn deref_mut(&mut self) -> &mut RootItem { &mut self.item }
}
fn git_repo_for(item: &RootItem) -> Option<GitRepo> {
git::git_repo_root(item.path()).map(|_| GitRepo::default())
}
pub(crate) fn entry_contains(entry: &ProjectEntry, target: &Path) -> bool {
entry.item.at_path(target).is_some()
|| entry
.item
.submodules()
.iter()
.any(|s| s.path.as_path() == target)
}