github_fetch/
config.rs

1use serde::{Deserialize, Serialize};
2use std::time::Duration;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct FetchConfig {
6    pub github: GitHubConfig,
7    pub rate_limiting: RateLimitConfig,
8}
9
10impl Default for FetchConfig {
11    fn default() -> Self {
12        Self {
13            github: GitHubConfig::default(),
14            rate_limiting: RateLimitConfig::default(),
15        }
16    }
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct GitHubConfig {
21    pub token_env_var: String,
22    pub api_base_url: String,
23    pub user_agent: String,
24    pub timeout_seconds: u64,
25}
26
27impl Default for GitHubConfig {
28    fn default() -> Self {
29        Self {
30            token_env_var: "GITHUB_TOKEN".to_string(),
31            api_base_url: "https://api.github.com".to_string(),
32            user_agent: "github-fetch/0.1.0".to_string(),
33            timeout_seconds: 30,
34        }
35    }
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct RateLimitConfig {
40    pub requests_per_minute: u32,
41    pub delay_between_requests_ms: u64,
42    pub respect_github_rate_limits: bool,
43    pub max_retries: u32,
44}
45
46impl Default for RateLimitConfig {
47    fn default() -> Self {
48        Self {
49            requests_per_minute: 60,
50            delay_between_requests_ms: 1000,
51            respect_github_rate_limits: true,
52            max_retries: 3,
53        }
54    }
55}
56
57impl RateLimitConfig {
58    pub fn delay_duration(&self) -> Duration {
59        Duration::from_millis(self.delay_between_requests_ms)
60    }
61}