1use chrono::{DateTime, Utc};
2use git2::Signature;
3
4pub struct Actor {
6 inner: Signature<'static>,
7}
8
9impl Actor {
10 pub fn new(signature: Signature<'_>) -> Self {
12 Self {
13 inner: signature.to_owned(),
14 }
15 }
16
17 pub fn name(&self) -> Option<String> {
19 self.inner.name().map(|s| s.to_string())
20 }
21
22 pub fn email(&self) -> Option<String> {
24 self.inner.email().map(|s| s.to_string())
25 }
26
27 pub fn timestamp(&self) -> Option<DateTime<Utc>> {
29 DateTime::from_timestamp_secs(self.inner.when().seconds())
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn test_actor() {
39 let sig = Signature::new(
40 "test",
41 "test@example.com",
42 &git2::Time::new(1_600_000_000, 0),
43 )
44 .unwrap();
45
46 let actor = Actor::new(sig);
47
48 assert_eq!(actor.name(), Some("test".to_string()));
49 assert_eq!(actor.email(), Some("test@example.com".to_string()));
50 assert_eq!(actor.timestamp().unwrap().timestamp(), 1_600_000_000);
51 }
52}