diff --git a/src/models/author.rs b/src/models/author.rs new file mode 100644 index 0000000..d6c14d5 --- /dev/null +++ b/src/models/author.rs @@ -0,0 +1,76 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AuthorStats { + pub name: String, + pub email: String, + pub commits: usize, + pub lines_added: usize, + pub lines_removed: usize, + pub net_change: i64, + pub files_changed: usize, + pub first_commit: String, + pub last_commit: String, + pub active_days: usize, + pub average_commits_per_day: f64, + pub busiest_day: String, + pub busiest_day_count: usize, + pub commit_messages: Vec, +} + +impl Default for AuthorStats { + fn default() -> Self { + Self { + name: String::new(), + email: String::new(), + commits: 0, + lines_added: 0, + lines_removed: 0, + net_change: 0, + files_changed: 0, + first_commit: String::new(), + last_commit: String::new(), + active_days: 0, + average_commits_per_day: 0.0, + busiest_day: String::new(), + busiest_day_count: 0, + commit_messages: Vec::new(), + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct AuthorIdentity { + pub primary_name: String, + pub emails: Vec, + pub aliases: Vec, +} + +impl AuthorIdentity { + pub fn new(name: String) -> Self { + Self { + primary_name: name, + emails: Vec::new(), + aliases: Vec::new(), + } + } + + pub fn add_email(&mut self, email: String) { + if !self.emails.contains(&email) { + self.emails.push(email); + } + } + + pub fn add_alias(&mut self, alias: String) { + if !self.aliases.contains(&alias) && alias != self.primary_name { + self.aliases.push(alias); + } + } + + pub fn matches(&self, name: &str, email: &str) -> bool { + name == self.primary_name + || self.aliases.contains(&name.to_string()) + || self.emails.contains(&email.to_string()) + } +}