index : sparkle-git.git

ascending towards madness

author holly sparkles <sparkles@holly.sh> 2023-12-08 19:01:19.0 +00:00:00
committer holly sparkles <sparkles@holly.sh> 2024-05-14 6:40:09.0 +00:00:00
commit
3f19c49c63ed70bd50001f07c180d1b4595737dc [patch]
tree
75c33f9895c3d9f39e9ef8357342e3ab1047cd71
parent
d7fad0790306d667f591912870282a26c5212612
download
3f19c49c63ed70bd50001f07c180d1b4595737dc.tar.gz

feat: add clone url display

- clone_prefix
- ssh_clone_prefix
- enable_http_clone

Diff

 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<Cow<'_, str>> {
        .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<Cow<'a, str>>,
    /// 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<Repository<'static>>;
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<YokedCommit>,
    branch: Option<Arc<str>>,
    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 @@
    </tr>
    </tbody>
    {%- endif %}

    {%- if repo_exported && config.http_clone_enabled() %}
    <tbody>
        <tr class="separator">
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr class="no-background">
            <th>Clone</th>
            <th></th>
            <th></th>
            <th></th>
        </tr>
        {% if !config.clone_prefix.is_empty() %}
        <tr>
            <td colspan="4">
                <a rel="vcs-git" href="{{ config.clone_prefix }}/{{ repo.display() }}" title="{{ repo.display() }} Git repository">
                    {{ config.clone_prefix }}/{{ repo.display() }}
                </a>
            </td>
        </tr>
        {% endif %}
        {% if !config.ssh_clone_prefix.is_empty() %}
        <tr>
            <td colspan="4">
                <a rel="vcs-git" href="{{ config.ssh_clone_prefix }}/{{ repo.display() }}" title="{{ repo.display() }} Git repository">
                    {{ config.ssh_clone_prefix }}/{{ repo.display() }}
                </a>
            </td>
        </tr>
        {% endif %}
    </tbody>
    {%- endif %}
</table>
</div>
{% endblock %}