1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
}
}