Skip to content
Clone
cb06060
52 lines 1.2 KB Rust
use std::path::PathBuf;
use std::sync::Arc;
use ::cache::Cache;
use export::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<AppDatabase>,
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
}
}