about summary refs log tree commit diff
path: root/wikarden/src/settings.rs
blob: e7bd41d97393b2505792aaa9e8eefece0267bcfa (plain)
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
use std::borrow::Cow;

use git2::Signature;

pub struct Settings {
	commit_name: Cow<'static, str>,
	commit_email: Cow<'static, str>,
}

impl Settings {
	pub fn commit_name<Name: Into<Cow<'static, str>>>(mut self, commit_name: Name) -> Self {
		self.commit_name = commit_name.into();
		self
	}

	pub fn commit_email<Email: Into<Cow<'static, str>>>(mut self, commit_email: Email) -> Self {
		self.commit_email = commit_email.into();
		self
	}

	pub(crate) fn signature<'s>(&'s self) -> Signature<'s> {
		git2::Signature::now(&self.commit_name, &self.commit_email).unwrap()
	}
}

impl Default for Settings {
	fn default() -> Self {
		Self {
			commit_name: Cow::Borrowed("Wikarden"),
			commit_email: Cow::Borrowed("wikarden@dreamy.place"),
		}
	}
}

#[cfg(test)]
mod test {
	use super::Settings;

	#[test]
	pub fn makes_signature() {
		let settings = Settings::default();
		let sig = settings.signature();

		assert_eq!(sig.email().unwrap(), "wikarden@dreamy.place");
		assert_eq!(sig.name().unwrap(), "Wikarden");
	}
}