use std::path::PathBuf; use std::sync::Arc; use ::cache::Cache; use db::AppDatabase; use models::repo::repos; use proto::kenshell::common::v1::{GitActor, RepositoryRef, WriteOptions}; #[derive(Clone)] pub struct GitContext { pub model: repos::Model, pub cache: Cache, pub database: Arc, pub space_name: String, pub repo_root: PathBuf, pub ks: proto::KenShellClient, } impl GitContext { pub fn repository_ref(&self) -> RepositoryRef { RepositoryRef { org_name: self.space_name.clone(), repo_name: self.model.name.clone(), } } pub fn actor(&self) -> GitActor { GitActor { user_id: 0, username: String::new(), } } pub fn write_options(&self) -> WriteOptions { WriteOptions { holder: format!("kenapi-{}", self.model.id), lock_ttl: Some(prost_types::Duration { seconds: 30, nanos: 0, }), lock_wait: Some(prost_types::Duration { seconds: 5, nanos: 0, }), require_all_replicas: false, } } pub fn repo_uninitialized(&self) -> bool { self.model.nums_commits == 0 } }