index : gitrs
A lightweight web interface for browsing Git repositories, implemented in Rust
about summary refs log tree commit diff
gitrs / src / git / signature.rs
-rw-r--r-- blob 8c5033fdbb4e3490e8fb4e87e6398bf459c12177 708 bytes (plain)
1
use gix::actor::SignatureRef;
2
3
use crate::time::Time;
4
5
#[derive(Clone)]
6
pub struct GitSignature {
7
    pub name: String,
8
    pub email: String,
9
    pub time: Time,
10
}
11
12
impl GitSignature {
13
    pub fn from_gix(sig: SignatureRef) -> Self {
14
        GitSignature {
15
            name: sig.name.to_string(),
16
            email: sig.email.to_string(),
17
            time: Time::new(sig.time().unwrap_or_default()),
18
        }
19
    }
20
21
    pub fn avatar_url(&self, size: u32) -> String {
22
        let normalized = self.email.trim().to_lowercase();
23
        let hash = md5::compute(normalized.as_bytes());
24
        format!(
25
            "https://www.gravatar.com/avatar/{:x}?s={}&d=retro",
26
            hash, size
27
        )
28
    }
29
}