Skip to content
Clone
149bec6
45 lines 1.3 KB Rust
use std::sync::Arc;
use crate::smart::push::{NoopPushBackend, PushCoordinator, PushOperations, RedisPushBackend};
use crate::smart::service::SmartService;
use config::git::{GitSshConfig, SyncSettings};
#[derive(Clone)]
pub struct GitSshService {
pub smart: SmartService,
pub config: GitSshConfig,
pub sync_settings: SyncSettings,
}
impl GitSshService {
pub fn new(smart: SmartService, config: GitSshConfig) -> Self {
Self {
smart,
config,
sync_settings: SyncSettings::default(),
}
}
pub fn with_sync_settings(mut self, settings: SyncSettings) -> Self {
self.sync_settings = settings;
self
}
pub fn push_coordinator(&self) -> PushCoordinator {
let backend: Arc<dyn PushOperations> = match &self.smart.kv {
Some(kv) => Arc::new(RedisPushBackend { kv: kv.clone() }),
None => Arc::new(NoopPushBackend),
};
PushCoordinator::new(backend)
}
pub fn with_ci_event_topic(mut self, topic: Option<String>) -> Self {
self.smart = self.smart.with_ci_event_topic(topic);
self
}
pub fn with_ai_config(mut self, config: Option<config::ai::AiConfig>) -> Self {
self.smart = self.smart.with_ai_config(config);
self
}
}