| 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()), |
| 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 | } |
