use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Commit {
pub id: i64,
pub sha: String,
pub author_id: Option<i64>,
pub author_name: String,
pub author_email: String,
pub timestamp: DateTime<Utc>,
pub message: String,
pub repository: String,
pub files_changed: u32,
pub insertions: u32,
pub deletions: u32,
pub classification_id: Option<i64>,
pub confidence: Option<f64>,
pub is_merge: bool,
pub ticketed: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Author {
pub id: i64,
pub canonical_name: String,
pub canonical_email: String,
pub aliases: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Classification {
pub id: i64,
pub category: String,
pub subcategory: Option<String>,
pub ticket_id: Option<String>,
pub confidence: f64,
pub method: ClassificationMethod,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileChange {
pub id: i64,
pub commit_id: i64,
pub path: String,
pub change_type: ChangeType,
pub insertions: u32,
pub deletions: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PullRequest {
pub id: i64,
pub pr_number: u64,
pub repository: String,
pub title: String,
pub author: String,
pub state: PrState,
pub created_at: DateTime<Utc>,
pub merged_at: Option<DateTime<Utc>>,
pub commit_shas: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ClassificationMethod {
ExactRule,
RegexRule,
FuzzyMatch,
LlmFallback,
Manual,
ExternalSource,
}
impl ClassificationMethod {
pub fn as_str(&self) -> &'static str {
match self {
ClassificationMethod::ExactRule => "exact_rule",
ClassificationMethod::RegexRule => "regex_rule",
ClassificationMethod::FuzzyMatch => "fuzzy_match",
ClassificationMethod::LlmFallback => "llm_fallback",
ClassificationMethod::Manual => "manual",
ClassificationMethod::ExternalSource => "external_source",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ChangeType {
Added,
Modified,
Deleted,
Renamed,
}
impl ChangeType {
pub fn as_str(&self) -> &'static str {
match self {
ChangeType::Added => "added",
ChangeType::Modified => "modified",
ChangeType::Deleted => "deleted",
ChangeType::Renamed => "renamed",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PrState {
Open,
Closed,
Merged,
}
impl PrState {
pub fn as_str(&self) -> &'static str {
match self {
PrState::Open => "open",
PrState::Closed => "closed",
PrState::Merged => "merged",
}
}
}