use crate::config::Config;
use crate::git::Repo;
pub mod branches;
pub mod dormant;
pub mod orphans;
pub mod stashes;
pub mod wip;
#[derive(Debug, Clone)]
pub enum Finding {
StaleBranch {
name: String,
last_commit_ts: u64,
last_commit_message: String,
ahead: usize,
behind: usize,
},
Stash {
index: String,
sha: String,
ts: u64,
message: String,
files_changed: usize,
insertions: usize,
deletions: usize,
},
OrphanCommit {
sha: String,
ts: u64,
message: String,
},
WipCommit {
sha: String,
ts: u64,
message: String,
marker: String,
},
DormantRepo {
path: String,
last_activity_ts: u64,
},
}
impl Finding {
pub fn timestamp(&self) -> u64 {
match self {
Finding::StaleBranch { last_commit_ts, .. } => *last_commit_ts,
Finding::Stash { ts, .. } => *ts,
Finding::OrphanCommit { ts, .. } => *ts,
Finding::WipCommit { ts, .. } => *ts,
Finding::DormantRepo { last_activity_ts, .. } => *last_activity_ts,
}
}
}
pub trait Scanner {
fn name(&self) -> &'static str;
fn scan(&self, repo: &Repo) -> Vec<Finding>;
}
pub fn registry(config: &Config) -> Vec<Box<dyn Scanner>> {
vec![
Box::new(dormant::DormantScanner {
dormant_secs: config.dormant_secs(),
}),
Box::new(branches::BranchScanner {
stale_secs: config.stale_secs(),
ignore_branches: config.ignore_branches.clone(),
}),
Box::new(stashes::StashScanner),
Box::new(orphans::OrphanScanner),
Box::new(wip::WipScanner),
]
}