use chrono::{DateTime, Utc};
use git2::Signature;
pub struct Actor {
inner: Signature<'static>,
}
impl Actor {
pub fn new(signature: Signature<'_>) -> Self {
Self {
inner: signature.to_owned(),
}
}
pub fn name(&self) -> Option<String> {
self.inner.name().map(|s| s.to_string())
}
pub fn email(&self) -> Option<String> {
self.inner.email().map(|s| s.to_string())
}
pub fn timestamp(&self) -> Option<DateTime<Utc>> {
DateTime::from_timestamp_secs(self.inner.when().seconds())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_actor() {
let sig = Signature::new(
"test",
"test@example.com",
&git2::Time::new(1_600_000_000, 0),
)
.unwrap();
let actor = Actor::new(sig);
assert_eq!(actor.name(), Some("test".to_string()));
assert_eq!(actor.email(), Some("test@example.com".to_string()));
assert_eq!(actor.timestamp().unwrap().timestamp(), 1_600_000_000);
}
}