mygit

[UNMAINTAINED] A cgit/webgit alternative, written in Rust
Log | Files | Refs | README | LICENSE

commit d245ca4e0552e674439d4933211736e8ecaf7eaa
parent afe913ac25352de269b118e02bb7231775df9208
Author: Johann150 <johann@qwertqwefsday.eu>
Date:   Mon, 28 Jun 2021 22:42:18 +0200

create tag info page

This page can show information about a specific tag, e.g. the message.

Diffstat:
Msrc/main.rs | 18+++++++++++++++++-
Atemplates/tag.html | 15+++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs @@ -1,5 +1,5 @@ use askama::Template; -use git2::{Commit, Diff, Reference, Repository, Signature, Tree}; +use git2::{Commit, Diff, Reference, Repository, Signature, Tag, Tree}; use once_cell::sync::Lazy; use serde::Deserialize; use std::fs::{self, File}; @@ -473,6 +473,21 @@ async fn repo_commit(req: Request<()>) -> tide::Result { } #[derive(Template)] +#[template(path = "tag.html")] +struct RepoTagTemplate<'a> { + repo: &'a Repository, + tag: Tag<'a>, +} + +async fn repo_tag(req: Request<()>) -> tide::Result { + let repo = repo_from_request(req.param("repo_name")?)?; + let tag = repo.revparse_single(req.param("tag")?)?.peel_to_tag()?; + + let tmpl = RepoTagTemplate { repo: &repo, tag }; + Ok(tmpl.into()) +} + +#[derive(Template)] #[template(path = "file.html")] // using the template in this path, relative struct RepoFileTemplate<'a> { repo: &'a Repository, @@ -987,6 +1002,7 @@ async fn main() -> Result<(), std::io::Error> { app.at("/:repo_name/refs").get(repo_refs); app.at("/:repo_name/refs/").get(repo_refs); app.at("/:repo_name/refs.xml").get(repo_refs_feed); + app.at("/:repo_name/refs/:tag").get(repo_tag); app.at("/:repo_name/log").get(repo_log); app.at("/:repo_name/log/").get(repo_log); app.at("/:repo_name/log/:ref").get(repo_log); // ref is optional diff --git a/templates/tag.html b/templates/tag.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block content %} + {% include "repo-navbar.html" %} + <b>Commit:</b> <a href="/{{repo|repo_name|urlencode_strict}}/commit/{{tag.target_id()}}" class="commit-hash">{{tag.target_id()}}</a> (<a href="/{{repo|repo_name|urlencode_strict}}/tree/{{tag.name().unwrap_or("")}}">tree</a>) + <br> + {% if tag.tagger().is_some() %} + <b>Tagged by:</b> {{tag.tagger().unwrap()|signature_email_link|safe}} + <br> + <b>Date:</b> {{tag.tagger().unwrap().when()|format_datetime("%c %z")}} + <br> + {% endif %} + <hr class="thin"/> + <pre class="commit-message">{{tag.message().unwrap()}}</pre> +{% endblock %}