From 3f19c49c63ed70bd50001f07c180d1b4595737dc Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Fri, 8 Dec 2023 20:01:19 +0100 Subject: [PATCH] feat: add clone url display - clone_prefix - ssh_clone_prefix - enable_http_clone --- src/configuration/mod.rs | 5 +++++ src/database/indexer.rs | 5 +++++ src/database/schema/repository.rs | 4 ++++ src/methods/repo/summary.rs | 2 ++ templates/repo/summary.html | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+) diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index a107a92..6fde2e1 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -101,4 +101,9 @@ impl AppConfig { pub fn load(path: String) -> Self { confy::load_path(path).unwrap_or_default() } + + pub fn http_clone_enabled(&self) -> bool { + (!self.clone_prefix.is_empty() || !self.ssh_clone_prefix.is_empty()) + && self.enable_http_clone + } } diff --git a/src/database/indexer.rs b/src/database/indexer.rs index 3469009..67ac884 100644 --- a/src/database/indexer.rs +++ b/src/database/indexer.rs @@ -88,6 +88,7 @@ fn update_repository_metadata(scan_path: &Path, db: &rocksdb::DB) { .ok() .flatten() .map(Cow::Owned), + exported: is_repository_exported(repository_path.as_path()), } .insert(db, relative); @@ -417,3 +418,7 @@ fn find_gitweb_owner(repository_path: &Path) -> Option> { .map(String::from) .map(Cow::Owned) } + +fn is_repository_exported(repository_path: &Path) -> Cow<'_, bool> { + Cow::Owned(repository_path.join("git-daemon-export-ok").exists()) +} diff --git a/src/database/schema/repository.rs b/src/database/schema/repository.rs index 763fc15..f29de85 100644 --- a/src/database/schema/repository.rs +++ b/src/database/schema/repository.rs @@ -33,6 +33,10 @@ pub struct Repository<'a> { /// The default branch for Git operations #[serde(borrow)] pub default_branch: Option>, + /// Whether the repository is available for HTTP(s) cloning + /// + /// This is set to `true` based on the presence of `git-daemon-export-ok` in the repository + pub exported: Cow<'a, bool>, } pub type YokedRepository = Yoked>; diff --git a/src/methods/repo/summary.rs b/src/methods/repo/summary.rs index 24ed16b..fd7b6d7 100644 --- a/src/methods/repo/summary.rs +++ b/src/methods/repo/summary.rs @@ -22,6 +22,7 @@ pub struct View { commit_list: Vec, branch: Option>, config: AppConfig, + repo_exported: bool, } pub async fn handle( @@ -52,6 +53,7 @@ pub async fn handle( commit_list: commits, branch: None, config, + repo_exported: *repository.get().exported, })) }) .await diff --git a/templates/repo/summary.html b/templates/repo/summary.html index 64e0a4d..80a000f 100644 --- a/templates/repo/summary.html +++ b/templates/repo/summary.html @@ -61,6 +61,41 @@ {%- endif %} + + {%- if repo_exported && config.http_clone_enabled() %} + + + + + + + + + Clone + + + + + {% if !config.clone_prefix.is_empty() %} + + + + {{ config.clone_prefix }}/{{ repo.display() }} + + + + {% endif %} + {% if !config.ssh_clone_prefix.is_empty() %} + + + + {{ config.ssh_clone_prefix }}/{{ repo.display() }} + + + + {% endif %} + + {%- endif %} {% endblock %} -- libgit2 1.7.2