acbf7ea
use std::path::PathBuf;
use std::sync::Arc;
use cache::CacheClient;
use export::AppDatabase;
use kenshell::proto::common::v1::{GitActor, RepositoryRef, WriteOptions};
use models::repo::repos;
use uuid::Uuid;
#[derive(Clone)]
pub struct GitContext {
pub model: repos::Model,
pub cache: Arc<CacheClient>,
pub database: Arc<AppDatabase>,
pub space_name: String,
pub repo_root: PathBuf,
pub ks: kenshell::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_dir(&self) -> PathBuf {
repo_dir_for(&self.repo_root, self.model.id)
}
pub fn repo_uninitialized(&self) -> bool {
self.model.nums_commits == 0
}
}
pub fn repo_dir_for(repo_root: &std::path::Path, repo_id: Uuid) -> PathBuf {
repo_root.join(repo_id.to_string())
}