use chrono::{Local, TimeZone};
use crate::{testutil::JAN_2021_EPOCH, Commit, Reference, User};
#[derive(Debug)]
pub struct CommitBuilder {
commit: Commit,
}
impl CommitBuilder {
#[inline]
#[must_use]
pub fn new(hash: &str) -> Self {
Self {
commit: Commit {
hash: String::from(hash),
reference: None,
author: User::new(None, None),
authored_date: None,
committed_date: Local.timestamp(JAN_2021_EPOCH, 0),
committer: None,
message: None,
summary: None,
},
}
}
#[inline]
#[must_use]
pub fn hash(mut self, hash: &str) -> Self {
self.commit.hash = String::from(hash);
self
}
#[inline]
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn reference(mut self, reference: Reference) -> Self {
self.commit.reference = Some(reference);
self
}
#[inline]
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn author(mut self, author: User) -> Self {
self.commit.author = author;
self
}
#[inline]
#[must_use]
pub fn authored_time(mut self, time: i64) -> Self {
self.commit.authored_date = Some(Local.timestamp(time, 0));
self
}
#[inline]
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn committer(mut self, committer: User) -> Self {
self.commit.committer = Some(committer);
self
}
#[inline]
#[must_use]
pub fn commit_time(mut self, time: i64) -> Self {
self.commit.committed_date = Local.timestamp(time, 0);
self
}
#[inline]
#[must_use]
pub fn summary(mut self, summary: &str) -> Self {
self.commit.summary = Some(String::from(summary));
self
}
#[inline]
#[must_use]
pub fn message(mut self, message: &str) -> Self {
self.commit.message = Some(String::from(message));
self
}
#[inline]
#[must_use]
#[allow(clippy::missing_const_for_fn)]
pub fn build(self) -> Commit {
self.commit
}
}