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
use impl_prelude::*;
#[derive(Debug)]
pub struct AllowRobot {
identity: Identity,
}
impl AllowRobot {
pub fn new(identity: Identity) -> Self {
Self {
identity: identity,
}
}
}
impl BranchCheck for AllowRobot {
fn name(&self) -> &str {
"allow-robot"
}
fn check(&self, ctx: &CheckGitContext, _: &CommitId) -> Result<CheckResult> {
let mut result = CheckResult::new();
if *ctx.topic_owner() == self.identity {
result.whitelist();
}
Ok(result)
}
}
#[cfg(test)]
mod tests {
use crates::git_workarea::Identity;
use checks::AllowRobot;
use checks::test::*;
const ALLOW_ROBOT_COMMIT: &str = "43adb8173eb6d7a39f98e1ec3351cf27414c9aa1";
#[test]
fn test_allow_robot_allowed() {
let check = AllowRobot::new(Identity::new("Rust Git Checks Tests",
"rust-git-checks@example.com"));
let result = run_branch_check("test_allow_robot_allowed", ALLOW_ROBOT_COMMIT, check);
assert_eq!(result.warnings().len(), 0);
assert_eq!(result.alerts().len(), 0);
assert_eq!(result.errors().len(), 0);
assert_eq!(result.temporary(), false);
assert_eq!(result.allowed(), true);
assert_eq!(result.pass(), true);
}
#[test]
fn test_allow_robot_not_robot_not_whitelisted() {
let check = AllowRobot::new(Identity::new("Rust Git Checks 7ests",
"rust-git-checks@example.com"));
run_branch_check_ok("test_allow_robot_not_robot_not_whitelisted",
ALLOW_ROBOT_COMMIT,
check);
}
}