Skip to main content

aptu_core/config/
cache.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Cache configuration.
4
5use serde::{Deserialize, Serialize};
6
7/// Cache settings.
8#[derive(Debug, Deserialize, Serialize, Clone)]
9#[serde(default)]
10pub struct CacheConfig {
11    /// Issue cache TTL in minutes.
12    pub issue_ttl_minutes: i64,
13    /// Repository metadata cache TTL in hours.
14    pub repo_ttl_hours: i64,
15    /// URL to fetch curated repositories from.
16    pub curated_repos_url: String,
17    /// File eviction TTL in days (default: 7).
18    pub file_eviction_days: i64,
19}
20
21impl Default for CacheConfig {
22    fn default() -> Self {
23        Self {
24            issue_ttl_minutes: crate::cache::DEFAULT_ISSUE_TTL_MINS,
25            repo_ttl_hours: crate::cache::DEFAULT_REPO_TTL_HOURS,
26            curated_repos_url:
27                "https://raw.githubusercontent.com/clouatre-labs/aptu/main/data/curated-repos.json"
28                    .to_string(),
29            file_eviction_days: 7,
30        }
31    }
32}
33
34impl CacheConfig {
35    /// Validates cache configuration.
36    ///
37    /// Ensures `file_eviction_days` is positive (> 0).
38    ///
39    /// # Errors
40    ///
41    /// Returns an error if `file_eviction_days <= 0`.
42    pub fn validate(&self) -> Result<(), String> {
43        if self.file_eviction_days <= 0 {
44            return Err(format!(
45                "file_eviction_days must be > 0, got {}",
46                self.file_eviction_days
47            ));
48        }
49        Ok(())
50    }
51}
52
53/// Repository settings.
54#[derive(Debug, Deserialize, Serialize, Clone)]
55#[serde(default)]
56pub struct ReposConfig {
57    /// Include curated repositories (default: true).
58    pub curated: bool,
59    /// DCO sign-off on commits (default: false).
60    #[serde(default)]
61    pub dco_signoff: bool,
62}
63
64impl Default for ReposConfig {
65    fn default() -> Self {
66        Self {
67            curated: true,
68            dco_signoff: false,
69        }
70    }
71}