use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub fn default_patterns() -> Vec<String> {
vec![
r"#(\d+)".to_string(),
r"(?i)(?:refs|fixes|closes|resolves)\s+#(\d+)".to_string(),
r"/issues/(\d+)".to_string(),
]
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LabelColorConfig {
pub bg: String,
pub fg: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedmineConfig {
pub url: String,
#[serde(default = "default_patterns")]
pub ticket_patterns: Vec<String>,
#[serde(default)]
pub tracker_type_colors: HashMap<String, LabelColorConfig>,
#[serde(default)]
pub priority_colors: HashMap<String, LabelColorConfig>,
}
impl Default for RedmineConfig {
fn default() -> Self {
Self {
url: String::new(),
ticket_patterns: default_patterns(),
tracker_type_colors: HashMap::new(),
priority_colors: HashMap::new(),
}
}
}
impl RedmineConfig {
pub fn is_active(&self) -> bool {
!self.url.trim().is_empty()
}
pub fn apply_env_override(&mut self) -> bool {
if let Ok(url) = std::env::var("REDMINE_URL") {
let url = url.trim().to_string();
if !url.is_empty() {
self.url = url;
return true;
}
}
false
}
}