git/testutil/
build_commit.rs1use chrono::{Local, TimeZone};
2
3use crate::{testutil::JAN_2021_EPOCH, Commit, Reference, User};
4
5#[derive(Debug)]
7pub struct CommitBuilder {
8 commit: Commit,
9}
10
11impl CommitBuilder {
12 #[inline]
15 #[must_use]
16 #[allow(clippy::missing_panics_doc)]
17 pub fn new(hash: &str) -> Self {
18 Self {
19 commit: Commit {
20 hash: String::from(hash),
21 reference: None,
22 author: User::new(None, None),
23 authored_date: None,
24 committed_date: Local.timestamp_opt(JAN_2021_EPOCH, 0).unwrap(),
25 committer: None,
26 message: None,
27 summary: None,
28 },
29 }
30 }
31
32 #[inline]
34 #[must_use]
35 pub fn hash(mut self, hash: &str) -> Self {
36 self.commit.hash = String::from(hash);
37 self
38 }
39
40 #[inline]
42 #[must_use]
43 #[allow(clippy::missing_const_for_fn)]
44 pub fn reference(mut self, reference: Reference) -> Self {
45 self.commit.reference = Some(reference);
46 self
47 }
48
49 #[inline]
51 #[must_use]
52 #[allow(clippy::missing_const_for_fn)]
53 pub fn author(mut self, author: User) -> Self {
54 self.commit.author = author;
55 self
56 }
57
58 #[inline]
60 #[must_use]
61 pub fn authored_time(mut self, time: i64) -> Self {
62 self.commit.authored_date = Some(Local.timestamp_opt(time, 0).unwrap());
63 self
64 }
65
66 #[inline]
68 #[must_use]
69 #[allow(clippy::missing_const_for_fn)]
70 pub fn committer(mut self, committer: User) -> Self {
71 self.commit.committer = Some(committer);
72 self
73 }
74
75 #[inline]
77 #[must_use]
78 pub fn commit_time(mut self, time: i64) -> Self {
79 self.commit.committed_date = Local.timestamp_opt(time, 0).unwrap();
80 self
81 }
82
83 #[inline]
85 #[must_use]
86 pub fn summary(mut self, summary: &str) -> Self {
87 self.commit.summary = Some(String::from(summary));
88 self
89 }
90
91 #[inline]
93 #[must_use]
94 pub fn message(mut self, message: &str) -> Self {
95 self.commit.message = Some(String::from(message));
96 self
97 }
98
99 #[inline]
101 #[must_use]
102 #[allow(clippy::missing_const_for_fn)]
103 pub fn build(self) -> Commit {
104 self.commit
105 }
106}