index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff

Diffstat (limited to 'src/git/signature.rs')

-rw-r--r-- src/git/signature.rs 29
 1 file changed, 29 insertions(+)

diff --git a/src/git/signature.rs b/src/git/signature.rs
new file mode 100644
index 0000000..e1f50f4 100644
--- /dev/null
+++ b/src/git/signature.rs
@@ -1,0 +1,29 @@
use gix::actor::SignatureRef;

use crate::time::Time;

#[derive(Clone)]
pub struct GitSignature {
    pub name: String,
    pub email: String,
    pub time: Time,
}

impl GitSignature {
    pub fn from_gix(sig: SignatureRef) -> Self {
        GitSignature {
            name: sig.name.to_string(),
            email: sig.email.to_string(),
            time: Time::new(sig.time().unwrap()),
        }
    }

    pub fn avatar_url(&self, size: u32) -> String {
        let normalized = self.email.trim().to_lowercase();
        let hash = md5::compute(normalized.as_bytes());
        format!(
            "https://www.gravatar.com/avatar/{:x}?s={}&d=retro",
            hash, size
        )
    }
}